]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
kmod_module: use pointer instead of vector for its name
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 13 Dec 2011 15:07:40 +0000 (13:07 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 13 Dec 2011 15:15:49 +0000 (13:15 -0200)
We still have name allocated just after the struct kmod_module, but
now we use a pointer instead of putting name as a vector in the end of
the structure.

The previous way has some problems, the worst is:
- it's not possible to swap the name with another value: this is
  the real problem that this patch is solving. Later patches
  will make name be swappable with alias, which is not possible
  if name is a vector.

libkmod/libkmod-module.c

index 9429f1d79afa9dbaf26fbfc4fc4427d3cda99431..0e71aea7424de220ef872e813864acfbece13e1e 100644 (file)
@@ -45,6 +45,7 @@
  */
 struct kmod_module {
        struct kmod_ctx *ctx;
+       char *name;
        char *path;
        struct kmod_list *dep;
        char *options;
@@ -58,7 +59,6 @@ struct kmod_module {
                bool install_commands : 1;
                bool remove_commands : 1;
        } init;
-       char name[];
 };
 
 inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
@@ -214,6 +214,7 @@ KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx,
        }
 
        m->ctx = kmod_ref(ctx);
+       m->name = (char *)m + sizeof(*m);
        memcpy(m->name, name_norm, namelen + 1);
        m->refcount = 1;
 
@@ -275,6 +276,7 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
                return -errno;
 
        m->ctx = kmod_ref(ctx);
+       m->name = (char *)m + sizeof(*m);
        memcpy(m->name, name, namelen);
        m->path = abspath;
        m->refcount = 1;