]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/module.c
[PATCH] driver core: fix built-in drivers sysfs links
[linux-2.6-omap-h63xx.git] / kernel / module.c
index 8a94e054230c07abb5371c8e8b4e369f3e8476bd..dcdb32b8b13cd31d51868375a03e1f54b6c34efd 100644 (file)
@@ -1068,7 +1068,8 @@ static inline void remove_sect_attrs(struct module *mod)
 }
 #endif /* CONFIG_KALLSYMS */
 
-static int module_add_modinfo_attrs(struct module *mod)
+#ifdef CONFIG_SYSFS
+int module_add_modinfo_attrs(struct module *mod)
 {
        struct module_attribute *attr;
        struct module_attribute *temp_attr;
@@ -1094,7 +1095,7 @@ static int module_add_modinfo_attrs(struct module *mod)
        return error;
 }
 
-static void module_remove_modinfo_attrs(struct module *mod)
+void module_remove_modinfo_attrs(struct module *mod)
 {
        struct module_attribute *attr;
        int i;
@@ -1109,8 +1110,10 @@ static void module_remove_modinfo_attrs(struct module *mod)
        }
        kfree(mod->modinfo_attrs);
 }
+#endif
 
-static int mod_sysfs_init(struct module *mod)
+#ifdef CONFIG_SYSFS
+int mod_sysfs_init(struct module *mod)
 {
        int err;
 
@@ -1133,7 +1136,7 @@ out:
        return err;
 }
 
-static int mod_sysfs_setup(struct module *mod,
+int mod_sysfs_setup(struct module *mod,
                           struct kernel_param *kparam,
                           unsigned int num_params)
 {
@@ -1169,16 +1172,14 @@ out_unreg:
 out:
        return err;
 }
+#endif
 
 static void mod_kobject_remove(struct module *mod)
 {
        module_remove_modinfo_attrs(mod);
        module_param_sysfs_remove(mod);
-       if (mod->mkobj.drivers_dir)
-               kobject_unregister(mod->mkobj.drivers_dir);
-       if (mod->holders_dir)
-               kobject_unregister(mod->holders_dir);
-
+       kobject_unregister(mod->mkobj.drivers_dir);
+       kobject_unregister(mod->holders_dir);
        kobject_unregister(&mod->mkobj.kobj);
 }
 
@@ -2345,6 +2346,7 @@ void print_modules(void)
        printk("\n");
 }
 
+#ifdef CONFIG_SYSFS
 static char *make_driver_name(struct device_driver *drv)
 {
        char *driver_name;
@@ -2382,8 +2384,13 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
 
                /* Lookup built-in module entry in /sys/modules */
                mkobj = kset_find_obj(&module_subsys.kset, drv->mod_name);
-               if (mkobj)
+               if (mkobj) {
                        mk = container_of(mkobj, struct module_kobject, kobj);
+                       /* remember our module structure */
+                       drv->mkobj = mk;
+                       /* kset_find_obj took a reference */
+                       kobject_put(mkobj);
+               }
        }
 
        if (!mk)
@@ -2403,22 +2410,28 @@ EXPORT_SYMBOL(module_add_driver);
 
 void module_remove_driver(struct device_driver *drv)
 {
+       struct module_kobject *mk = NULL;
        char *driver_name;
 
        if (!drv)
                return;
 
        sysfs_remove_link(&drv->kobj, "module");
-       if (drv->owner && drv->owner->mkobj.drivers_dir) {
+
+       if (drv->owner)
+               mk = &drv->owner->mkobj;
+       else if (drv->mkobj)
+               mk = drv->mkobj;
+       if (mk && mk->drivers_dir) {
                driver_name = make_driver_name(drv);
                if (driver_name) {
-                       sysfs_remove_link(drv->owner->mkobj.drivers_dir,
-                                         driver_name);
+                       sysfs_remove_link(mk->drivers_dir, driver_name);
                        kfree(driver_name);
                }
        }
 }
 EXPORT_SYMBOL(module_remove_driver);
+#endif
 
 #ifdef CONFIG_MODVERSIONS
 /* Generate the signature for struct module here, too, for modversions. */