driver core patches against 2.6.24
Subsystems (67)
PATCH 86/196 kobject: convert parisc/pdc_stable to kobj_attr interface
In reply to Greg KHThis makes the code a bit simpler and and gets us one step closer to deleting the deprecated subsys_attr code.
NOTE, this needs the next patch in the series in order to work properly. This will build, but the sysfs files will not properly operate.
--- drivers/parisc/pdc_stable.c | 147 ++++++++++++++++++++---------------------- 1 files changed, 70 insertions(+), 77 deletions(-)
drivers/parisc/pdc_stable.c +70 -77
@@ -120,7 +120,7 @@ struct pdcspath_entry pdcspath_entry_##_name = { \ };#define PDCS_ATTR (_name, _mode, _show, _store) \ -struct subsys_attribute pdcs_attr_##_name = { \ +struct kobj_attribute pdcs_attr_##_name = { \ .attr = {.name = __stringify(_name), .mode = _mode}, \ .show = _show, \ .store = _store, \
@@ -523,15 +523,15 @@ static struct pdcspath_entry *pdcspath_entries[] = {/** * pdcs_size_read - Stable Storage size output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. */ -static ssize_t -pdcs_size_read (struct kset *kset,char *buf) +static ssize_t pdcs_size_read (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf) {char *out = buf; -if (!kset || !buf) +if (!buf)return -EINVAL ;/* show the size of the stable storage */
@@ -542,17 +542,17 @@ pdcs_size_read(struct kset *kset, char *buf)/** * pdcs_auto_read - Stable Storage autoboot/search flag output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag */ -static ssize_t -pdcs_auto_read (struct kset *kset,char *buf,int knob) +static ssize_t pdcs_auto_read (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf,int knob) {char *out = buf;struct pdcspath_entry *pathentry; -if (!kset || !buf) +if (!buf)return -EINVAL ;/* Current flags are stored in primary boot path entry */
@@ -568,40 +568,37 @@ pdcs_auto_read(struct kset *kset, char *buf, int knob)/** * pdcs_autoboot_read - Stable Storage autoboot flag output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. */ -static inline ssize_t -pdcs_autoboot_read (struct kset *kset,char *buf) +static ssize_t pdcs_autoboot_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) { -return pdcs_auto_read (kset, buf,PF_AUTOBOOT ); +return pdcs_auto_read (kobj, attr, buf,PF_AUTOBOOT ); }/** * pdcs_autosearch_read - Stable Storage autoboot flag output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. */ -static inline ssize_t -pdcs_autosearch_read (struct kset *kset,char *buf) +static ssize_t pdcs_autosearch_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) { -return pdcs_auto_read (kset, buf,PF_AUTOSEARCH ); +return pdcs_auto_read (kobj, attr, buf,PF_AUTOSEARCH ); }/** * pdcs_timer_read - Stable Storage timer count output (in seconds). -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. * * The value of the timer field correponds to a number of seconds in powers of 2. */ -static ssize_t -pdcs_timer_read (struct kset *kset,char *buf) +static ssize_t pdcs_timer_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) {char *out = buf;struct pdcspath_entry *pathentry; -if (!kset || !buf) +if (!buf)return -EINVAL ;/* Current flags are stored in primary boot path entry */
@@ -618,15 +615,14 @@ pdcs_timer_read(struct kset *kset, char *buf)/** * pdcs_osid_read - Stable Storage OS ID register output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. */ -static ssize_t -pdcs_osid_read (struct kset *kset,char *buf) +static ssize_t pdcs_osid_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) {char *out = buf; -if (!kset || !buf) +if (!buf)return -EINVAL ; out += sprintf(out, "%s dependent data (0x%.4x)\n",
@@ -637,18 +633,17 @@ pdcs_osid_read(struct kset *kset, char *buf)/** * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. * * This can hold 16 bytes of OS-Dependent data. */ -static ssize_t -pdcs_osdep1_read (struct kset *kset,char *buf) +static ssize_t pdcs_osdep1_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) {char *out = buf;u32 result[4 ]; -if (!kset || !buf) +if (!buf)return -EINVAL ;if (pdc_stable_read (PDCS_ADDR_OSD1 , &result,sizeof (result)) !=PDC_OK )
@@ -664,18 +659,17 @@ pdcs_osdep1_read(struct kset *kset, char *buf)/** * pdcs_diagnostic_read - Stable Storage Diagnostic register output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. * * I have NFC how to interpret the content of that register ;-). */ -static ssize_t -pdcs_diagnostic_read (struct kset *kset,char *buf) +static ssize_t pdcs_diagnostic_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) {char *out = buf;u32 result; -if (!kset || !buf) +if (!buf)return -EINVAL ;/* get diagnostic */
@@ -689,18 +683,17 @@ pdcs_diagnostic_read(struct kset *kset, char *buf)/** * pdcs_fastsize_read - Stable Storage FastSize register output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. * * This register holds the amount of system RAM to be tested during boot sequence. */ -static ssize_t -pdcs_fastsize_read (struct kset *kset,char *buf) +static ssize_t pdcs_fastsize_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) {char *out = buf;u32 result; -if (!kset || !buf) +if (!buf)return -EINVAL ;/* get fast-size */
@@ -718,13 +711,12 @@ pdcs_fastsize_read(struct kset *kset, char *buf)/** * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The output buffer to write to. * * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available. */ -static ssize_t -pdcs_osdep2_read (struct kset *kset,char *buf) +static ssize_t pdcs_osdep2_read (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) {char *out = buf;unsigned long size;
@@ -736,7 +728,7 @@ pdcs_osdep2_read(struct kset *kset, char *buf) size = pdcs_size -224 ; -if (!kset || !buf) +if (!buf)return -EINVAL ;for (i=0 ; i<size; i+=4 ) {
@@ -751,7 +743,6 @@ pdcs_osdep2_read(struct kset *kset, char *buf)/** * pdcs_auto_write - This function handles autoboot/search flag modifying. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The input buffer to read from. * @count: The number of bytes to be read. * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
@@ -760,8 +751,9 @@ pdcs_osdep2_read(struct kset *kset, char *buf)* We expect a precise syntax: * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On */ -static ssize_t -pdcs_auto_write (struct kset *kset,const char *buf,size_t count,int knob) +static ssize_t pdcs_auto_write (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf, +size_t count,int knob) {struct pdcspath_entry *pathentry;unsigned char flags;
@@ -771,7 +763,7 @@ pdcs_auto_write(struct kset *kset, const char *buf, size_t count, int knob)if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (!kset || !buf || !count) +if (!buf || !count)return -EINVAL ;/* We'll use a local copy of buf */
@@ -826,7 +818,6 @@ parse_error:/** * pdcs_autoboot_write - This function handles autoboot flag modifying. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The input buffer to read from. * @count: The number of bytes to be read. *
@@ -834,15 +825,15 @@ parse_error:* We expect a precise syntax: * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On */ -static inline ssize_t -pdcs_autoboot_write (struct kset *kset,const char *buf,size_t count) +static ssize_t pdcs_autoboot_write (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) { -return pdcs_auto_write (kset, buf, count,PF_AUTOBOOT ); +return pdcs_auto_write (kset, attr, buf, count,PF_AUTOBOOT ); }/** * pdcs_autosearch_write - This function handles autosearch flag modifying. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The input buffer to read from. * @count: The number of bytes to be read. *
@@ -850,15 +841,15 @@ pdcs_autoboot_write(struct kset *kset, const char *buf, size_t count)* We expect a precise syntax: * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On */ -static inline ssize_t -pdcs_autosearch_write (struct kset *kset,const char *buf,size_t count) +static ssize_t pdcs_autosearch_write (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) { -return pdcs_auto_write (kset, buf, count,PF_AUTOSEARCH ); +return pdcs_auto_write (kset, attr, buf, count,PF_AUTOSEARCH ); }/** * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The input buffer to read from. * @count: The number of bytes to be read. *
@@ -866,15 +857,16 @@ pdcs_autosearch_write(struct kset *kset, const char *buf, size_t count)* write approach. It's up to userspace to deal with it when constructing * its input buffer. */ -static ssize_t -pdcs_osdep1_write (struct kset *kset,const char *buf,size_t count) +static ssize_t pdcs_osdep1_write (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) {u8 in[16 ];if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (!kset || !buf || !count) +if (!buf || !count)return -EINVAL ;if (unlikely (pdcs_osid !=OS_ID_LINUX ))
@@ -895,7 +887,6 @@ pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count)/** * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input. -* @kset: An allocated and populated struct kset. We don't use it tho. * @buf: The input buffer to read from. * @count: The number of bytes to be read. *
@@ -903,8 +894,9 @@ pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count)* byte-by-byte write approach. It's up to userspace to deal with it when * constructing its input buffer. */ -static ssize_t -pdcs_osdep2_write (struct kset *kset,const char *buf,size_t count) +static ssize_t pdcs_osdep2_write (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) {unsigned long size;unsigned short i;
@@ -913,7 +905,7 @@ pdcs_osdep2_write(struct kset *kset, const char *buf, size_t count)if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (!kset || !buf || !count) +if (!buf || !count)return -EINVAL ;if (unlikely (pdcs_size <=224 ))
@@ -951,19 +943,23 @@ static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL); static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL); static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write); -static struct subsys_attribute *pdcs_subsys_attrs[] = { - &pdcs_attr_size, - &pdcs_attr_autoboot, - &pdcs_attr_autosearch, - &pdcs_attr_timer, - &pdcs_attr_osid, - &pdcs_attr_osdep1, - &pdcs_attr_diagnostic, - &pdcs_attr_fastsize, - &pdcs_attr_osdep2, +static struct attribute *pdcs_subsys_attrs[] = { + &pdcs_attr_size.attr, + &pdcs_attr_autoboot.attr, + &pdcs_attr_autosearch.attr, + &pdcs_attr_timer.attr, + &pdcs_attr_osid.attr, + &pdcs_attr_osdep1.attr, + &pdcs_attr_diagnostic.attr, + &pdcs_attr_fastsize.attr, + &pdcs_attr_osdep2.attr,NULL , }; +static struct attribute_group pdcs_attr_group = { + .attrs = pdcs_subsys_attrs, +}; + static decl_subsys(paths, NULL); static decl_subsys(stable, NULL);
@@ -1042,8 +1038,7 @@ pdcs_unregister_pathentries(void)static int __init pdc_stable_init (void ) { -struct subsys_attribute *attr; -int i, rc =0 , error =0 ; +int rc =0 , error =0 ;u32 result;/* find the size of the stable storage */
@@ -1068,10 +1063,8 @@ pdc_stable_init(void) goto fail_firmreg;/* Don't forget the root entries */ -for (i =0 ; (attr = pdcs_subsys_attrs[i]) && !error; i++) -if (attr->show) - error =subsys_create_file (&stable_subsys, attr); - + error =sysfs_create_group (&stable_subsys.kobj, pdcs_attr_group); +/* register the paths subsys as a subsystem of stable subsys */ paths_subsys.kobj.kset = &stable_subsys;if ((rc =subsystem_register (&paths_subsys)))
Signature · 1 line
1.5.3.8
PATCH 87/196 kset: convert parisc/pdc_stable.c to use kset_create
In reply to Greg KHDynamically create the kset instead of declaring it statically. This makes the kobject attributes now work properly that I broke in the previous patch.
--- drivers/parisc/pdc_stable.c | 38 +++++++++++++++++++++----------------- 1 files changed, 21 insertions(+), 17 deletions(-)
drivers/parisc/pdc_stable.c +21 -17
@@ -960,8 +960,8 @@ static struct attribute_group pdcs_attr_group = { .attrs = pdcs_subsys_attrs, }; -static decl_subsys(paths, NULL); -static decl_subsys(stable, NULL); +static struct kset *stable_kset; +static struct kset *paths_kset;/** * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
@@ -993,7 +993,7 @@ pdcs_register_pathentries(void)if ((err =kobject_set_name (&entry->kobj,"%s" , entry->name)))return err; - entry->kobj.kset = &paths_subsys; + entry->kobj.kset = paths_kset; entry->kobj.ktype = &ktype_pdcspath;if ((err =kobject_register (&entry->kobj)))return err;
@@ -1058,19 +1058,24 @@ pdc_stable_init(void)/* the actual result is 16 bits away */ pdcs_osid = (u16)(result >>16 ); -/* For now we'll register the stable subsys within this driver */ -if ((rc =firmware_register (&stable_subsys))) +/* For now we'll register the stable kset within this driver */ + stable_kset =kset_create_and_add ("stable" ,NULL , &firmware_kset->kobj); +if (!stable_kset) { + rc = -ENOMEM ; goto fail_firmreg; + }/* Don't forget the root entries */ - error =sysfs_create_group (&stable_subsys.kobj, pdcs_attr_group); + error =sysfs_create_group (&stable_kset->kobj, pdcs_attr_group); -/* register the paths subsys as a subsystem of stable subsys */ - paths_subsys.kobj.kset = &stable_subsys; -if ((rc =subsystem_register (&paths_subsys))) - goto fail_subsysreg; +/* register the paths kset as a child of the stable kset */ + paths_kset =kset_create_and_add ("paths" ,NULL , &stable_kset->kobj); +if (!paths_kset) { + rc = -ENOMEM ; + goto fail_ksetreg; + } -/* now we create all "files" for the paths subsys */ +/* now we create all "files" for the paths kset */ if ((rc =pdcs_register_pathentries ())) goto fail_pdcsreg;
@@ -1078,10 +1083,10 @@ pdc_stable_init(void) fail_pdcsreg:pdcs_unregister_pathentries (); -subsystem_unregister (&paths_subsys); +kset_unregister (paths_kset); -fail_subsysreg: -firmware_unregister (&stable_subsys); +fail_ksetreg: +kset_unregister (stable_kset); fail_firmreg: printk(KERN_INFO PDCS_PREFIX " bailing out\n");
@@ -1092,9 +1097,8 @@ static void __exitpdc_stable_exit (void) {pdcs_unregister_pathentries (); -subsystem_unregister (&paths_subsys); - -firmware_unregister (&stable_subsys); +kset_unregister (paths_kset); +kset_unregister (stable_kset); }
Signature · 1 line
1.5.3.8
PATCH 88/196 Driver Core: kill subsys_attribute and default sysfs ops
In reply to Greg KHFrom: Kay Sievers <[email protected]>
Remove the no longer needed subsys_attributes, they are all converted to the more sensical kobj_attributes.
There is no longer a magic fallback in sysfs attribute operations, all kobjects which create simple attributes need explicitely a ktype assigned, which tells the core what was intended here.
--- fs/sysfs/file.c | 63 +++++++--------------------------------------- include/linux/kobject.h | 9 ------ lib/kobject.c | 21 --------------- 3 files changed, 10 insertions(+), 83 deletions(-)
fs/sysfs/file.c +10 -53
@@ -20,43 +20,6 @@#include "sysfs.h" -#define to_sattr (a) container_of(a,struct subsys_attribute, attr) - -/* -* Subsystem file operations. -* These operations allow subsystems to have files that can be -* read/written. -*/ -static ssize_t -subsys_attr_show (struct kobject * kobj,struct attribute * attr,char * page) -{ -struct kset *kset =to_kset (kobj); -struct subsys_attribute * sattr =to_sattr (attr); -ssize_t ret = -EIO ; - -if (sattr->show) - ret = sattr->show (kset, page); -return ret; -} - -static ssize_t -subsys_attr_store (struct kobject * kobj,struct attribute * attr, -const char * page,size_t count) -{ -struct kset *kset =to_kset (kobj); -struct subsys_attribute * sattr =to_sattr (attr); -ssize_t ret = -EIO ; - -if (sattr->store) - ret = sattr->store (kset, page, count); -return ret; -} - -static struct sysfs_ops subsys_sysfs_ops = { - .show = subsys_attr_show, - .store = subsys_attr_store, -}; -/* * There's one sysfs_buffer for each open file and one * sysfs_open_dirent for each sysfs_dirent with one or more open
@@ -354,29 +317,23 @@ static int sysfs_open_file(struct inode *inode, struct file *file) {struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; -struct sysfs_buffer * buffer; -struct sysfs_ops * ops =NULL ; -int error; +struct sysfs_buffer *buffer; +struct sysfs_ops *ops; +int error = -EACCES ;/* need attr_sd for attr and ops, its parent for kobj */ if (!sysfs_get_active_two (attr_sd))return -ENODEV ; -/* if the kobject has no ktype, then we assume that it is a subsystem -* itself, and use ops for it. -*/ -if (kobj->ktype) +/* every kobject with an attribute needs a ktype assigned */ +if (kobj->ktype && kobj->ktype->sysfs_ops) ops = kobj->ktype->sysfs_ops; -else - ops = &subsys_sysfs_ops; - - error = -EACCES ; - -/* No sysfs operations, either from having no subsystem, -* or the subsystem have no operations. -*/ -if (!ops) +else { +printk (KERN_ERR "missing sysfs attribute operations for " +"kobject: %s\n" ,kobject_name (kobj)); +WARN_ON (1 ); goto err_out; + }/* File needs write support. * The inode's perms must say it's ok,
include/linux/kobject.h +0 -9
@@ -216,15 +216,6 @@ extern struct kset *firmware_kset;extern int __must_check subsystem_register (struct kset *);extern void subsystem_unregister (struct kset *); -struct subsys_attribute { -struct attribute attr; -ssize_t (*show)(struct kset *,char *); -ssize_t (*store)(struct kset *,const char *,size_t ); -}; - -extern int __must_check subsys_create_file (struct kset *, -struct subsys_attribute *); -#if defined(CONFIG_HOTPLUG )int kobject_uevent (struct kobject *kobj,enum kobject_action action); int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
lib/kobject.c +0 -21
@@ -810,26 +810,6 @@ void subsystem_unregister(struct kset *s)kset_unregister (s); } -/** -* subsystem_create_file - export sysfs attribute file. -* @s: subsystem. -* @a: subsystem attribute descriptor. -*/ - -int subsys_create_file (struct kset *s,struct subsys_attribute *a) -{ -int error =0 ; - -if (!s || !a) -return -EINVAL ; - -if (kset_get (s)) { - error =sysfs_create_file (&s->kobj, &a->attr); -kset_put (s); - } -return error; -} -static void kset_release (struct kobject *kobj) { struct kset *kset = container_of(kobj, struct kset, kobj);
@@ -927,4 +907,3 @@ EXPORT_SYMBOL(kset_unregister);EXPORT_SYMBOL (subsystem_register);EXPORT_SYMBOL (subsystem_unregister); -EXPORT_SYMBOL (subsys_create_file);
Signature · 1 line
1.5.3.8
PATCH 89/196 kset: convert edd to use kset_create
In reply to Greg KHDynamically create the kset instead of declaring it statically.
--- drivers/firmware/edd.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/firmware/edd.c +7 -7
@@ -631,7 +631,7 @@ static struct kobj_type edd_ktype = { .default_attrs = def_attrs, }; -static decl_subsys(edd, NULL); +static struct kset *edd_kset;/**
@@ -723,7 +723,7 @@ edd_device_register(struct edd_device *edev, int i)edd_dev_set_info (edev, i);kobject_set_name (&edev->kobj,"int13_dev%02x" ,0x80 + i); - edev->kobj.kset = &edd_subsys; + edev->kobj.kset = edd_kset; edev->kobj.ktype = &edd_ktype; error =kobject_register (&edev->kobj);if (!error)
@@ -756,9 +756,9 @@ edd_init(void)return 1 ; } - rc =firmware_register (&edd_subsys); -if (rc) -return rc; + edd_kset =kset_create_and_add ("edd" ,NULL , &firmware_kset->kobj); +if (!edd_kset) +return -ENOMEM ;for (i =0 ; i <edd_num_devices () && !rc; i++) { edev =kzalloc (sizeof (*edev),GFP_KERNEL );
@@ -774,7 +774,7 @@ edd_init(void) }if (rc) -firmware_unregister (&edd_subsys); +kset_unregister (edd_kset);return rc; }
@@ -788,7 +788,7 @@ edd_exit(void)if ((edev = edd_devices[i]))edd_device_unregister (edev); } -firmware_unregister (&edd_subsys); +kset_unregister (edd_kset); }late_initcall (edd_init);
Signature · 1 line
1.5.3.8
PATCH 90/196 kobject: convert /sys/firmware/acpi/ to use kobject_create
In reply to Greg KHWe don't need a kset here, a simple kobject will do just fine, so dynamically create the kobject and use it.
--- drivers/acpi/bus.c | 11 ++++++----- drivers/acpi/system.c | 2 +- include/acpi/acpi_bus.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-)
drivers/acpi/bus.c +6 -5
@@ -743,7 +743,7 @@ static int __init acpi_bus_init(void)return -ENODEV ; } -decl_subsys (acpi,NULL ); +struct kobject *acpi_kobj;static int __init acpi_init (void ) {
@@ -755,10 +755,11 @@ static int __init acpi_init(void)return -ENODEV ; } - result =firmware_register (&acpi_subsys); -if (result <0 ) -printk (KERN_WARNING "%s: firmware_register error: %d\n" , - __FUNCTION__, result); + acpi_kobj =kobject_create_and_add ("acpi" , &firmware_kset->kobj); +if (!acpi_kobj) { +printk (KERN_WARNING "%s: kset create error\n" , __FUNCTION__); + acpi_kobj =NULL ; + } result =acpi_bus_init ();
drivers/acpi/system.c +1 -1
@@ -135,7 +135,7 @@ static int acpi_system_sysfs_init(void)int table_index =0 ;int result; - tables_kobj.parent = &acpi_subsys.kobj; + tables_kobj.parent = acpi_kobj;kobject_set_name (&tables_kobj,"tables" ); result =kobject_register (&tables_kobj);if (result)
include/acpi/acpi_bus.h +1 -1
@@ -319,7 +319,7 @@ struct acpi_bus_event {u32 data; }; -extern struct kset acpi_subsys; +extern struct kobject *acpi_kobj;extern int acpi_bus_generate_netlink_event (const char *,const char *,u8 ,int );/* * External Functions
Signature · 1 line
1.5.3.8
PATCH 91/196 firmware: remove firmware_(un)register()
In reply to Greg KHThese functions are no longer called or needed, so we can remove them.
As I rewrote the whole firmware.c file, add my copyright.
--- drivers/base/firmware.c | 19 ++----------------- include/linux/device.h | 5 ----- 2 files changed, 2 insertions(+), 22 deletions(-)
drivers/base/firmware.c +2 -17
@@ -3,11 +3,11 @@* * Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs +* Copyright (c) 2007 Greg Kroah-Hartman <[email protected]> +* Copyright (c) 2007 Novell Inc. * * This file is released under the GPLv2 -* */ -#include <linux/kobject.h> #include <linux/module.h> #include <linux/init.h>
@@ -18,18 +18,6 @@struct kset *firmware_kset;EXPORT_SYMBOL_GPL (firmware_kset); -int firmware_register (struct kset *s) -{ - s->kobj.kset = firmware_kset; - s->kobj.ktype =NULL ; -return subsystem_register (s); -} - -void firmware_unregister (struct kset *s) -{ -subsystem_unregister (s); -} -int __init firmware_init (void ) { firmware_kset =kset_create_and_add ("firmware" ,NULL ,NULL );
@@ -37,6 +25,3 @@ int __init firmware_init(void)return -ENOMEM ;return 0 ; } - -EXPORT_SYMBOL_GPL (firmware_register); -EXPORT_SYMBOL_GPL (firmware_unregister);
include/linux/device.h +0 -5
@@ -555,11 +555,6 @@ extern void device_shutdown(void);/* drivers/base/sys.c */ extern void sysdev_shutdown (void ); - -/* drivers/base/firmware.c */ -extern int __must_check firmware_register (struct kset *); -extern void firmware_unregister (struct kset *); -/* debugging and troubleshooting/diagnostic helpers. */ extern const char *dev_driver_string (struct device *dev); #define dev_printk(level, dev, format, arg...) \
Signature · 1 line
1.5.3.8
PATCH 92/196 firmware: change firmware_kset to firmware_kobj
In reply to Greg KHThere is no firmware "subsystem" it's just a directory in /sys that other portions of the kernel want to hook into. So make it a kobject not a kset to help alivate anyone who tries to do some odd kset-like things with this.
--- arch/s390/kernel/ipl.c | 8 ++++---- drivers/acpi/bus.c | 2 +- drivers/base/firmware.c | 8 ++++---- drivers/firmware/edd.c | 2 +- drivers/firmware/efivars.c | 2 +- drivers/parisc/pdc_stable.c | 2 +- include/linux/kobject.h | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-)
arch/s390/kernel/ipl.c +4 -4
@@ -855,7 +855,7 @@ static int __init ipl_init(void) {int rc; - ipl_kset =kset_create_and_add ("ipl" ,NULL , &firmware_kset->kobj); + ipl_kset =kset_create_and_add ("ipl" ,NULL , firmware_kobj);if (!ipl_kset)return -ENOMEM ;switch (ipl_info.type) {
@@ -974,7 +974,7 @@ static int __init reipl_init(void) {int rc; - reipl_kset =kset_create_and_add ("reipl" ,NULL , &firmware_kset->kobj); + reipl_kset =kset_create_and_add ("reipl" ,NULL , firmware_kobj);if (!reipl_kset)return -ENOMEM ; rc =sysfs_create_file (&reipl_kset->kobj, &reipl_type_attr.attr);
@@ -1063,7 +1063,7 @@ static int __init dump_init(void) {int rc; - dump_kset =kset_create_and_add ("dump" ,NULL , &firmware_kset->kobj); + dump_kset =kset_create_and_add ("dump" ,NULL , firmware_kobj);if (!dump_kset)return -ENOMEM ; rc =sysfs_create_file (&dump_kset->kobj, &dump_type_attr);
@@ -1086,7 +1086,7 @@ static int __init shutdown_actions_init(void)int rc; shutdown_actions_kset =kset_create_and_add ("shutdown_actions" ,NULL , - &firmware_kset->kobj); + firmware_kobj);if (!shutdown_actions_kset)return -ENOMEM ; rc =sysfs_create_file (&shutdown_actions_kset->kobj, &on_panic_attr);
drivers/acpi/bus.c +1 -1
@@ -755,7 +755,7 @@ static int __init acpi_init(void)return -ENODEV ; } - acpi_kobj =kobject_create_and_add ("acpi" , &firmware_kset->kobj); + acpi_kobj =kobject_create_and_add ("acpi" , firmware_kobj);if (!acpi_kobj) {printk (KERN_WARNING "%s: kset create error\n" , __FUNCTION__); acpi_kobj =NULL ;
drivers/base/firmware.c +4 -4
@@ -15,13 +15,13 @@#include "base.h" -struct kset *firmware_kset; -EXPORT_SYMBOL_GPL (firmware_kset); +struct kobject *firmware_kobj; +EXPORT_SYMBOL_GPL (firmware_kobj);int __init firmware_init (void ) { - firmware_kset =kset_create_and_add ("firmware" ,NULL ,NULL ); -if (!firmware_kset) + firmware_kobj =kobject_create_and_add ("firmware" ,NULL ); +if (!firmware_kobj)return -ENOMEM ;return 0 ; }
drivers/firmware/edd.c +1 -1
@@ -756,7 +756,7 @@ edd_init(void)return 1 ; } - edd_kset =kset_create_and_add ("edd" ,NULL , &firmware_kset->kobj); + edd_kset =kset_create_and_add ("edd" ,NULL , firmware_kobj);if (!edd_kset)return -ENOMEM ;
drivers/firmware/efivars.c +1 -1
@@ -668,7 +668,7 @@ efivars_init(void)/* * For now we'll register the efi subsys within this driver */ - efi_kset =kset_create_and_add ("efi" ,NULL , &firmware_kset->kobj); + efi_kset =kset_create_and_add ("efi" ,NULL , firmware_kobj);if (!efi_kset) {printk (KERN_ERR "efivars: Firmware registration failed.\n" ); error = -ENOMEM ;
drivers/parisc/pdc_stable.c +1 -1
@@ -1059,7 +1059,7 @@ pdc_stable_init(void) pdcs_osid = (u16)(result >>16 );/* For now we'll register the stable kset within this driver */ - stable_kset =kset_create_and_add ("stable" ,NULL , &firmware_kset->kobj); + stable_kset =kset_create_and_add ("stable" ,NULL , firmware_kobj);if (!stable_kset) { rc = -ENOMEM ; goto fail_firmreg;
include/linux/kobject.h +2 -2
@@ -210,8 +210,8 @@ extern struct kset *kernel_kset;extern struct kobject *hypervisor_kobj;/* The global /sys/power/ kset for people to chain off of */ extern struct kset *power_kset; -/* The global /sys/firmware/ kset for people to chain off of */ -extern struct kset *firmware_kset; +/* The global /sys/firmware/ kobject for people to chain off of */ +extern struct kobject *firmware_kobj;extern int __must_check subsystem_register (struct kset *);extern void subsystem_unregister (struct kset *);
Signature · 1 line
1.5.3.8
PATCH 93/196 kset: convert ocfs2 to use kset_create
In reply to Greg KHDynamically create the kset instead of declaring it statically.
Also use the new kobj_attribute which cleans up this file a _lot_.
--- fs/ocfs2/cluster/masklog.c | 4 +- fs/ocfs2/cluster/sys.c | 83 +++++++++++-------------------------------- 2 files changed, 23 insertions(+), 64 deletions(-)
fs/ocfs2/cluster/masklog.c +2 -2
@@ -146,7 +146,7 @@ static struct kset mlog_kset = { .kobj = {.ktype = &mlog_ktype}, }; -int mlog_sys_init (struct kset *o2cb_subsys) +int mlog_sys_init (struct kset *o2cb_kset) {int i =0 ;
@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys) mlog_attr_ptrs[i] =NULL ;kobject_set_name (&mlog_kset.kobj,"logmask" ); - mlog_kset.kobj.kset = o2cb_subsys; + mlog_kset.kobj.kset = o2cb_kset;return kset_register (&mlog_kset); }
fs/ocfs2/cluster/sys.c +21 -62
117 lines not on this page · raw message
Signature · 1 line
1.5.3.8
Re: [PATCH 093/196] kset: convert ocfs2 to use kset_create
Quoted 8 lines · Greg Kroah-Hartman
Dynamically create the kset instead of declaring it statically.
Also use the new
kobj_attributewhich cleans up this file a _lot_.Cc Kay Sievers <[email protected]>Cc Mark Fasheh <[email protected]>Cc Kurt Hackel <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
--
Mark Fasheh
Principal Software Developer, Oracle
[email protected]
PATCH 94/196 kset: convert block_subsys to use kset_create
In reply to Greg KHDynamically create the kset instead of declaring it statically. We also rename block_subsys to block_kset to catch all users of this symbol with a build error instead of an easy-to-ignore build warning.
--- block/genhd.c | 34 ++++++++++++++++------------------ fs/partitions/check.c | 6 +++--- 2 files changed, 19 insertions(+), 21 deletions(-)
block/genhd.c +16 -18
@@ -17,7 +17,8 @@#include <linux/buffer_head.h> #include <linux/mutex.h> -struct kset block_subsys; +struct kset *block_kset; +static struct kset_uevent_ops block_uevent_ops;static DEFINE_MUTEX (block_subsys_lock);/*
@@ -221,7 +222,7 @@ void __init printk_all_partitions(void)mutex_lock (&block_subsys_lock);/* For each block device... */ -list_for_each_entry (sgp, &block_subsys.list, kobj.entry) { +list_for_each_entry (sgp, &block_kset->list, kobj.entry) {char buf[BDEVNAME_SIZE ];/* * Don't show empty devices or things that have been surpressed
@@ -270,7 +271,7 @@ static void *part_start(struct seq_file *part, loff_t *pos)loff_t l = *pos;mutex_lock (&block_subsys_lock); -list_for_each (p, &block_subsys.list) +list_for_each (p, &block_kset->list)if (!l--) return list_entry(p, struct gendisk, kobj.entry);return NULL ;
@@ -280,7 +281,7 @@ static void *part_next(struct seq_file *part, void *v, loff_t *pos) {struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; ++*pos; -return p==&block_subsys.list ?NULL : +return p==&block_kset->list ?NULL : list_entry(p, struct gendisk, kobj.entry); }
@@ -295,7 +296,7 @@ static int show_partition(struct seq_file *part, void *v)int n;char buf[BDEVNAME_SIZE ]; -if (&sgp->kobj.entry == block_subsys.list.next) +if (&sgp->kobj.entry == block_kset->list.next)seq_puts (part,"major minor #blocks name\n\n" );/* Don't show non-partitionable removeable devices or empty devices */
@@ -345,15 +346,14 @@ static struct kobject *base_probe(dev_t dev, int *part, void *data)static int __init genhd_device_init (void ) { -int err; - bdev_map =kobj_map_init (base_probe, &block_subsys_lock);blk_dev_init (); - err =subsystem_register (&block_subsys); -if (err <0 ) -printk (KERN_WARNING "%s: subsystem_register error: %d\n" , - __FUNCTION__, err); -return err; + block_kset =kset_create_and_add ("block" , &block_uevent_ops,NULL ); +if (!block_kset) { +printk (KERN_WARNING "%s: kset_create error\n" , __FUNCTION__); +return -ENOMEM ; + } +return 0 ; }subsys_initcall (genhd_device_init);
@@ -584,8 +584,6 @@ static struct kset_uevent_ops block_uevent_ops = { .uevent = block_uevent, }; -decl_subsys (block, &block_uevent_ops); -/* * aggregate disk stat collector. Uses the same stats that the sysfs * entries do, above, but makes them available through one seq_file.
@@ -603,7 +601,7 @@ static void *diskstats_start(struct seq_file *part, loff_t *pos)struct list_head *p;mutex_lock (&block_subsys_lock); -list_for_each (p, &block_subsys.list) +list_for_each (p, &block_kset->list)if (!k--) return list_entry(p, struct gendisk, kobj.entry);return NULL ;
@@ -613,7 +611,7 @@ static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos) {struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; ++*pos; -return p==&block_subsys.list ?NULL : +return p==&block_kset->list ?NULL : list_entry(p, struct gendisk, kobj.entry); }
@@ -629,7 +627,7 @@ static int diskstats_show(struct seq_file *s, void *v)int n =0 ;/* -if (&sgp->kobj.entry == block_subsys.kset.list.next) +if (&sgp->kobj.entry == block_kset->list.next) seq_puts(s, "major minor name" " rio rmerge rsect ruse wio wmerge " "wsect wuse running use aveq"
@@ -721,7 +719,7 @@ struct gendisk *alloc_disk_node(int minors, int node_id) } } disk->minors = minors; - disk->kobj.kset = &block_subsys; + disk->kobj.kset = block_kset; disk->kobj.ktype = &ktype_block;kobject_init (&disk->kobj);rand_initialize_disk (disk);
fs/partitions/check.c +3 -3
@@ -316,7 +316,7 @@ static struct attribute * default_attrs[] = { NULL, }; -extern struct kset block_subsys; +extern struct kset *block_kset;static void part_release (struct kobject *kobj) {
@@ -393,7 +393,7 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len,kobject_add (&p->kobj);if (!disk->part_uevent_suppress)kobject_uevent (&p->kobj,KOBJ_ADD ); -sysfs_create_link (&p->kobj, &block_subsys.kobj,"subsystem" ); +sysfs_create_link (&p->kobj, &block_kset->kobj,"subsystem" );if (flags &ADDPART_FLAG_WHOLEDISK ) {static struct attribute addpartattr = { .name ="whole_disk" ,
@@ -448,7 +448,7 @@ static int disk_sysfs_symlinks(struct gendisk *disk) goto err_out_dev_link; } - err =sysfs_create_link (&disk->kobj, &block_subsys.kobj, + err =sysfs_create_link (&disk->kobj, &block_kset->kobj,"subsystem" );if (err) goto err_out_disk_name_lnk;
Signature · 1 line
1.5.3.8
PATCH 95/196 kset: remove decl_subsys macro
In reply to Greg KHThis macro is no longer used. ksets should be created dynamically with a call to kset_create_and_add() not declared statically.
Yes, there are 5 remaining static struct kset usages in the kernel tree, but they will be fixed up soon.
--- drivers/base/class.c | 11 +++++++++-- include/linux/kobject.h | 6 ------ 2 files changed, 9 insertions(+), 8 deletions(-)
drivers/base/class.c +9 -2
@@ -453,8 +453,15 @@ static struct kset_uevent_ops class_uevent_ops = { .uevent = class_uevent, }; -static decl_subsys(class_obj, &class_uevent_ops); - +/* +* DO NOT copy how this is created, kset_create_and_add() should be +* called, but this is a hold-over from the old-way and will be deleted +* entirely soon. +*/ +static struct kset class_obj_subsys = { + .kobj = { .k_name ="class_obj" , }, + .uevent_ops = &class_uevent_ops, +};static int class_device_add_attrs (struct class_device * cd) {
include/linux/kobject.h +0 -6
@@ -198,12 +198,6 @@ extern struct kobject * kset_find_obj(struct kset *, const char *);#define set_kset_name (str) .kset = { .kobj = { .k_name = str } } -#define decl_subsys (_name,_uevent_ops) \ -struct kset _name##_subsys = { \ - .kobj = { .k_name = __stringify(_name) }, \ - .uevent_ops =_uevent_ops, \ -} -/* The global /sys/kernel/ kset for people to chain off of */ extern struct kset *kernel_kset;/* The global /sys/hypervisor/ kobject for people to chain off of */
Signature · 1 line
1.5.3.8
PATCH 96/196 kobject: convert kernel_kset to be a kobject
In reply to Greg KHkernel_kset does not need to be a kset, but a much simpler kobject now that we have kobj_attributes.
We also rename kernel_kset to kernel_kobj to catch all users of this symbol with a build error instead of an easy-to-ignore build warning.
--- fs/configfs/mount.c | 2 +- fs/debugfs/inode.c | 2 +- fs/dlm/lockspace.c | 2 +- fs/gfs2/locking/dlm/sysfs.c | 2 +- include/linux/kobject.h | 4 ++-- kernel/ksysfs.c | 18 +++++++++--------- kernel/user.c | 2 +- mm/slub.c | 3 +-- security/inode.c | 2 +- 9 files changed, 18 insertions(+), 19 deletions(-)
fs/configfs/mount.c +1 -1
@@ -140,7 +140,7 @@ static int __init configfs_init(void)if (!configfs_dir_cachep) goto out; - config_kobj =kobject_create_and_add ("config" , &kernel_kset->kobj); + config_kobj =kobject_create_and_add ("config" , kernel_kobj);if (!config_kobj) {kmem_cache_destroy (configfs_dir_cachep); configfs_dir_cachep =NULL ;
fs/debugfs/inode.c +1 -1
@@ -432,7 +432,7 @@ static int __init debugfs_init(void) {int retval; - debug_kobj =kobject_create_and_add ("debug" , &kernel_kset->kobj); + debug_kobj =kobject_create_and_add ("debug" , kernel_kobj);if (!debug_kobj)return -EINVAL ;
fs/dlm/lockspace.c +1 -1
@@ -223,7 +223,7 @@ int dlm_lockspace_init(void)INIT_LIST_HEAD (&lslist);spin_lock_init (&lslist_lock); - dlm_kset =kset_create_and_add ("dlm" ,NULL , &kernel_kset->kobj); + dlm_kset =kset_create_and_add ("dlm" ,NULL , kernel_kobj);if (!dlm_kset) {printk (KERN_WARNING "%s: can not create kset\n" , __FUNCTION__);return -ENOMEM ;
fs/gfs2/locking/dlm/sysfs.c +1 -1
@@ -219,7 +219,7 @@ void gdlm_kobject_release(struct gdlm_ls *ls)int gdlm_sysfs_init (void ) { - gdlm_kset =kset_create_and_add ("lock_dlm" ,NULL , &kernel_kset->kobj); + gdlm_kset =kset_create_and_add ("lock_dlm" ,NULL , kernel_kobj);if (!gdlm_kset) {printk (KERN_WARNING "%s: can not create kset\n" , __FUNCTION__);return -ENOMEM ;
include/linux/kobject.h +2 -2
@@ -198,8 +198,8 @@ extern struct kobject * kset_find_obj(struct kset *, const char *);#define set_kset_name (str) .kset = { .kobj = { .k_name = str } } -/* The global /sys/kernel/ kset for people to chain off of */ -extern struct kset *kernel_kset; +/* The global /sys/kernel/ kobject for people to chain off of */ +extern struct kobject *kernel_kobj;/* The global /sys/hypervisor/ kobject for people to chain off of */ extern struct kobject *hypervisor_kobj;/* The global /sys/power/ kset for people to chain off of */
kernel/ksysfs.c +9 -9
@@ -101,8 +101,8 @@ static struct bin_attribute notes_attr = { .read = ¬es_read, }; -struct kset *kernel_kset; -EXPORT_SYMBOL_GPL (kernel_kset); +struct kobject *kernel_kobj; +EXPORT_SYMBOL_GPL (kernel_kobj); static struct attribute * kernel_attrs[] = {#if defined(CONFIG_HOTPLUG ) && defined(CONFIG_NET )
@@ -125,18 +125,18 @@ static int __init ksysfs_init(void) {int error; - kernel_kset =kset_create_and_add ("kernel" ,NULL ,NULL ); -if (!kernel_kset) { + kernel_kobj =kobject_create_and_add ("kernel" ,NULL ); +if (!kernel_kobj) { error = -ENOMEM ; goto exit; } - error =sysfs_create_group (&kernel_kset->kobj, &kernel_attr_group); + error =sysfs_create_group (kernel_kobj, &kernel_attr_group);if (error) goto kset_exit;if (notes_size >0 ) { notes_attr.size = notes_size; - error =sysfs_create_bin_file (&kernel_kset->kobj, ¬es_attr); + error =sysfs_create_bin_file (kernel_kobj, ¬es_attr);if (error) goto group_exit; }
@@ -150,11 +150,11 @@ static int __init ksysfs_init(void) notes_exit:if (notes_size >0 ) -sysfs_remove_bin_file (&kernel_kset->kobj, ¬es_attr); +sysfs_remove_bin_file (kernel_kobj, ¬es_attr); group_exit: -sysfs_remove_group (&kernel_kset->kobj, &kernel_attr_group); +sysfs_remove_group (kernel_kobj, &kernel_attr_group); kset_exit: -kset_unregister (kernel_kset); +kobject_unregister (kernel_kobj); exit:return error; }
kernel/user.c +1 -1
@@ -201,7 +201,7 @@ done:*/ int __init uids_sysfs_init (void ) { - uids_kset =kset_create_and_add ("uids" ,NULL , &kernel_kset->kobj); + uids_kset =kset_create_and_add ("uids" ,NULL , kernel_kobj);if (!uids_kset)return -ENOMEM ;
mm/slub.c +1 -2
@@ -4091,8 +4091,7 @@ static int __init slab_sysfs_init(void)struct kmem_cache *s;int err; - slab_kset =kset_create_and_add ("slab" , &slab_uevent_ops, - &kernel_kset->kobj); + slab_kset =kset_create_and_add ("slab" , &slab_uevent_ops, kernel_kobj);if (!slab_kset) {printk (KERN_ERR "Cannot register slab subsystem.\n" );return -ENOSYS ;
security/inode.c +1 -1
@@ -321,7 +321,7 @@ static int __init securityfs_init(void) {int retval; - security_kobj =kobject_create_and_add ("security" , &kernel_kset->kobj); + security_kobj =kobject_create_and_add ("security" , kernel_kobj);if (!security_kobj)return -EINVAL ;
Signature · 1 line
1.5.3.8
PATCH 97/196 kobject: remove subsystem_(un)register functions
In reply to Greg KHThese functions are no longer used and are the last remants of the old subsystem crap. So delete them for good.
--- drivers/base/bus.c | 6 +++--- drivers/base/class.c | 4 ++-- include/linux/kobject.h | 3 --- lib/kobject.c | 13 ------------- 4 files changed, 5 insertions(+), 21 deletions(-)
drivers/base/bus.c +3 -3
@@ -854,7 +854,7 @@ int bus_register(struct bus_type * bus) bus->subsys.kobj.kset = bus_kset; bus->subsys.kobj.ktype = &bus_ktype; - retval =subsystem_register (&bus->subsys); + retval =kset_register (&bus->subsys);if (retval) goto out;
@@ -900,7 +900,7 @@ bus_drivers_fail: bus_devices_fail:bus_remove_file (bus, &bus_attr_uevent); bus_uevent_fail: -subsystem_unregister (&bus->subsys); +kset_unregister (&bus->subsys); out:return retval; }
@@ -920,7 +920,7 @@ void bus_unregister(struct bus_type * bus)kset_unregister (bus->drivers_kset);kset_unregister (bus->devices_kset);bus_remove_file (bus, &bus_attr_uevent); -subsystem_unregister (&bus->subsys); +kset_unregister (&bus->subsys); }int bus_register_notifier (struct bus_type *bus,struct notifier_block *nb)
drivers/base/class.c +2 -2
@@ -152,7 +152,7 @@ int class_register(struct class * cls) cls->subsys.kobj.kset = class_kset; cls->subsys.kobj.ktype = &class_ktype; - error =subsystem_register (&cls->subsys); + error =kset_register (&cls->subsys);if (!error) { error =add_class_attrs (class_get (cls));class_put (cls);
@@ -164,7 +164,7 @@ void class_unregister(struct class * cls) {pr_debug ("device class '%s': unregistering\n" , cls->name);remove_class_attrs (cls); -subsystem_unregister (&cls->subsys); +kset_unregister (&cls->subsys); }static void class_create_release (struct class *cls)
include/linux/kobject.h +0 -3
@@ -207,9 +207,6 @@ extern struct kset *power_kset;/* The global /sys/firmware/ kobject for people to chain off of */ extern struct kobject *firmware_kobj; -extern int __must_check subsystem_register (struct kset *); -extern void subsystem_unregister (struct kset *); -#if defined(CONFIG_HOTPLUG )int kobject_uevent (struct kobject *kobj,enum kobject_action action); int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
lib/kobject.c +0 -13
@@ -800,16 +800,6 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)return ret; } -int subsystem_register (struct kset *s) -{ -return kset_register (s); -} - -void subsystem_unregister (struct kset *s) -{ -kset_unregister (s); -} -static void kset_release (struct kobject *kobj) { struct kset *kset = container_of(kobj, struct kset, kobj);
@@ -904,6 +894,3 @@ EXPORT_SYMBOL(kobject_del);EXPORT_SYMBOL (kset_register);EXPORT_SYMBOL (kset_unregister); - -EXPORT_SYMBOL (subsystem_register); -EXPORT_SYMBOL (subsystem_unregister);
Signature · 1 line
1.5.3.8
PATCH 98/196 kobject: clean up rpadlpar horrid sysfs abuse
In reply to Greg KHrpadlpar pci hotplug driver was doing some pretty bad stuff with the sysfs files. This cleans up the logic to be sane and gets rid of the gratuitous kset that is not needed for a simple directory like this.
Note, this patch is not even build tested, let alone run-time tested. Someone with access to this hardware and can test would be greatly appreciated.
--- drivers/pci/hotplug/rpadlpar_sysfs.c | 112 +++++++++++++--------------------- 1 files changed, 43 insertions(+), 69 deletions(-)
drivers/pci/hotplug/rpadlpar_sysfs.c +43 -69
@@ -23,44 +23,13 @@#define MAX_DRC_NAME_LEN 64 -/* Store return code of dlpar operation in attribute struct */ -struct dlpar_io_attr { -int rc; -struct attribute attr; -ssize_t (*store)(struct dlpar_io_attr *dlpar_attr,const char *buf, -size_t nbytes); -}; -/* Common show callback for all attrs, display the return code -* of the dlpar op */ -static ssize_t -dlpar_attr_show (struct kobject * kobj,struct attribute * attr,char * buf) -{ -struct dlpar_io_attr *dlpar_attr =container_of (attr, - struct dlpar_io_attr, attr); -return sprintf (buf,"%d\n" , dlpar_attr->rc); -} - -static ssize_t -dlpar_attr_store (struct kobject * kobj,struct attribute * attr, -const char *buf,size_t nbytes) -{ -struct dlpar_io_attr *dlpar_attr =container_of (attr, - struct dlpar_io_attr, attr); -return dlpar_attr->store ? - dlpar_attr->store (dlpar_attr, buf, nbytes) : -EIO ; -} - -static struct sysfs_ops dlpar_attr_sysfs_ops = { - .show = dlpar_attr_show, - .store = dlpar_attr_store, -}; - -static ssize_t add_slot_store (struct dlpar_io_attr *dlpar_attr, -const char *buf,size_t nbytes) +static ssize_t add_slot_store (struct kobject *kobj,struct kobj_attribute *attr, +const char *buf,size_t nbytes) {char drc_name[MAX_DRC_NAME_LEN ];char *end; +int rc;if (nbytes >=MAX_DRC_NAME_LEN )return 0 ;
@@ -72,15 +41,25 @@ static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr, end = &drc_name[nbytes]; *end ='\0' ; - dlpar_attr->rc =dlpar_add_slot (drc_name); + rc =dlpar_add_slot (drc_name); +if (rc) +return rc;return nbytes; } -static ssize_t remove_slot_store (struct dlpar_io_attr *dlpar_attr, -const char *buf,size_t nbytes) +static ssize_t add_slot_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sprintf (buf,"0\n" ); +} + +static ssize_t remove_slot_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t nbytes) {char drc_name[MAX_DRC_NAME_LEN ]; +int rc;char *end;if (nbytes >=MAX_DRC_NAME_LEN )
@@ -93,22 +72,24 @@ static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr, end = &drc_name[nbytes]; *end ='\0' ; - dlpar_attr->rc =dlpar_remove_slot (drc_name); + rc =dlpar_remove_slot (drc_name); +if (rc) +return rc;return nbytes; } -static struct dlpar_io_attr add_slot_attr = { - .rc =0 , - .attr = { .name =ADD_SLOT_ATTR_NAME , .mode =0644 , }, - .store = add_slot_store, -}; +static ssize_t remove_slot_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sprintf (buf,"0\n" ); +} -static struct dlpar_io_attr remove_slot_attr = { - .rc =0 , - .attr = { .name =REMOVE_SLOT_ATTR_NAME , .mode =0644 }, - .store = remove_slot_store, -}; +static struct kobj_attribute add_slot_attr = +__ATTR (ADD_SLOT_ATTR_NAME ,0644 , add_slot_show, add_slot_store); + +static struct kobj_attribute remove_slot_attr = +__ATTR (REMOVE_SLOT_ATTR_NAME ,0644 , remove_slot_show, remove_slot_store);static struct attribute *default_attrs[] = { &add_slot_attr.attr,
@@ -116,36 +97,29 @@ static struct attribute *default_attrs[] = { NULL, }; -static void dlpar_io_release (struct kobject *kobj) -{ -/* noop */ -return ; -} - -struct kobj_type ktype_dlpar_io = { - .release = dlpar_io_release, - .sysfs_ops = &dlpar_attr_sysfs_ops, - .default_attrs = default_attrs, +static struct attribute_group dlpar_attr_group = { + .attrs = default_attrs, }; -struct kset dlpar_io_kset = { - .kobj = {.ktype = &ktype_dlpar_io, - .parent = &pci_hotplug_slots_kset->kobj}, -}; +static struct kobject *dlpar_kobj;int dlpar_sysfs_init (void ) { -kobject_set_name (&dlpar_io_kset.kobj,DLPAR_KOBJ_NAME ); -if (kset_register (&dlpar_io_kset)) { -printk (KERN_ERR "rpadlpar_io: cannot register kset for %s\n" , -kobject_name (&dlpar_io_kset.kobj)); +int error; + + dlpar_kobj =kobject_create_and_add (DLPAR_KOBJ_NAME , + &pci_hotplug_slots_kset->kobj); +if (!dlpar_kobj)return -EINVAL ; - } -return 0 ; + error =sysfs_create_group (dlpar_kobj, &dlpar_attr_group); +if (error) +kobject_unregister (dlpar_kobj); +return error; }void dlpar_sysfs_exit (void ) { -kset_unregister (&dlpar_io_kset); +sysfs_remove_group (dlpar_kobj, &dlpar_attr_group); +kobject_unregister (dlpar_kobj); }
Signature · 1 line
1.5.3.8
PATCH 99/196 kobject: convert ecryptfs to use kobject_create
In reply to Greg KHUsing a kset for this trivial directory is an overkill.
--- fs/ecryptfs/main.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
fs/ecryptfs/main.c +7 -7
@@ -734,7 +734,7 @@ static int ecryptfs_init_kmem_caches(void)return 0 ; } -static struct kset *ecryptfs_kset; +static struct kobject *ecryptfs_kobj;static ssize_t version_show (struct kobject *kobj,struct kobj_attribute *attr,char *buff)
@@ -757,17 +757,17 @@ static int do_sysfs_registration(void) {int rc; - ecryptfs_kset =kset_create_and_add ("ecryptfs" ,NULL , fs_kobj); -if (!ecryptfs_kset) { + ecryptfs_kobj =kobject_create_and_add ("ecryptfs" , fs_kobj); +if (!ecryptfs_kobj) {printk (KERN_ERR "Unable to create ecryptfs kset\n" ); rc = -ENOMEM ; goto out; } - rc =sysfs_create_group (&ecryptfs_kset->kobj, &attr_group); + rc =sysfs_create_group (ecryptfs_kobj, &attr_group);if (rc) {printk (KERN_ERR "Unable to create ecryptfs version attributes\n" ); -kset_unregister (ecryptfs_kset); +kobject_unregister (ecryptfs_kobj); } out:return rc;
@@ -775,8 +775,8 @@ out:static void do_sysfs_unregistration (void ) { -sysfs_remove_group (&ecryptfs_kset->kobj, &attr_group); -kset_unregister (ecryptfs_kset); +sysfs_remove_group (ecryptfs_kobj, &attr_group); +kobject_unregister (ecryptfs_kobj); }static int __init ecryptfs_init (void )
Signature · 1 line
1.5.3.8
PATCH 100/196 kobject: convert efivars to use kobject_create
In reply to Greg KHUsing a kset for this simple directory is an overkill.
--- drivers/firmware/efivars.c | 18 ++++++++---------- 1 files changed, 8 insertions(+), 10 deletions(-)
drivers/firmware/efivars.c +8 -10
@@ -573,7 +573,7 @@ static struct attribute_group efi_subsys_attr_group = {static struct kset *vars_kset; -static struct kset *efi_kset; +static struct kobject *efi_kobj;/* * efivar_create_sysfs_entry()
@@ -665,17 +665,15 @@ efivars_init(void)printk (KERN_INFO "EFI Variables Facility v%s %s\n" ,EFIVARS_VERSION ,EFIVARS_DATE ); -/* -* For now we'll register the efi subsys within this driver -*/ - efi_kset =kset_create_and_add ("efi" ,NULL , firmware_kobj); -if (!efi_kset) { +/* For now we'll register the efi directory at /sys/firmware/efi */ + efi_kobj =kobject_create_and_add ("efi" , firmware_kobj); +if (!efi_kobj) {printk (KERN_ERR "efivars: Firmware registration failed.\n" ); error = -ENOMEM ; goto out_free; } - vars_kset =kset_create_and_add ("vars" ,NULL , &efi_kset->kobj); + vars_kset =kset_create_and_add ("vars" ,NULL , efi_kobj);if (!vars_kset) {printk (KERN_ERR "efivars: Subsystem registration failed.\n" ); error = -ENOMEM ;
@@ -725,7 +723,7 @@ efivars_init(void) " due to error %d\n", error);/* Don't forget the systab entry */ - error =sysfs_create_group (&efi_kset->kobj, &efi_subsys_attr_group); + error =sysfs_create_group (efi_kobj, &efi_subsys_attr_group);if (error)printk (KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n" , error);else
@@ -734,7 +732,7 @@ efivars_init(void)kset_unregister (vars_kset); out_firmware_unregister: -kset_unregister (efi_kset); +kobject_unregister (efi_kobj); out_free:kfree (variable_name);
@@ -755,7 +753,7 @@ efivars_exit(void) }kset_unregister (vars_kset); -kset_unregister (efi_kset); +kobject_unregister (efi_kobj); }module_init (efivars_init);
Signature · 1 line
1.5.3.8
PATCH 101/196 kobject: convert parisc/pdc_stable to use kobject_create
In reply to Greg KHUsing a kset for this simple directory is an overkill.
--- drivers/parisc/pdc_stable.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
drivers/parisc/pdc_stable.c +8 -8
@@ -960,7 +960,7 @@ static struct attribute_group pdcs_attr_group = { .attrs = pdcs_subsys_attrs, }; -static struct kset *stable_kset; +static struct kobject *stable_kobj;static struct kset *paths_kset;/**
@@ -1058,18 +1058,18 @@ pdc_stable_init(void)/* the actual result is 16 bits away */ pdcs_osid = (u16)(result >>16 ); -/* For now we'll register the stable kset within this driver */ - stable_kset =kset_create_and_add ("stable" ,NULL , firmware_kobj); -if (!stable_kset) { +/* For now we'll register the directory at /sys/firmware/stable */ + stable_kobj =kobject_create_and_add ("stable" , firmware_kobj); +if (!stable_kobj) { rc = -ENOMEM ; goto fail_firmreg; }/* Don't forget the root entries */ - error =sysfs_create_group (&stable_kset->kobj, pdcs_attr_group); + error =sysfs_create_group (stable_kobj, pdcs_attr_group);/* register the paths kset as a child of the stable kset */ - paths_kset =kset_create_and_add ("paths" ,NULL , &stable_kset->kobj); + paths_kset =kset_create_and_add ("paths" ,NULL , stable_kobj);if (!paths_kset) { rc = -ENOMEM ; goto fail_ksetreg;
@@ -1086,7 +1086,7 @@ fail_pdcsreg:kset_unregister (paths_kset); fail_ksetreg: -kset_unregister (stable_kset); +kobject_unregister (stable_kobj); fail_firmreg: printk(KERN_INFO PDCS_PREFIX " bailing out\n");
@@ -1098,7 +1098,7 @@ pdc_stable_exit(void) {pdcs_unregister_pathentries ();kset_unregister (paths_kset); -kset_unregister (stable_kset); +kobject_unregister (stable_kobj); }
Signature · 1 line
1.5.3.8
PATCH 102/196 driver core: clean up shutdown.c
In reply to Greg KHshutdown.c had some stuff it did not need, including a duplicate extern in the power.h file. This cleans up all of that.
--- drivers/base/power/power.h | 7 ------- drivers/base/power/shutdown.c | 5 ----- 2 files changed, 0 insertions(+), 12 deletions(-)
drivers/base/power/power.h +0 -7
@@ -1,10 +1,3 @@ -/* -* shutdown.c -*/ - -extern void device_shutdown (void ); - -#ifdef CONFIG_PM_SLEEP /*
drivers/base/power/shutdown.c +0 -5
@@ -12,10 +12,6 @@#include <asm/semaphore.h> #include "../base.h" -#include "power.h" - -#define to_dev (node) container_of(node, struct device, kobj.entry) -/** * We handle system devices differently - we suspend and shut them
@@ -45,4 +41,3 @@ void device_shutdown(void) } } } -
Signature · 1 line
1.5.3.8
PATCH 103/196 driver core: clean up device_shutdown
In reply to Greg KHdevice_shutdown does not need to be in a separate file. Move it into the driver core file where it belongs.
This also moves us one more step closer to making devices_kset static, now only the crazy sysdevs are keeping that from happening...
--- drivers/base/core.c | 20 ++++++++++++++++++- drivers/base/power/Makefile | 1 - drivers/base/power/shutdown.c | 43 ----------------------------------------- 3 files changed, 19 insertions(+), 45 deletions(-) delete mode 100644 drivers/base/power/shutdown.c
drivers/base/core.c +19 -1
@@ -1415,5 +1415,23 @@ out:put_device (dev);return error; } -EXPORT_SYMBOL_GPL (device_move); + +/** +* device_shutdown - call ->shutdown() on each device to shutdown. +*/ +void device_shutdown (void ) +{ +struct device * dev, *devn; + +list_for_each_entry_safe_reverse (dev, devn, &devices_kset->list, + kobj.entry) { +if (dev->bus && dev->bus->shutdown) { +dev_dbg (dev,"shutdown\n" ); + dev->bus->shutdown (dev); + }else if (dev->driver && dev->driver->shutdown) { +dev_dbg (dev,"shutdown\n" ); + dev->driver->shutdown (dev); + } + } +}
drivers/base/power/Makefile +0 -1
@@ -1,4 +1,3 @@ -obj-y := shutdown.o obj-$(CONFIG_PM) += sysfs.o obj-$(CONFIG_PM_SLEEP) += main.o obj-$(CONFIG_PM_TRACE) += trace.o
drivers/base/power/shutdown.c deleted +0 -43
43 lines not on this page · raw message
Signature · 1 line
1.5.3.8
PATCH 104/196 driver core: make /sys/power a kobject
In reply to Greg KH/sys/power should not be a kset, that's overkill. This patch renames it to power_kset and fixes up all usages of it in the tree.
--- arch/arm/mach-omap1/pm.c | 2 +- arch/powerpc/platforms/pseries/power.c | 10 +++++----- include/linux/kobject.h | 4 ++-- kernel/power/disk.c | 2 +- kernel/power/main.c | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-)
arch/arm/mach-omap1/pm.c +1 -1
@@ -719,7 +719,7 @@ static int __init omap_pm_init(void)omap_pm_init_proc ();#endif - error =sysfs_create_file (&power_kset->kobj, &sleep_while_idle_attr); + error =sysfs_create_file (power_kobj, &sleep_while_idle_attr);if (error)printk (KERN_ERR "sysfs_create_file failed: %d\n" , error);
arch/powerpc/platforms/pseries/power.c +5 -5
@@ -53,7 +53,7 @@ static struct kobj_attribute auto_poweron_attr =__ATTR (auto_poweron,0644 , auto_poweron_show, auto_poweron_store);#ifndef CONFIG_PM -struct kset *power_kset; +struct kobject *power_kobj;static struct attribute *g[] = { &auto_poweron_attr.attr,
@@ -66,16 +66,16 @@ static struct attribute_group attr_group = {static int __init pm_init (void ) { - power_kset =kset_create_and_add ("power" ,NULL ,NULL ); -if (!power_kset) + power_kobj =kobject_create_and_add ("power" ,NULL ); +if (!power_kobj)return -ENOMEM ; -return sysfs_create_group (&power_kset->kobj, &attr_group); +return sysfs_create_group (power_kobj, &attr_group); }core_initcall (pm_init);#else static int __init apo_pm_init (void ) { -return (sysfs_create_file (&power_kset->kobj, &auto_poweron_attr)); +return (sysfs_create_file (power_kobj, &auto_poweron_attr)); }__initcall (apo_pm_init);#endif
include/linux/kobject.h +2 -2
@@ -202,8 +202,8 @@ extern struct kobject * kset_find_obj(struct kset *, const char *);extern struct kobject *kernel_kobj;/* The global /sys/hypervisor/ kobject for people to chain off of */ extern struct kobject *hypervisor_kobj; -/* The global /sys/power/ kset for people to chain off of */ -extern struct kset *power_kset; +/* The global /sys/power/ kobject for people to chain off of */ +extern struct kobject *power_kobj;/* The global /sys/firmware/ kobject for people to chain off of */ extern struct kobject *firmware_kobj;
kernel/power/disk.c +1 -1
@@ -714,7 +714,7 @@ static struct attribute_group attr_group = {static int __init pm_disk_init (void ) { -return sysfs_create_group (&power_kset->kobj, &attr_group); +return sysfs_create_group (power_kobj, &attr_group); }core_initcall (pm_disk_init);
kernel/power/main.c +4 -4
@@ -276,7 +276,7 @@ EXPORT_SYMBOL(pm_suspend);#endif /* CONFIG_SUSPEND */ -struct kset *power_kset; +struct kobject *power_kobj;/** * state - control system power state.
@@ -389,10 +389,10 @@ static struct attribute_group attr_group = {static int __init pm_init (void ) { - power_kset =kset_create_and_add ("power" ,NULL ,NULL ); -if (!power_kset) + power_kobj =kobject_create_and_add ("power" ,NULL ); +if (!power_kobj)return -ENOMEM ; -return sysfs_create_group (&power_kset->kobj, &attr_group); +return sysfs_create_group (power_kobj, &attr_group); }core_initcall (pm_init);
Signature · 1 line
1.5.3.8
PATCH 105/196 kobject: grab the kset reference in kobject_add, not kobject_init
In reply to Greg KHkobject_init should not be grabing any references, but only initializing the object. This patch fixes this, and makes the lock hold-time shorter for when a kset is present in the kobject.
The current kernel tree has been audited to verify that this change should be safe.
--- lib/kobject.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
lib/kobject.c +3 -3
@@ -133,7 +133,6 @@ void kobject_init(struct kobject * kobj)return ;kref_init (&kobj->kref);INIT_LIST_HEAD (&kobj->entry); - kobj->kset =kset_get (kobj->kset); }
@@ -184,7 +183,7 @@ int kobject_add(struct kobject * kobj) kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );if (kobj->kset) { -spin_lock (&kobj->kset->list_lock); + kobj->kset =kset_get (kobj->kset);if (!parent) { parent =kobject_get (&kobj->kset->kobj);
@@ -196,7 +195,8 @@ int kobject_add(struct kobject * kobj)kobject_get (parent); } -list_add_tail (&kobj->entry,&kobj->kset->list); +spin_lock (&kobj->kset->list_lock); +list_add_tail (&kobj->entry, &kobj->kset->list);spin_unlock (&kobj->kset->list_lock); kobj->parent = parent; }
Signature · 1 line
1.5.3.8
PATCH 106/196 kobject: clean up debugging messages
In reply to Greg KHThe kobject debugging messages are a mess. This provides a unified message that makes them actually useful.
The format for new kobject debug messages should be:
kobject: 'KOBJECT_NAME' (ADDRESS): FUNCTION_NAME: message.\n
--- lib/kobject.c | 23 +++++++++++++++-------- lib/kobject_uevent.c | 20 ++++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-)
lib/kobject.c +15 -8
@@ -95,7 +95,8 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length) *(path + --length) ='/' ; } -pr_debug ("%s: path = '%s'\n" ,__FUNCTION__,path); +pr_debug ("kobject: '%s' (%p): %s: path = '%s'\n" ,kobject_name (kobj), + kobj, __FUNCTION__,path); }/**
@@ -171,15 +172,17 @@ int kobject_add(struct kobject * kobj)if (!kobj->k_name)kobject_set_name (kobj,"NO_NAME" );if (!*kobj->k_name) { -pr_debug ("kobject attempted to be registered with no name!\n" ); +pr_debug ("kobject (%p) attempted to be registered with no " +"name!\n" , kobj);WARN_ON (1 );kobject_put (kobj);return -EINVAL ; } parent =kobject_get (kobj->parent); -pr_debug ("kobject %s: registering. parent: %s, set: %s\n" , -kobject_name (kobj), parent ?kobject_name (parent) :"<NULL>" , +pr_debug ("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n" , +kobject_name (kobj), kobj, __FUNCTION__, + parent ?kobject_name (parent) :"<NULL>" , kobj->kset ?kobject_name (&kobj->kset->kobj) :"<NULL>" );if (kobj->kset) {
@@ -560,7 +563,8 @@ void kobject_unregister(struct kobject * kobj) {if (!kobj)return ; -pr_debug ("kobject %s: unregistering\n" ,kobject_name (kobj)); +pr_debug ("kobject: '%s' (%p): %s\n" , +kobject_name (kobj), kobj, __FUNCTION__);kobject_uevent (kobj,KOBJ_REMOVE );kobject_del (kobj);kobject_put (kobj);
@@ -589,7 +593,8 @@ static void kobject_cleanup(struct kobject *kobj)struct kobject * parent = kobj->parent;const char *name = kobj->k_name; -pr_debug ("kobject %s: cleaning up\n" ,kobject_name (kobj)); +pr_debug ("kobject: '%s' (%p): %s\n" , +kobject_name (kobj), kobj, __FUNCTION__);if (t && t->release) { t->release (kobj);/* If we have a release function, we can guess that this was
@@ -621,7 +626,8 @@ void kobject_put(struct kobject * kobj)static void dynamic_kobj_release (struct kobject *kobj) { -pr_debug ("%s: freeing %s\n" , __FUNCTION__,kobject_name (kobj)); +pr_debug ("kobject: '%s' (%p): %s\n" , +kobject_name (kobj), kobj, __FUNCTION__);kfree (kobj); }
@@ -803,7 +809,8 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)static void kset_release (struct kobject *kobj) { struct kset *kset = container_of(kobj, struct kset, kobj); -pr_debug ("kset %s: now freed\n" ,kobject_name (kobj)); +pr_debug ("kobject: '%s' (%p): %s\n" , +kobject_name (kobj), kobj, __FUNCTION__);kfree (kset); }
lib/kobject_uevent.c +14 -6
@@ -98,7 +98,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,int i =0 ;int retval =0 ; -pr_debug ("%s\n" , __FUNCTION__); +pr_debug ("kobject: '%s' (%p): %s\n" , +kobject_name (kobj), kobj, __FUNCTION__);/* search the kset we belong to */ top_kobj = kobj;
@@ -106,7 +107,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, top_kobj = top_kobj->parent;if (!top_kobj->kset) { -pr_debug ("kobject attempted to send uevent without kset!\n" ); +pr_debug ("kobject: '%s' (%p): %s: attempted to send uevent " +"without kset!\n" ,kobject_name (kobj), kobj, + __FUNCTION__);return -EINVAL ; }
@@ -116,7 +119,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,/* skip the event, if the filter returns zero. */ if (uevent_ops && uevent_ops->filter)if (!uevent_ops->filter (kset, kobj)) { -pr_debug ("kobject filter function caused the event to drop!\n" ); +pr_debug ("kobject: '%s' (%p): %s: filter function " +"caused the event to drop!\n" , +kobject_name (kobj), kobj, __FUNCTION__);return 0 ; }
@@ -126,7 +131,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,else subsystem =kobject_name (&kset->kobj);if (!subsystem) { -pr_debug ("unset subsystem caused the event to drop!\n" ); +pr_debug ("kobject: '%s' (%p): %s: unset subsystem caused the " +"event to drop!\n" ,kobject_name (kobj), kobj, + __FUNCTION__);return 0 ; }
@@ -166,8 +173,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,if (uevent_ops && uevent_ops->uevent) { retval = uevent_ops->uevent (kset, kobj, env);if (retval) { -pr_debug ("%s - uevent() returned %d\n" , - __FUNCTION__, retval); +pr_debug ("kobject: '%s' (%p): %s: uevent() returned " +"%d\n" ,kobject_name (kobj), kobj, + __FUNCTION__, retval); goto exit; } }
Signature · 1 line
1.5.3.8
PATCH 107/196 UIO: fix kobject usage
In reply to Greg KHThe uio kobject code is "wierd". This patch should hopefully fix it up to be sane and not leak memory anymore.
--- drivers/uio/uio.c | 91 +++++++++++++++++++++++--------------------- include/linux/uio_driver.h | 6 ++- 2 files changed, 52 insertions(+), 45 deletions(-)
drivers/uio/uio.c +48 -43
@@ -34,7 +34,7 @@ struct uio_device {wait_queue_head_t wait;int vma_count;struct uio_info *info; -struct kset map_attr_kset; +struct kobject *map_dir; };static int uio_major;
@@ -51,47 +51,48 @@ static struct uio_class {* attributes */ -static struct attribute attr_addr = { - .name ="addr" , - .mode =S_IRUGO , +struct uio_map { +struct kobject kobj; +struct uio_mem *mem; }; +#define to_map (map) container_of(map, struct uio_map, kobj) -static struct attribute attr_size = { - .name ="size" , - .mode =S_IRUGO , -}; -static struct attribute * map_attrs[] = { - &attr_addr, &attr_size,NULL -}; - -static ssize_t map_attr_show (struct kobject *kobj,struct attribute *attr, +static ssize_t map_attr_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) { - struct uio_mem *mem = container_of(kobj, struct uio_mem, kobj); +struct uio_map *map =to_map (kobj); +struct uio_mem *mem = map->mem; -if (strncmp (attr->name,"addr" ,4 ) ==0 ) +if (strncmp (attr->attr.name,"addr" ,4 ) ==0 )return sprintf (buf,"0x%lx\n" , mem->addr); -if (strncmp (attr->name,"size" ,4 ) ==0 ) +if (strncmp (attr->attr.name,"size" ,4 ) ==0 )return sprintf (buf,"0x%lx\n" , mem->size);return -ENODEV ; } -static void map_attr_release (struct kobject *kobj) -{ -/* TODO ??? */ -} +static struct kobj_attribute attr_attribute = +__ATTR (addr,S_IRUGO , map_attr_show,NULL ); +static struct kobj_attribute size_attribute = +__ATTR (size,S_IRUGO , map_attr_show,NULL ); -static struct sysfs_ops map_attr_ops = { - .show = map_attr_show, +static struct attribute *attrs[] = { + &attr_attribute.attr, + &size_attribute.attr, +NULL ,/* need to NULL terminate the list of attributes */ }; +static void map_release (struct kobject *kobj) +{ +struct uio_map *map =to_map (kobj); +kfree (map); +} +static struct kobj_type map_attr_type = { - .release = map_attr_release, - .sysfs_ops = &map_attr_ops, - .default_attrs = map_attrs, + .release = map_release, + .default_attrs = attrs, }; static ssize_t show_name(struct device *dev,
@@ -148,6 +149,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)int mi;int map_found =0 ;struct uio_mem *mem; +struct uio_map *map; ret =sysfs_create_group (&idev->dev->kobj, &uio_attr_grp);if (ret)
@@ -159,31 +161,34 @@ static int uio_dev_add_attributes(struct uio_device *idev)break ;if (!map_found) { map_found =1 ; -kobject_set_name (&idev->map_attr_kset.kobj,"maps" ); - idev->map_attr_kset.kobj.ktype = &map_attr_type; - idev->map_attr_kset.kobj.parent = &idev->dev->kobj; - ret =kset_register (&idev->map_attr_kset); -if (ret) - goto err_remove_group; + idev->map_dir =kobject_create_and_add ("maps" , + &idev->dev->kobj); +if (!idev->map_dir) + goto err; } -kobject_init (&mem->kobj); -kobject_set_name (&mem->kobj,"map%d" ,mi); - mem->kobj.parent = &idev->map_attr_kset.kobj; - mem->kobj.kset = &idev->map_attr_kset; - ret =kobject_add (&mem->kobj); + map =kzalloc (sizeof (*map),GFP_KERNEL ); +if (!map) + goto err; +kobject_init_ng (&map->kobj, &map_attr_type); + map->mem = mem; + mem->map = map; + ret =kobject_add_ng (&map->kobj, idev->map_dir,"map%d" , mi); +if (ret) + goto err; + ret =kobject_uevent (&map->kobj,KOBJ_ADD );if (ret) - goto err_remove_maps; + goto err; }return 0 ; -err_remove_maps: +err:for (mi--; mi>=0 ; mi--) { mem = &idev->info->mem[mi]; -kobject_unregister (&mem->kobj); + map = mem->map; +kobject_unregister (&map->kobj); } -kset_unregister (&idev->map_attr_kset);/* Needed ? */ -err_remove_group: +kobject_unregister (idev->map_dir);sysfs_remove_group (&idev->dev->kobj, &uio_attr_grp); err_group:dev_err (idev->dev,"error creating sysfs files (%d)\n" , ret);
@@ -198,9 +203,9 @@ static void uio_dev_del_attributes(struct uio_device *idev) mem = &idev->info->mem[mi];if (mem->size ==0 )break ; -kobject_unregister (&mem->kobj); +kobject_unregister (&mem->map->kobj); } -kset_unregister (&idev->map_attr_kset); +kobject_unregister (idev->map_dir);sysfs_remove_group (&idev->dev->kobj, &uio_attr_grp); }
include/linux/uio_driver.h +4 -2
@@ -18,20 +18,22 @@#include <linux/fs.h> #include <linux/interrupt.h> +struct uio_map ; +/** * struct uio_mem - description of a UIO memory region -* @kobj: kobject for this mapping * @addr: address of the device's memory * @size: size of IO * @memtype: type of memory addr points to * @internal_addr: ioremap-ped version of addr, for driver internal use +* @map: for use by the UIO core only. */ struct uio_mem { -struct kobject kobj;unsigned long addr;unsigned long size;int memtype;void __iomem *internal_addr; +struct uio_map *map; };#define MAX_UIO_MAPS 5
Signature · 1 line
1.5.3.8
PATCH 108/196 Kobject: change net/bridge to use kobject_create_and_add
In reply to Greg KHThe kobject in the bridge code is only used for registering with sysfs, not for any lifespan rules. This patch changes it to be only a pointer and use the simpler api for this kind of thing.
--- net/bridge/br_if.c | 2 +- net/bridge/br_private.h | 2 +- net/bridge/br_sysfs_br.c | 14 ++++---------- net/bridge/br_sysfs_if.c | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-)
net/bridge/br_if.c +1 -1
@@ -133,7 +133,7 @@ static void del_nbp(struct net_bridge_port *p)struct net_bridge *br = p->br;struct net_device *dev = p->dev; -sysfs_remove_link (&br->ifobj, dev->name); +sysfs_remove_link (br->ifobj, dev->name);dev_set_promiscuity (dev,-1 );
net/bridge/br_private.h +1 -1
@@ -124,7 +124,7 @@ struct net_bridgestruct timer_list tcn_timer;struct timer_list topology_change_timer;struct timer_list gc_timer; -struct kobject ifobj; +struct kobject *ifobj; };extern struct notifier_block br_device_notifier;
net/bridge/br_sysfs_br.c +4 -10
@@ -426,16 +426,10 @@ int br_sysfs_addbr(struct net_device *dev) goto out2; } - -kobject_set_name (&br->ifobj,SYSFS_BRIDGE_PORT_SUBDIR ); - br->ifobj.ktype =NULL ; - br->ifobj.kset =NULL ; - br->ifobj.parent = brobj; - - err =kobject_register (&br->ifobj); -if (err) { + br->ifobj =kobject_create_and_add (SYSFS_BRIDGE_PORT_SUBDIR , brobj); +if (!br->ifobj) {pr_info ("%s: can't add kobject (directory) %s/%s\n" , - __FUNCTION__, dev->name,kobject_name (&br->ifobj)); + __FUNCTION__, dev->name,SYSFS_BRIDGE_PORT_SUBDIR ); goto out3; }return 0 ;
@@ -453,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)struct kobject *kobj = &dev->dev.kobj;struct net_bridge *br =netdev_priv (dev); -kobject_unregister (&br->ifobj); +kobject_unregister (br->ifobj);sysfs_remove_bin_file (kobj, &bridge_forward);sysfs_remove_group (kobj, &bridge_group); }
net/bridge/br_sysfs_if.c +1 -1
@@ -229,7 +229,7 @@ int br_sysfs_addif(struct net_bridge_port *p) goto out2; } - err=sysfs_create_link (&br->ifobj, &p->kobj, p->dev->name); + err =sysfs_create_link (br->ifobj, &p->kobj, p->dev->name); out2:return err; }
Signature · 1 line
1.5.3.8
Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add
Quoted 78 lines · On Thu, 24 Jan 2008 23:32:17 -0800 Greg Kroah-Hartman <[email protected]> wrote:
The kobject in the bridge code is only used for registering with sysfs, not for any lifespan rules. This patch changes it to be only a pointer and use the simpler api for this kind of thing.
Cc Stephen Hemminger <[email protected]>Cc Kay Sievers <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/bridge/br_if.c | 2 +- net/bridge/br_private.h | 2 +- net/bridge/br_sysfs_br.c | 14 ++++---------- net/bridge/br_sysfs_if.c | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-)net/bridge/br_if.c +1
-1@@ -133,7 +133,7 @@ static void del_nbp(struct net_bridge_port *p)struct net_bridge *br = p->br;struct net_device *dev = p->dev; -sysfs_remove_link (&br->ifobj, dev->name); +sysfs_remove_link (br->ifobj, dev->name);dev_set_promiscuity (dev,-1 );net/bridge/br_private.h +1
-1@@ -124,7 +124,7 @@ struct net_bridgestruct timer_list tcn_timer;struct timer_list topology_change_timer;struct timer_list gc_timer; -struct kobject ifobj; +struct kobject *ifobj; };extern struct notifier_block br_device_notifier;net/bridge/br_sysfs_br.c +4
-10@@ -426,16 +426,10 @@ int br_sysfs_addbr(struct net_device *dev) goto out2; } - -kobject_set_name (&br->ifobj,SYSFS_BRIDGE_PORT_SUBDIR ); - br->ifobj.ktype =NULL ; - br->ifobj.kset =NULL ; - br->ifobj.parent = brobj; - - err =kobject_register (&br->ifobj); -if (err) { + br->ifobj =kobject_create_and_add (SYSFS_BRIDGE_PORT_SUBDIR , brobj); +if (!br->ifobj) {pr_info ("%s: can't add kobject (directory) %s/%s\n" , - __FUNCTION__, dev->name,kobject_name (&br->ifobj)); + __FUNCTION__, dev->name,SYSFS_BRIDGE_PORT_SUBDIR ); goto out3; }return 0 ;@@ -453,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)struct kobject *kobj = &dev->dev.kobj;struct net_bridge *br =netdev_priv (dev); -kobject_unregister (&br->ifobj); +kobject_unregister (br->ifobj);sysfs_remove_bin_file (kobj, &bridge_forward);sysfs_remove_group (kobj, &bridge_group); }net/bridge/br_sysfs_if.c +0
-0
net/bridge/br_sysfs_if.c int br_sysfs_addif(struct net_bridge_port *p) · line 235
Quoted 8 lines
net/bridge/br_sysfs_if.c +1
-1@@ -229,7 +229,7 @@ int br_sysfs_addif(struct net_bridge_port *p) goto out2; } - err=sysfs_create_link (&br->ifobj, &p->kobj, p->dev->name); + err =sysfs_create_link (br->ifobj, &p->kobj, p->dev->name); out2:return err; }
Okay, but where is the new kobject freed?
Signature · 1 line
Stephen Hemminger <[email protected]>
Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add
Quoted 84 lines · Stephen Hemminger
Quoted 81 lines · On Thu, 24 Jan 2008 23:32:17 -0800 Greg Kroah-Hartman <[email protected]> wrote:
The kobject in the bridge code is only used for registering with sysfs, not for any lifespan rules. This patch changes it to be only a pointer and use the simpler api for this kind of thing.
Cc Stephen Hemminger <[email protected]>Cc Kay Sievers <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/bridge/br_if.c | 2 +- net/bridge/br_private.h | 2 +- net/bridge/br_sysfs_br.c | 14 ++++---------- net/bridge/br_sysfs_if.c | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-)net/bridge/br_if.c +1
-1@@ -133,7 +133,7 @@ static void del_nbp(struct net_bridge_port *p)struct net_bridge *br = p->br;struct net_device *dev = p->dev; -sysfs_remove_link (&br->ifobj, dev->name); +sysfs_remove_link (br->ifobj, dev->name);dev_set_promiscuity (dev,-1 );net/bridge/br_private.h +1
-1@@ -124,7 +124,7 @@ struct net_bridgestruct timer_list tcn_timer;struct timer_list topology_change_timer;struct timer_list gc_timer; -struct kobject ifobj; +struct kobject *ifobj; };extern struct notifier_block br_device_notifier;net/bridge/br_sysfs_br.c +4
-10@@ -426,16 +426,10 @@ int br_sysfs_addbr(struct net_device *dev) goto out2; } - -kobject_set_name (&br->ifobj,SYSFS_BRIDGE_PORT_SUBDIR ); - br->ifobj.ktype =NULL ; - br->ifobj.kset =NULL ; - br->ifobj.parent = brobj; - - err =kobject_register (&br->ifobj); -if (err) { + br->ifobj =kobject_create_and_add (SYSFS_BRIDGE_PORT_SUBDIR , brobj); +if (!br->ifobj) {pr_info ("%s: can't add kobject (directory) %s/%s\n" , - __FUNCTION__, dev->name,kobject_name (&br->ifobj)); + __FUNCTION__, dev->name,SYSFS_BRIDGE_PORT_SUBDIR ); goto out3; }return 0 ;@@ -453,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)struct kobject *kobj = &dev->dev.kobj;struct net_bridge *br =netdev_priv (dev); -kobject_unregister (&br->ifobj); +kobject_unregister (br->ifobj);sysfs_remove_bin_file (kobj, &bridge_forward);sysfs_remove_group (kobj, &bridge_group); }net/bridge/br_sysfs_if.c +0
-0@@ -229,7 +229,7 @@ int br_sysfs_addif(struct net_bridge_port *p) goto out2; }
Quoted 7 lines
net/bridge/br_sysfs_if.c int br_sysfs_addif(struct net_bridge_port *p) · line 235
Quoted 5 lines
net/bridge/br_sysfs_if.c +1
-1- err=sysfs_create_link (&br->ifobj, &p->kobj, p->dev->name); + err =sysfs_create_link (br->ifobj, &p->kobj, p->dev->name); out2:return err; }Okay, but where is the new kobject freed?
In the call to kobject_unregister(), which has then later in the series been converted to a call to kobject_put().
thanks,
greg k-h
Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add
Quoted 6 lines · Greg KH
Quoted 2 lines
Okay, but where is the new kobject freed?
In the call to
kobject_unregister(), which has then later in the series been converted to a call tokobject_put().
Hm, working on LDD 3.1? :-)
Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add
Quoted 9 lines · Jan Engelhardt
Quoted 6 lines · Greg KH
Quoted 2 lines
Okay, but where is the new kobject freed?
In the call to
kobject_unregister(), which has then later in the series been converted to a call tokobject_put().Hm, working on LDD 3.1? :-)
No, unfortunatly :(
Actually, the documentation that was written in this patch series, would be good to replace the existing kobject documentation in LDD 3. But it's a bit hard to just replace a chapter at a time in a book that is already published, we really don't have the mechanism in place for such a thing...
thanks,
greg k-h
PATCH 109/196 Kobject: change GFS2 to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- fs/dlm/lockspace.c | 26 ++++---------------------- fs/gfs2/locking/dlm/sysfs.c | 13 +++---------- fs/gfs2/sys.c | 10 +++------- 3 files changed, 10 insertions(+), 39 deletions(-)
fs/dlm/lockspace.c +4 -22
@@ -168,23 +168,6 @@ static struct kobj_type dlm_ktype = {static struct kset *dlm_kset; -static int kobject_setup (struct dlm_ls *ls) -{ -char lsname[DLM_LOCKSPACE_LEN ]; -int error; - -memset (lsname,0 ,DLM_LOCKSPACE_LEN ); -snprintf (lsname,DLM_LOCKSPACE_LEN ,"%s" , ls->ls_name); - - error =kobject_set_name (&ls->ls_kobj,"%s" , lsname); -if (error) -return error; - - ls->ls_kobj.kset = dlm_kset; - ls->ls_kobj.ktype = &dlm_ktype; -return 0 ; -} -static int do_uevent (struct dlm_ls *ls,int in) {int error;
@@ -545,13 +528,12 @@ static int new_lockspace(char *name, int namelen, void **lockspace, goto out_delist; } - error =kobject_setup (ls); -if (error) - goto out_stop; - - error =kobject_register (&ls->ls_kobj); + ls->ls_kobj.kset = dlm_kset; + error =kobject_init_and_add (&ls->ls_kobj, &dlm_ktype,NULL , +"%s" , ls->ls_name);if (error) goto out_stop; +kobject_uevent (&ls->ls_kobj,KOBJ_ADD );/* let kobject handle freeing of ls if there's an error */ do_unreg =1 ;
fs/gfs2/locking/dlm/sysfs.c +3 -10
@@ -195,19 +195,12 @@ int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj) {int error; - error =kobject_set_name (&ls->kobj,"%s" ,"lock_module" ); -if (error) { -log_error ("can't set kobj name %d" , error); -return error; - } - ls->kobj.kset = gdlm_kset; - ls->kobj.ktype = &gdlm_ktype; - ls->kobj.parent = fskobj; - - error =kobject_register (&ls->kobj); + error =kobject_init_and_add (&ls->kobj, &gdlm_ktype, fskobj, +"lock_module" );if (error)log_error ("can't register kobj %d" , error); +kobject_uevent (&ls->kobj,KOBJ_ADD );return error; }
fs/gfs2/sys.c +3 -7
@@ -494,13 +494,8 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)int error; sdp->sd_kobj.kset = gfs2_kset; - sdp->sd_kobj.ktype = &gfs2_ktype; - - error =kobject_set_name (&sdp->sd_kobj,"%s" , sdp->sd_table_name); -if (error) - goto fail; - - error =kobject_register (&sdp->sd_kobj); + error =kobject_init_and_add (&sdp->sd_kobj, &gfs2_ktype,NULL , +"%s" , sdp->sd_table_name);if (error) goto fail;
@@ -520,6 +515,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)if (error) goto fail_args; +kobject_uevent (&sdp->sd_kobj,KOBJ_ADD );return 0 ; fail_args:
Signature · 1 line
1.5.3.8
PATCH 110/196 Kobject: change drivers/infiniband to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/infiniband/core/sysfs.c | 35 +++++++++-------------------------- include/rdma/ib_verbs.h | 2 +- 2 files changed, 10 insertions(+), 27 deletions(-)
drivers/infiniband/core/sysfs.c +9 -26
@@ -508,19 +508,10 @@ static int add_port(struct ib_device *device, int port_num) p->ibdev = device; p->port_num = port_num; - p->kobj.ktype = &port_type; - p->kobj.parent =kobject_get (&device->ports_parent); -if (!p->kobj.parent) { - ret = -EBUSY ; - goto err; - } - - ret =kobject_set_name (&p->kobj,"%d" , port_num); -if (ret) - goto err_put; - - ret =kobject_register (&p->kobj); + ret =kobject_init_and_add (&p->kobj, &port_type, +kobject_get (device->ports_parent), +"%d" , port_num);if (ret) goto err_put;
@@ -549,6 +540,7 @@ static int add_port(struct ib_device *device, int port_num)list_add_tail (&p->kobj.entry, &device->port_list); +kobject_uevent (&p->kobj,KOBJ_ADD );return 0 ; err_free_pkey:
@@ -570,9 +562,7 @@ err_remove_pma:sysfs_remove_group (&p->kobj, &pma_group); err_put: -kobject_put (&device->ports_parent); - -err: +kobject_put (device->ports_parent);kfree (p);return ret; }
@@ -694,16 +684,9 @@ int ib_device_register_sysfs(struct ib_device *device) goto err_unregister; } - device->ports_parent.parent =kobject_get (&class_dev->kobj); -if (!device->ports_parent.parent) { - ret = -EBUSY ; - goto err_unregister; - } - ret =kobject_set_name (&device->ports_parent,"ports" ); -if (ret) - goto err_put; - ret =kobject_register (&device->ports_parent); -if (ret) + device->ports_parent =kobject_create_and_add ("ports" , +kobject_get (&class_dev->kobj)); +if (!device->ports_parent) goto err_put;if (device->node_type ==RDMA_NODE_IB_SWITCH ) {
@@ -758,7 +741,7 @@ void ib_device_unregister_sysfs(struct ib_device *device)kobject_unregister (p); } -kobject_unregister (&device->ports_parent); +kobject_unregister (device->ports_parent);class_device_unregister (&device->class_dev); }
include/rdma/ib_verbs.h +1 -1
@@ -1026,7 +1026,7 @@ struct ib_device {struct module *owner;struct class_device class_dev; -struct kobject ports_parent; +struct kobject *ports_parent;struct list_head port_list;enum {
Signature · 1 line
1.5.3.8
PATCH 111/196 Kobject: change drivers/firmware/edd.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/firmware/edd.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/firmware/edd.c +5 -5
@@ -721,13 +721,13 @@ edd_device_register(struct edd_device *edev, int i)if (!edev)return 1 ;edd_dev_set_info (edev, i); -kobject_set_name (&edev->kobj,"int13_dev%02x" , -0x80 + i); edev->kobj.kset = edd_kset; - edev->kobj.ktype = &edd_ktype; - error =kobject_register (&edev->kobj); -if (!error) + error =kobject_init_and_add (&edev->kobj, &edd_ktype,NULL , +"int13_dev%02x" ,0x80 + i); +if (!error) {edd_populate_dir (edev); +kobject_uevent (&edev->kobj,KOBJ_ADD ); + }return error; }
Signature · 1 line
1.5.3.8
PATCH 112/196 Kobject: change drivers/firmware/efivars.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/firmware/efivars.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/firmware/efivars.c +3 -3
@@ -617,16 +617,16 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, *(short_name +strlen (short_name)) ='-' ;efi_guid_unparse (vendor_guid, short_name +strlen (short_name)); -kobject_set_name (&new_efivar->kobj,"%s" , short_name); new_efivar->kobj.kset = vars_kset; - new_efivar->kobj.ktype = &efivar_ktype; - i =kobject_register (&new_efivar->kobj); + i =kobject_init_and_add (&new_efivar->kobj, &efivar_ktype,NULL , +"%s" , short_name);if (i) {kfree (short_name);kfree (new_efivar);return 1 ; } +kobject_uevent (&new_efivar->kobj,KOBJ_ADD );kfree (short_name); short_name =NULL ;
Signature · 1 line
1.5.3.8
PATCH 113/196 Kobject: change drivers/cpufreq/cpufreq.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/cpufreq/cpufreq.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
drivers/cpufreq/cpufreq.c +3 -5
@@ -828,11 +828,8 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)memcpy (&new_policy, policy,sizeof (struct cpufreq_policy ));/* prepare interface data */ - policy->kobj.parent = &sys_dev->kobj; - policy->kobj.ktype = &ktype_cpufreq; -kobject_set_name (&policy->kobj,"cpufreq" ); - - ret =kobject_register (&policy->kobj); + ret =kobject_init_and_add (&policy->kobj, &ktype_cpufreq, &sys_dev->kobj, +"cpufreq" );if (ret) {unlock_policy_rwsem_write (cpu); goto err_out_driver_exit;
@@ -902,6 +899,7 @@ static int cpufreq_add_dev (struct sys_device * sys_dev) goto err_out_unregister; } +kobject_uevent (&policy->kobj,KOBJ_ADD );module_put (cpufreq_driver->owner);dprintk ("initialization complete\n" );cpufreq_debug_enable_ratelimit ();
Signature · 1 line
1.5.3.8
PATCH 114/196 Kobject: change drivers/edac to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/edac/edac_device_sysfs.c | 39 +++++++++++-------------------------- drivers/edac/edac_mc_sysfs.c | 28 ++++++++------------------ drivers/edac/edac_pci_sysfs.c | 29 +++++++-------------------- 3 files changed, 29 insertions(+), 67 deletions(-)
drivers/edac/edac_device_sysfs.c +12 -27
@@ -246,16 +246,6 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)/* Init the devices's kobject */ memset (&edac_dev->kobj,0 ,sizeof (struct kobject )); - edac_dev->kobj.ktype = &ktype_device_ctrl; - -/* set this new device under the edac_class kobject */ - edac_dev->kobj.parent = &edac_class->kset.kobj; - -/* generate sysfs "..../edac/<name>" */ -debugf4 ("%s() set name of kobject to: %s\n" , __func__, edac_dev->name); - err =kobject_set_name (&edac_dev->kobj,"%s" , edac_dev->name); -if (err) - goto err_out;/* Record which module 'owns' this control structure * and bump the ref count of the module
@@ -268,12 +258,15 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) }/* register */ - err =kobject_register (&edac_dev->kobj); + err =kobject_init_and_add (&edac_dev->kobj, &ktype_device_ctrl, + &edac_class->kset.kobj, +"%s" , edac_dev->name);if (err) {debugf1 ("%s()Failed to register '.../edac/%s'\n" , __func__, edac_dev->name); goto err_kobj_reg; } +kobject_uevent (&edac_dev->kobj,KOBJ_ADD );/* At this point, to 'free' the control struct, * edac_device_unregister_sysfs_main_kobj() must be used
@@ -533,12 +526,6 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,/* init this block's kobject */ memset (&block->kobj,0 ,sizeof (struct kobject )); - block->kobj.parent = &instance->kobj; - block->kobj.ktype = &ktype_block_ctrl; - - err =kobject_set_name (&block->kobj,"%s" , block->name); -if (err) -return err;/* bump the main kobject's reference count for this controller * and this instance is dependant on the main
@@ -550,7 +537,9 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, }/* Add this block's kobject */ - err =kobject_register (&block->kobj); + err =kobject_init_and_add (&block->kobj, &ktype_block_ctrl, + &instance->kobj, +"%s" , block->name);if (err) {debugf1 ("%s() Failed to register instance '%s'\n" , __func__, block->name);
@@ -579,6 +568,7 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, goto err_on_attrib; } } +kobject_uevent (&block->kobj,KOBJ_ADD );return 0 ;
@@ -637,15 +627,8 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,/* Init the instance's kobject */ memset (&instance->kobj,0 ,sizeof (struct kobject )); -/* set this new device under the edac_device main kobject */ - instance->kobj.parent = &edac_dev->kobj; - instance->kobj.ktype = &ktype_instance_ctrl; instance->ctl = edac_dev; - err =kobject_set_name (&instance->kobj,"%s" , instance->name); -if (err) - goto err_out; -/* bump the main kobject's reference count for this controller * and this instance is dependant on the main */
@@ -655,8 +638,9 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, goto err_out; } -/* Formally register this instance's kobject */ - err =kobject_register (&instance->kobj); +/* Formally register this instance's kobject under the edac_device */ + err =kobject_init_and_add (&instance->kobj, &ktype_instance_ctrl, + &edac_dev->kobj,"%s" , instance->name);if (err !=0 ) {debugf2 ("%s() Failed to register instance '%s'\n" , __func__, instance->name);
@@ -679,6 +663,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, goto err_release_instance_kobj; } } +kobject_uevent (&instance->kobj,KOBJ_ADD );debugf4 ("%s() Registered instance %d '%s' kobject\n" , __func__, idx, instance->name);
drivers/edac/edac_mc_sysfs.c +9 -19
@@ -380,13 +380,6 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,/* generate ..../edac/mc/mc<id>/csrow<index> */ memset (&csrow->kobj,0 ,sizeof (csrow->kobj)); csrow->mci = mci;/* include container up link */ - csrow->kobj.parent = kobj_mci; - csrow->kobj.ktype = &ktype_csrow; - -/* name this instance of csrow<id> */ - err =kobject_set_name (&csrow->kobj,"csrow%d" , index); -if (err) - goto err_out;/* bump the mci instance's kobject's ref count */ kobj =kobject_get (&mci->edac_mci_kobj);
@@ -396,7 +389,8 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci, }/* Instanstiate the csrow object */ - err =kobject_register (&csrow->kobj); + err =kobject_init_and_add (&csrow->kobj, &ktype_csrow, kobj_mci, +"csrow%d" , index);if (err) goto err_release_top_kobj;
@@ -416,7 +410,7 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci, goto err_out; } } - +kobject_uevent (&csrow->kobj,KOBJ_ADD );return 0 ;/* error unwind stack */
@@ -764,15 +758,6 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)/* Init the mci's kobject */ memset (kobj_mci,0 ,sizeof (*kobj_mci)); -/* this instance become part of the mc_kset */ - kobj_mci->kset = &mc_kset; - kobj_mci->ktype = &ktype_mci; - -/* set the name of the mc<id> object */ - err =kobject_set_name (kobj_mci,"mc%d" , mci->mc_idx); -if (err) - goto fail_out; -/* Record which module 'owns' this control structure * and bump the ref count of the module */
@@ -784,13 +769,18 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci) goto fail_out; } +/* this instance become part of the mc_kset */ + kobj_mci->kset = &mc_kset; +/* register the mc<id> kobject to the mc_kset */ - err =kobject_register (kobj_mci); + err =kobject_init_and_add (kobj_mci, &ktype_mci,NULL , +"mc%d" , mci->mc_idx);if (err) {debugf1 ("%s()Failed to register '.../edac/mc%d'\n" , __func__, mci->mc_idx); goto kobj_reg_fail; } +kobject_uevent (kobj_mci,KOBJ_ADD );/* At this point, to 'free' the control struct, * edac_mc_unregister_sysfs_main_kobj() must be used
drivers/edac/edac_pci_sysfs.c +8 -21
@@ -162,14 +162,6 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)debugf0 ("%s()\n" , __func__); -/* Set the parent and the instance's ktype */ - pci->kobj.parent = &edac_pci_top_main_kobj; - pci->kobj.ktype = &ktype_pci_instance; - - err =kobject_set_name (&pci->kobj,"pci%d" , idx); -if (err) -return err; -/* First bump the ref count on the top main kobj, which will * track the number of PCI instances we have, and thus nest * properly on keeping the module loaded
@@ -181,7 +173,8 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx) }/* And now register this new kobject under the main kobj */ - err =kobject_register (&pci->kobj); + err =kobject_init_and_add (&pci->kobj, &ktype_pci_instance, + &edac_pci_top_main_kobj,"pci%d" , idx);if (err !=0 ) {debugf2 ("%s() failed to register instance pci%d\n" , __func__, idx);
@@ -189,6 +182,7 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx) goto error_out; } +kobject_uevent (&pci->kobj,KOBJ_ADD );debugf1 ("%s() Register instance 'pci%d' kobject\n" , __func__, idx);return 0 ;
@@ -364,14 +358,6 @@ int edac_pci_main_kobj_setup(void) goto decrement_count_fail; } -/* Need the kobject hook ups, and name setting */ - edac_pci_top_main_kobj.ktype = &ktype_edac_pci_main_kobj; - edac_pci_top_main_kobj.parent = &edac_class->kset.kobj; - - err =kobject_set_name (&edac_pci_top_main_kobj,"pci" ); -if (err) - goto decrement_count_fail; -/* Bump the reference count on this module to ensure the * modules isn't unloaded until we deconstruct the top * level main kobj for EDAC PCI
@@ -383,23 +369,24 @@ int edac_pci_main_kobj_setup(void) }/* Instanstiate the pci object */ -/* FIXME: maybe new sysdev_create_subdir() */ - err =kobject_register (&edac_pci_top_main_kobj); + err =kobject_init_and_add (&edac_pci_top_main_kobj, &ktype_edac_pci_main_kobj, + &edac_class->kset.kobj,"pci" );if (err) {debugf1 ("Failed to register '.../edac/pci'\n" ); - goto kobject_register_fail; + goto kobject_init_and_add_fail; }/* At this point, to 'release' the top level kobject * for EDAC PCI, then edac_pci_main_kobj_teardown() * must be used, for resources to be cleaned up properly */ +kobject_uevent (&edac_pci_top_main_kobj,KOBJ_ADD );debugf1 ("Registered '.../edac/pci' kobject\n" );return 0 ;/* Error unwind statck */ -kobject_register_fail: +kobject_init_and_add_fail:module_put (THIS_MODULE ); decrement_count_fail:
Signature · 1 line
1.5.3.8
PATCH 115/196 Kobject: change drivers/cpuidle/sysfs.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/cpuidle/sysfs.c | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-)
drivers/cpuidle/sysfs.c +9 -8
@@ -300,14 +300,13 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device) kobj->state = &device->states[i];init_completion (&kobj->kobj_unregister); - kobj->kobj.parent = &device->kobj; - kobj->kobj.ktype = &ktype_state_cpuidle; -kobject_set_name (&kobj->kobj,"state%d" , i); - ret =kobject_register (&kobj->kobj); + ret =kobject_init_and_add (&kobj->kobj, &ktype_state_cpuidle, &device->kobj, +"state%d" , i);if (ret) {kfree (kobj); goto error_state; } +kobject_uevent (&kobj->kobj,KOBJ_ADD ); device->kobjs[i] = kobj; }
@@ -339,12 +338,14 @@ int cpuidle_add_sysfs(struct sys_device *sysdev) {int cpu = sysdev->id;struct cpuidle_device *dev; +int error; dev =per_cpu (cpuidle_devices, cpu); - dev->kobj.parent = &sysdev->kobj; - dev->kobj.ktype = &ktype_cpuidle; -kobject_set_name (&dev->kobj,"%s" ,"cpuidle" ); -return kobject_register (&dev->kobj); + error =kobject_init_and_add (&dev->kobj, &ktype_cpuidle, &sysdev->kobj, +"cpuidle" ); +if (!error) +kobject_uevent (&dev->kobj,KOBJ_ADD ); +return error; }/**
Signature · 1 line
1.5.3.8
PATCH 116/196 Kobject: change drivers/pci/hotplug/pci_hotplug_core.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/pci/hotplug/pci_hotplug_core.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/pci/hotplug/pci_hotplug_core.c +7 -7
@@ -630,19 +630,19 @@ int pci_hp_register (struct hotplug_slot *slot)return -EINVAL ; } -kobject_set_name (&slot->kobj,"%s" , slot->name); - slot->kobj.kset = pci_hotplug_slots_kset; - slot->kobj.ktype = &hotplug_slot_ktype; -/* this can fail if we have already registered a slot with the same name */ -if (kobject_register (&slot->kobj)) { -err ("Unable to register kobject" ); + slot->kobj.kset = pci_hotplug_slots_kset; + result =kobject_init_and_add (&slot->kobj, &hotplug_slot_ktype,NULL , +"%s" , slot->name); +if (result) { +err ("Unable to register kobject '%s'" , slot->name);return -EINVAL ; } - +list_add (&slot->slot_list, &pci_hotplug_slot_list); result =fs_add_slot (slot); +kobject_uevent (&slot->kobj,KOBJ_ADD );dbg ("Added slot %s to the list\n" , slot->name);return result; }
Signature · 1 line
1.5.3.8
PATCH 117/196 Kobject: change drivers/base/sys.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/base/sys.c | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-)
drivers/base/sys.c +6 -10
@@ -224,20 +224,15 @@ int sysdev_register(struct sys_device * sysdev)if (!cls)return -EINVAL ; +pr_debug ("Registering sys device '%s'\n" ,kobject_name (&sysdev->kobj)); +/* Make sure the kset is set */ sysdev->kobj.kset = &cls->kset; -/* But make sure we point to the right type for sysfs translation */ - sysdev->kobj.ktype = &ktype_sysdev; - error =kobject_set_name (&sysdev->kobj,"%s%d" , -kobject_name (&cls->kset.kobj), sysdev->id); -if (error) -return error; - -pr_debug ("Registering sys device '%s'\n" ,kobject_name (&sysdev->kobj)); -/* Register the object */ - error =kobject_register (&sysdev->kobj); + error =kobject_init_and_add (&sysdev->kobj, &ktype_sysdev,NULL , +"%s%d" ,kobject_name (&cls->kset.kobj), + sysdev->id);if (!error) {struct sysdev_driver * drv;
@@ -254,6 +249,7 @@ int sysdev_register(struct sys_device * sysdev) }mutex_unlock (&sysdev_drivers_lock); } +kobject_uevent (&sysdev->kobj,KOBJ_ADD );return error; }
Signature · 1 line
1.5.3.8
PATCH 118/196 Kobject: change arch/x86/kernel/cpu/intel_cacheinfo.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- arch/x86/kernel/cpu/intel_cacheinfo.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +7 -8
@@ -733,10 +733,8 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)if (unlikely (retval <0 ))return retval; - cache_kobject[cpu]->parent = &sys_dev->kobj; -kobject_set_name (cache_kobject[cpu],"%s" ,"cache" ); - cache_kobject[cpu]->ktype = &ktype_percpu_entry; - retval =kobject_register (cache_kobject[cpu]); + retval =kobject_init_and_add (cache_kobject[cpu], &ktype_percpu_entry, + &sys_dev->kobj,"%s" ,"cache" );if (retval <0 ) {cpuid4_cache_sysfs_exit (cpu);return retval;
@@ -746,10 +744,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) this_object =INDEX_KOBJECT_PTR (cpu,i); this_object->cpu = cpu; this_object->index = i; - this_object->kobj.parent = cache_kobject[cpu]; -kobject_set_name (&(this_object->kobj),"index%1lu" , i); - this_object->kobj.ktype = &ktype_cache; - retval =kobject_register (&(this_object->kobj)); + retval =kobject_init_and_add (&(this_object->kobj), + &ktype_cache, cache_kobject[cpu], +"index%1lu" , i);if (unlikely (retval)) {for (j =0 ; j < i; j++) { kobject_unregister(
@@ -759,10 +756,12 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)cpuid4_cache_sysfs_exit (cpu);break ; } +kobject_uevent (&(this_object->kobj),KOBJ_ADD ); }if (!retval)cpu_set (cpu, cache_dev_map); +kobject_uevent (cache_kobject[cpu],KOBJ_ADD );return retval; }
Signature · 1 line
1.5.3.8
PATCH 119/196 Kobject: change drivers/acpi/system.c to use kobject_create_and_add
In reply to Greg KHStop using kobject_register for this static kobject, as it's overkill. This way is much simpler.
--- drivers/acpi/system.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)
drivers/acpi/system.c +6 -7
@@ -58,7 +58,7 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);FS Interface (/sys) -------------------------------------------------------------------------- */ static LIST_HEAD (acpi_table_attr_list); -static struct kobject tables_kobj; +static struct kobject *tables_kobj;struct acpi_table_attr {struct bin_attribute attr;
@@ -135,11 +135,9 @@ static int acpi_system_sysfs_init(void)int table_index =0 ;int result; - tables_kobj.parent = acpi_kobj; -kobject_set_name (&tables_kobj,"tables" ); - result =kobject_register (&tables_kobj); -if (result) -return result; + tables_kobj =kobject_create_and_add ("tables" , acpi_kobj); +if (!tables_kobj) +return -ENOMEM ; do { result = acpi_get_table_by_index(table_index, &table_header);
@@ -153,7 +151,7 @@ static int acpi_system_sysfs_init(void)acpi_table_attr_init (table_attr, table_header); result = -sysfs_create_bin_file (&tables_kobj, +sysfs_create_bin_file (tables_kobj, &table_attr->attr);if (result) {kfree (table_attr);
@@ -163,6 +161,7 @@ static int acpi_system_sysfs_init(void) &acpi_table_attr_list); } }while (!result); +kobject_uevent (tables_kobj,KOBJ_ADD );return 0 ; }
Signature · 1 line
1.5.3.8
PATCH 120/196 Kobject: change drivers/block/pktcdvd.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/block/pktcdvd.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
drivers/block/pktcdvd.c +5 -4
@@ -110,17 +110,18 @@ static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd, struct kobj_type* ktype) {struct pktcdvd_kobj *p; +int error; + p =kzalloc (sizeof (*p),GFP_KERNEL );if (!p)return NULL ; -kobject_set_name (&p->kobj,"%s" , name); - p->kobj.parent = parent; - p->kobj.ktype = ktype; p->pd = pd; -if (kobject_register (&p->kobj) !=0 ) { + error =kobject_init_and_add (&p->kobj, ktype, parent,"%s" , name); +if (error) {kobject_put (&p->kobj);return NULL ; } +kobject_uevent (&p->kobj,KOBJ_ADD );return p; }/*
Signature · 1 line
1.5.3.8
PATCH 121/196 Kobject: change arch/sh/kernel/cpu/sh4/sq.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- arch/sh/kernel/cpu/sh4/sq.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
arch/sh/kernel/cpu/sh4/sq.c +6 -5
@@ -341,17 +341,18 @@ static int __devinit sq_sysdev_add(struct sys_device *sysdev) {unsigned int cpu = sysdev->id;struct kobject *kobj; +int error; sq_kobject[cpu] =kzalloc (sizeof (struct kobject ),GFP_KERNEL );if (unlikely (!sq_kobject[cpu]))return -ENOMEM ; kobj = sq_kobject[cpu]; - kobj->parent = &sysdev->kobj; -kobject_set_name (kobj,"%s" ,"sq" ); - kobj->ktype = &ktype_percpu_entry; - -return kobject_register (kobj); + error =kobject_init_and_add (kobj, &ktype_percpu_entry, &sysdev->kobj, +"%s" ,"sq" ); +if (!error) +kobject_uevent (kobj,KOBJ_ADD ); +return error; } static int __devexit sq_sysdev_remove(struct sys_device *sysdev)
Signature · 1 line
1.5.3.8
PATCH 122/196 Kobject: change drivers/net/ibmveth.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/net/ibmveth.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/net/ibmveth.c +6 -4
@@ -1179,13 +1179,15 @@ static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_for (i =0 ; i<IbmVethNumBufferPools; i++) {struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; +int error; +ibmveth_init_buffer_pool (&adapter->rx_buff_pool[i], i, pool_count[i], pool_size[i], pool_active[i]); - kobj->parent = &dev->dev.kobj; -kobject_set_name (kobj,"pool%d" , i); - kobj->ktype = &ktype_veth_pool; -kobject_register (kobj); + error =kobject_init_and_add (kobj, &ktype_veth_pool, + &dev->dev.kobj,"pool%d" , i); +if (!error) +kobject_uevent (kobj,KOBJ_ADD ); }ibmveth_debug_printk ("adapter @ 0x%p\n" , adapter);
Signature · 1 line
1.5.3.8
PATCH 123/196 Kobject: change drivers/parisc/pdc_stable.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/parisc/pdc_stable.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/parisc/pdc_stable.c +5 -5
@@ -991,13 +991,12 @@ pdcs_register_pathentries(void)if (err <0 )continue ; -if ((err =kobject_set_name (&entry->kobj,"%s" , entry->name))) -return err; entry->kobj.kset = paths_kset; - entry->kobj.ktype = &ktype_pdcspath; -if ((err =kobject_register (&entry->kobj))) + err =kobject_init_and_add (&entry->kobj, &ktype_pdcspath,NULL , +"%s" , entry->name); +if (err)return err; - +/* kobject is now registered */ write_lock (&entry->rw_lock); entry->ready =2 ;
@@ -1009,6 +1008,7 @@ pdcs_register_pathentries(void) }write_unlock (&entry->rw_lock); +kobject_uevent (&entry->kobj,KOBJ_ADD ); }return 0 ;
Signature · 1 line
1.5.3.8
PATCH 124/196 Kobject: change arch/ia64/kernel/topology.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- arch/ia64/kernel/topology.c | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-)
arch/ia64/kernel/topology.c +9 -8
@@ -354,17 +354,16 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)if (unlikely (retval <0 ))return retval; - all_cpu_cache_info[cpu].kobj.parent = &sys_dev->kobj; -kobject_set_name (&all_cpu_cache_info[cpu].kobj,"%s" ,"cache" ); - all_cpu_cache_info[cpu].kobj.ktype = &cache_ktype_percpu_entry; - retval =kobject_register (&all_cpu_cache_info[cpu].kobj); + retval =kobject_init_and_add (&all_cpu_cache_info[cpu].kobj, + &cache_ktype_percpu_entry, &sys_dev->kobj, +"%s" ,"cache" );for (i =0 ; i < all_cpu_cache_info[cpu].num_cache_leaves; i++) { this_object =LEAF_KOBJECT_PTR (cpu,i); - this_object->kobj.parent = &all_cpu_cache_info[cpu].kobj; -kobject_set_name (&(this_object->kobj),"index%1lu" , i); - this_object->kobj.ktype = &cache_ktype; - retval =kobject_register (&(this_object->kobj)); + retval =kobject_init_and_add (&(this_object->kobj), + &cache_ktype, + &all_cpu_cache_info[cpu].kobj, +"index%1lu" , i);if (unlikely (retval)) {for (j =0 ; j < i; j++) { kobject_unregister(
@@ -374,7 +373,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)cpu_cache_sysfs_exit (cpu);break ; } +kobject_uevent (&(this_object->kobj),KOBJ_ADD ); } +kobject_uevent (&all_cpu_cache_info[cpu].kobj,KOBJ_ADD );return retval; }
Signature · 1 line
1.5.3.8
PATCH 125/196 Kobject: change drivers/md/md.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/md/md.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/md/md.c +6 -4
@@ -3054,6 +3054,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)int partitioned = (MAJOR (dev) !=MD_MAJOR );int shift = partitioned ? MdpMinorShift :0 ;int unit =MINOR (dev) >> shift; +int error;if (!mddev)return NULL ;
@@ -3082,12 +3083,13 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)add_disk (disk); mddev->gendisk = disk;mutex_unlock (&disks_mutex); - mddev->kobj.parent = &disk->kobj; -kobject_set_name (&mddev->kobj,"%s" ,"md" ); - mddev->kobj.ktype = &md_ktype; -if (kobject_register (&mddev->kobj)) + error =kobject_init_and_add (&mddev->kobj, &md_ktype, &disk->kobj, +"%s" ,"md" ); +if (error)printk (KERN_WARNING "md: cannot register %s/md - name in use\n" , disk->disk_name); +else +kobject_uevent (&mddev->kobj,KOBJ_ADD );return NULL ; }
Signature · 1 line
1.5.3.8
PATCH 126/196 Kobject: change arch/x86/kernel/cpu/mcheck/mce_amd_64.c to use kobject_create_and_add
In reply to Greg KHMake this kobject dynamic and convert it to not use kobject_register, which is going away.
--- arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/mcheck/mce_amd_64.c +9 -10
@@ -65,7 +65,7 @@ static struct threshold_block threshold_defaults = { };struct threshold_bank { -struct kobject kobj; +struct kobject *kobj;struct threshold_block *blocks;cpumask_t cpus; };
@@ -433,7 +433,7 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,per_cpu (threshold_banks, cpu)[bank]->blocks = b;kobject_set_name (&b->kobj,"misc%i" , block); - b->kobj.parent = &per_cpu (threshold_banks, cpu)[bank]->kobj; + b->kobj.parent =per_cpu (threshold_banks, cpu)[bank]->kobj; b->kobj.ktype = &threshold_ktype; err =kobject_register (&b->kobj);if (err)
@@ -489,7 +489,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) goto out; err =sysfs_create_link (&per_cpu (device_mce, cpu).kobj, - &b->kobj, name); + b->kobj, name);if (err) goto out;
@@ -505,16 +505,15 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) goto out; } -kobject_set_name (&b->kobj,"threshold_bank%i" , bank); - b->kobj.parent = &per_cpu (device_mce, cpu).kobj; + b->kobj =kobject_create_and_add (name, &per_cpu (device_mce, cpu).kobj); +if (!b->kobj) + goto out_free; +#ifndef CONFIG_SMP b->cpus =CPU_MASK_ALL ;#else b->cpus =per_cpu (cpu_core_map, cpu);#endif - err =kobject_register (&b->kobj); -if (err) - goto out_free;per_cpu (threshold_banks, cpu)[bank] = b;
@@ -531,7 +530,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)continue ; err =sysfs_create_link (&per_cpu (device_mce, i).kobj, - &b->kobj, name); + b->kobj, name);if (err) goto out;
@@ -627,7 +626,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)deallocate_threshold_block (cpu, bank); free_out: -kobject_unregister (&b->kobj); +kobject_unregister (b->kobj);kfree (b);per_cpu (threshold_banks, cpu)[bank] =NULL ; }
Signature · 1 line
1.5.3.8
PATCH 127/196 Kobject: change arch/x86/kernel/cpu/mcheck/mce_amd_64.c to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/mcheck/mce_amd_64.c +5 -4
@@ -432,10 +432,9 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,else per_cpu (threshold_banks, cpu)[bank]->blocks = b; -kobject_set_name (&b->kobj,"misc%i" , block); - b->kobj.parent =per_cpu (threshold_banks, cpu)[bank]->kobj; - b->kobj.ktype = &threshold_ktype; - err =kobject_register (&b->kobj); + err =kobject_init_and_add (&b->kobj, &threshold_ktype, +per_cpu (threshold_banks, cpu)[bank]->kobj, +"misc%i" , block);if (err) goto out_free; recurse:
@@ -451,6 +450,8 @@ recurse:if (err) goto out_free; +kobject_uevent (&b->kobj,KOBJ_ADD ); +return err; out_free:
Signature · 1 line
1.5.3.8
PATCH 128/196 Kobject: the cris iop_fw_load.c code is broken
In reply to Greg KHThis code is really really really broken. So much so that it's almost impossible to fix with a simple patch, so just comment out the offending registration with the kobject core, and mark the driver as broken.
The problem is that the code is trying to register a "raw" struct device, which is not allowed. struct device is only for use within the driver model. This is being done to try to use the firmware layer which wants a struct device. To properly fix this, use something easy, like a platform device, which is a struct device and can be used for this kind of thing.
--- arch/cris/arch-v32/drivers/iop_fw_load.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
arch/cris/arch-v32/drivers/iop_fw_load.c +11 -0
@@ -20,6 +20,9 @@#define IOP_TIMEOUT 100 +#error "This driver is broken with regard to its driver core usage." +#error "Please contact <[email protected]> for details on how to fix it properly." +static struct device iop_spu_device[2 ] = { { .bus_id ="iop-spu0" , }, { .bus_id ="iop-spu1" , },
@@ -192,6 +195,13 @@ int iop_start_mpu(unsigned int start_addr)static int __init iop_fw_load_init (void ) { +#if 0 +/* +* static struct devices can not be added directly to sysfs by ignoring +* the driver model infrastructure. To fix this properly, please use +* the platform_bus to register these devices to be able to properly +* use the firmware infrastructure. +*/ device_initialize (&iop_spu_device[0 ]);kobject_set_name (&iop_spu_device[0 ].kobj,"iop-spu0" );kobject_add (&iop_spu_device[0 ].kobj);
@@ -201,6 +211,7 @@ static int __init iop_fw_load_init(void)device_initialize (&iop_mpu_device);kobject_set_name (&iop_mpu_device.kobj,"iop-mpu" );kobject_add (&iop_mpu_device.kobj); +#endif return 0 ; }
Signature · 1 line
1.5.3.8
PATCH 129/196 Kobject: convert drivers/base/class.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- drivers/base/class.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)
drivers/base/class.c +3 -7
@@ -546,8 +546,7 @@ static struct class_device_attribute class_uevent_attr =void class_device_initialize (struct class_device *class_dev) { class_dev->kobj.kset = &class_obj_subsys; - class_dev->kobj.ktype = &class_device_ktype; -kobject_init (&class_dev->kobj); +kobject_init_ng (&class_dev->kobj, &class_device_ktype);INIT_LIST_HEAD (&class_dev->node); }
@@ -575,16 +574,13 @@ int class_device_add(struct class_device *class_dev) class_dev->class_id);/* first, register with generic layer. */ - error =kobject_set_name (&class_dev->kobj,"%s" , class_dev->class_id); -if (error) - goto out2; -if (parent_class_dev) class_dev->kobj.parent = &parent_class_dev->kobj;else class_dev->kobj.parent = &parent_class->subsys.kobj; - error =kobject_add (&class_dev->kobj); + error =kobject_add_ng (&class_dev->kobj, class_dev->kobj.parent, +"%s" , class_dev->class_id);if (error) goto out2;
Signature · 1 line
1.5.3.8
PATCH 130/196 Kobject: convert drivers/base/core.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- drivers/base/core.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
drivers/base/core.c +3 -5
@@ -523,8 +523,7 @@ static void klist_children_put(struct klist_node *n)void device_initialize (struct device *dev) { dev->kobj.kset = devices_kset; - dev->kobj.ktype = &device_ktype; -kobject_init (&dev->kobj); +kobject_init_ng (&dev->kobj, &device_ktype);klist_init (&dev->klist_children, klist_children_get, klist_children_put);INIT_LIST_HEAD (&dev->dma_pools);
@@ -729,7 +728,7 @@ static void device_remove_class_symlinks(struct device *dev)* This is part 2 of device_register(), though may be called * separately _iff_ device_initialize() has been called separately. * -* This adds it to the kobject hierarchy via kobject_add(), adds it +* This adds it to the kobject hierarchy via kobject_add_ng(), adds it * to the global and sibling lists for the device, then * adds it to the other relevant subsystems of the driver model. */
@@ -760,8 +759,7 @@ int device_add(struct device *dev) goto Error;/* first, register with generic layer. */ -kobject_set_name (&dev->kobj,"%s" , dev->bus_id); - error =kobject_add (&dev->kobj); + error =kobject_add_ng (&dev->kobj, dev->kobj.parent,"%s" , dev->bus_id);if (error) goto Error;
Signature · 1 line
1.5.3.8
PATCH 131/196 Kobject: convert drivers/net/iseries_veth.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- drivers/net/iseries_veth.c | 19 ++++++------------- 1 files changed, 6 insertions(+), 13 deletions(-)
drivers/net/iseries_veth.c +6 -13
@@ -815,7 +815,7 @@ static int veth_init_connection(u8 rlp) {struct veth_lpar_connection *cnx;struct veth_msg *msgs; -int i, rc; +int i;if ( (rlp == this_lp) || !HvLpConfig_doLpsCommunicateOnVirtualLan (this_lp, rlp) )
@@ -844,11 +844,7 @@ static int veth_init_connection(u8 rlp)/* This gets us 1 reference, which is held on behalf of the driver * infrastructure. It's released at module unload. */ -kobject_init (&cnx->kobject); - cnx->kobject.ktype = &veth_lpar_connection_ktype; - rc =kobject_set_name (&cnx->kobject,"cnx%.2d" , rlp); -if (rc !=0 ) -return rc; +kobject_init_ng (&cnx->kobject, &veth_lpar_connection_ktype); msgs =kcalloc (VETH_NUMBUFFERS ,sizeof (struct veth_msg ),GFP_KERNEL );if (! msgs) {
@@ -1087,11 +1083,8 @@ static struct net_device * __init veth_probe_one(int vlan,return NULL ; } -kobject_init (&port->kobject); - port->kobject.parent = &dev->dev.kobj; - port->kobject.ktype = &veth_port_ktype; -kobject_set_name (&port->kobject,"veth_port" ); -if (0 !=kobject_add (&port->kobject)) +kobject_init_ng (&port->kobject, &veth_port_ktype); +if (0 !=kobject_add_ng (&port->kobject, &dev->dev.kobj,"veth_port" ))veth_error ("Failed adding port for %s to sysfs.\n" , dev->name); veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n",
@@ -1711,9 +1704,9 @@ static int __init veth_module_init(void)continue ; kobj = &veth_cnx[i]->kobject; - kobj->parent = &veth_driver.driver.kobj;/* If the add failes, complain but otherwise continue */ -if (0 !=kobject_add (kobj)) +if (0 !=kobject_add_ng (kobj, &veth_driver.driver.kobj, +"cnx%.2d" , veth_cnx[i]->remote_lp))veth_error ("cnx %d: Failed adding to sysfs.\n" , i); }
Signature · 1 line
1.5.3.8
PATCH 132/196 Kobject: convert fs/char_dev.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- fs/char_dev.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
fs/char_dev.c +2 -4
@@ -510,9 +510,8 @@ struct cdev *cdev_alloc(void) {struct cdev *p =kzalloc (sizeof (struct cdev ),GFP_KERNEL );if (p) { - p->kobj.ktype = &ktype_cdev_dynamic;INIT_LIST_HEAD (&p->list); -kobject_init (&p->kobj); +kobject_init_ng (&p->kobj, &ktype_cdev_dynamic); }return p; }
@@ -529,8 +528,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops) {memset (cdev,0 ,sizeof *cdev);INIT_LIST_HEAD (&cdev->list); - cdev->kobj.ktype = &ktype_cdev_default; -kobject_init (&cdev->kobj); +kobject_init_ng (&cdev->kobj, &ktype_cdev_default); cdev->ops = fops; }
Signature · 1 line
1.5.3.8
PATCH 133/196 Kobject: convert kernel/params.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- kernel/params.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
kernel/params.c +2 -4
@@ -561,11 +561,9 @@ static void __init kernel_param_sysfs_setup(const char *name, mk->mod =THIS_MODULE ; mk->kobj.kset = module_kset; - mk->kobj.ktype = &module_ktype; -kobject_set_name (&mk->kobj, name); -kobject_init (&mk->kobj); - ret =kobject_add (&mk->kobj); + ret =kobject_init_and_add (&mk->kobj, &module_ktype,NULL ,"%s" , name);if (ret) { +kobject_put (&mk->kobj);printk (KERN_ERR "Module '%s' failed to be added to sysfs, " "error number %d\n" , name, ret);printk (KERN_ERR "The system will be unstable now.\n" );
Signature · 1 line
1.5.3.8
PATCH 134/196 Kobject: convert kernel/user.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- kernel/user.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
kernel/user.c +4 -5
@@ -181,13 +181,12 @@ static int uids_user_create(struct user_struct *up)int error;memset (kobj,0 ,sizeof (struct kobject )); - kobj->ktype = &uids_ktype; kobj->kset = uids_kset; -kobject_init (kobj); -kobject_set_name (&up->kobj,"%d" , up->uid); - error =kobject_add (kobj); -if (error) + error =kobject_init_and_add (kobj, &uids_ktype,NULL ,"%d" , up->uid); +if (error) { +kobject_put (kobj); goto done; + }kobject_uevent (kobj,KOBJ_ADD ); done:
Signature · 1 line
1.5.3.8
PATCH 135/196 Kobject: convert mm/slub.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- mm/slub.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
mm/slub.c +4 -5
@@ -4025,13 +4025,12 @@ static int sysfs_slab_add(struct kmem_cache *s) name =create_unique_id (s); } -kobject_set_name (&s->kobj, name); s->kobj.kset = slab_kset; - s->kobj.ktype = &slab_ktype; -kobject_init (&s->kobj); - err =kobject_add (&s->kobj); -if (err) + err =kobject_init_and_add (&s->kobj, &slab_ktype,NULL , name); +if (err) { +kobject_put (&s->kobj);return err; + } err =sysfs_create_group (&s->kobj, &slab_attr_group);if (err)
Signature · 1 line
1.5.3.8
Re: [PATCH 135/196] Kobject: convert mm/slub.c to use kobject_init/add_ng()
Quoted 2 lines · Greg Kroah-Hartman
This converts the code to use the new kobject functions, cleaning up the logic in doing so.
PATCH 136/196 Kobject: convert net/bridge/br_if.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- net/bridge/br_if.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)
net/bridge/br_if.c +3 -7
@@ -258,12 +258,6 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br, p->state =BR_STATE_DISABLED ;br_stp_port_timer_init (p); -kobject_init (&p->kobj); -kobject_set_name (&p->kobj,SYSFS_BRIDGE_PORT_ATTR ); - p->kobj.ktype = &brport_ktype; - p->kobj.parent = &(dev->dev.kobj); - p->kobj.kset =NULL ; -return p; }
@@ -379,7 +373,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)if (IS_ERR (p))return PTR_ERR (p); - err =kobject_add (&p->kobj); + err =kobject_init_and_add (&p->kobj, &brport_ktype, &(dev->dev.kobj), +SYSFS_BRIDGE_PORT_ATTR );if (err) goto err0;
@@ -416,6 +411,7 @@ err2:br_fdb_delete_by_port (br, p,1 ); err1:kobject_del (&p->kobj); +return err; err0:kobject_put (&p->kobj);return err;
Signature · 1 line
1.5.3.8
Re: [PATCH 136/196] Kobject: convert net/bridge/br_if.c to use kobject_init/add_ng()
Quoted 38 lines · On Thu, 24 Jan 2008 23:32:45 -0800 Greg Kroah-Hartman <[email protected]> wrote:
This converts the code to use the new kobject functions, cleaning up the logic in doing so.
Cc Stephen Hemminger <[email protected]>Cc Kay Sievers <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/bridge/br_if.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)net/bridge/br_if.c +2
-7@@ -258,12 +258,6 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br, p->state =BR_STATE_DISABLED ;br_stp_port_timer_init (p); -kobject_init (&p->kobj); -kobject_set_name (&p->kobj,SYSFS_BRIDGE_PORT_ATTR ); - p->kobj.ktype = &brport_ktype; - p->kobj.parent = &(dev->dev.kobj); - p->kobj.kset =NULL ; -return p; }@@ -379,7 +373,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)if (IS_ERR (p))return PTR_ERR (p); - err =kobject_add (&p->kobj); + err =kobject_init_and_add (&p->kobj, &brport_ktype, &(dev->dev.kobj), +SYSFS_BRIDGE_PORT_ATTR );if (err) goto err0;
net/bridge/br_if.c err2: · line 417
Quoted 7 lines
net/bridge/br_if.c +1
-0@@ -416,6 +411,7 @@ err2:br_fdb_delete_by_port (br, p,1 ); err1:kobject_del (&p->kobj); +return err; err0:kobject_put (&p->kobj);return err;
This is fine, no issues.
Signature · 1 line
Stephen Hemminger <[email protected]>
PATCH 137/196 driver core: remove owner field from struct bus_type
In reply to Greg KHThis isn't used by anything in the driver core, and by no one in the 204 different usages of it in the kernel tree. Remove this field so no one gets any idea that it is needed to be used.
--- include/linux/device.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
include/linux/device.h +0 -1
@@ -51,7 +51,6 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);struct bus_type {const char * name; -struct module * owner;struct kset subsys;struct kset *drivers_kset;
Signature · 1 line
1.5.3.8
PATCH 138/196 driver core: add way to get to bus kset
In reply to Greg KHThis allows an easier way to get to the kset associated with a struct bus_type (you have three to choose from...) This will make it easier to move these fields to be dynamic in a future patch.
--- drivers/base/bus.c | 6 ++++++ drivers/pci/hotplug/pci_hotplug_core.c | 5 ++++- include/linux/device.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletions(-)
drivers/base/bus.c +6 -0
@@ -935,6 +935,12 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) }EXPORT_SYMBOL_GPL (bus_unregister_notifier); +struct kset *bus_get_kset (struct bus_type *bus) +{ +return &bus->subsys; +} +EXPORT_SYMBOL_GPL (bus_get_kset); +int __init buses_init (void ) { bus_kset =kset_create_and_add ("bus" , &bus_uevent_ops,NULL );
drivers/pci/hotplug/pci_hotplug_core.c +4 -1
@@ -699,9 +699,12 @@ int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,static int __init pci_hotplug_init (void ) {int result; +struct kset *pci_bus_kset; + + pci_bus_kset =bus_get_kset (&pci_bus_type); pci_hotplug_slots_kset =kset_create_and_add ("slots" ,NULL , - &pci_bus_type.subsys.kobj); + &pci_bus_kset->kobj);if (!pci_hotplug_slots_kset) { result = -ENOMEM ;err ("Register subsys error\n" );
include/linux/device.h +2 -0
@@ -117,6 +117,8 @@ extern int bus_unregister_notifier(struct bus_type *bus,#define BUS_NOTIFY_UNBIND_DRIVER 0x00000004/* driver about to be unbound */ +extern struct kset *bus_get_kset (struct bus_type *bus); +struct device_driver {const char * name;struct bus_type * bus;
Signature · 1 line
1.5.3.8
PATCH 139/196 driver core: add way to get to bus device klist
In reply to Greg KHThis allows an easier way to get to the device klist associated with a struct bus_type (you have three to choose from...) This will make it easier to move these fields to be dynamic in a future patch.
The only user of this is the PCI core which horribly abuses this interface to rearrange the order of the pci devices. This should be done using the existing bus device walking functions, but that's left for future patches.
--- drivers/base/bus.c | 6 ++++++ drivers/pci/probe.c | 11 +++++++---- include/linux/device.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-)
drivers/base/bus.c +6 -0
@@ -941,6 +941,12 @@ struct kset *bus_get_kset(struct bus_type *bus) }EXPORT_SYMBOL_GPL (bus_get_kset); +struct klist *bus_get_device_klist (struct bus_type *bus) +{ +return &bus->klist_devices; +} +EXPORT_SYMBOL_GPL (bus_get_device_klist); +int __init buses_init (void ) { bus_kset =kset_create_and_add ("bus" , &bus_uevent_ops,NULL );
drivers/pci/probe.c +7 -4
@@ -1210,16 +1210,19 @@ static void __init pci_sort_breadthfirst_klist(void)struct klist_node *n;struct device *dev;struct pci_dev *pdev; +struct klist *device_klist; -spin_lock (&pci_bus_type.klist_devices.k_lock); -list_for_each_safe (pos, tmp, &pci_bus_type.klist_devices.k_list) { + device_klist =bus_get_device_klist (&pci_bus_type); + +spin_lock (&device_klist->k_lock); +list_for_each_safe (pos, tmp, &device_klist->k_list) { n = container_of(pos, struct klist_node, n_node); dev = container_of(n, struct device, knode_bus); pdev =to_pci_dev (dev);pci_insertion_sort_klist (pdev, &sorted_devices); } -list_splice (&sorted_devices, &pci_bus_type.klist_devices.k_list); -spin_unlock (&pci_bus_type.klist_devices.k_lock); +list_splice (&sorted_devices, &device_klist->k_list); +spin_unlock (&device_klist->k_lock); }static void __init pci_insertion_sort_devices (struct pci_dev *a,struct list_head *list)
include/linux/device.h +1 -0
@@ -118,6 +118,7 @@ extern int bus_unregister_notifier(struct bus_type *bus,unbound */ extern struct kset *bus_get_kset (struct bus_type *bus); +extern struct klist *bus_get_device_klist (struct bus_type *bus);struct device_driver {const char * name;
Signature · 1 line
1.5.3.8
PATCH 140/196 driver core: remove fields from struct bus_type
In reply to Greg KHstruct bus_type is static everywhere in the kernel. This moves the kobject in the structure out of it, and a bunch of other private only to the driver core fields are now moved to a private structure. This lets us dynamically create the backing kobject properly and gives us the chance to be able to document to users exactly how to use the struct bus_type as there are no fields they can improperly access.
Thanks to Kay for the build fixes on this patch.
--- drivers/base/base.h | 30 ++++++++++++- drivers/base/bus.c | 116 ++++++++++++++++++++++++++--------------------- drivers/base/core.c | 6 +- drivers/base/dd.c | 4 +- drivers/base/driver.c | 2 +- drivers/base/platform.c | 4 +- include/linux/device.h | 12 +---- 7 files changed, 104 insertions(+), 70 deletions(-)
drivers/base/base.h +29 -1
@@ -1,6 +1,34 @@ -/* initialisation functions */ +/** +* struct bus_type_private - structure to hold the private to the driver core portions of the bus_type structure. +* +* @subsys - the struct kset that defines this bus. This is the main kobject +* @drivers_kset - the list of drivers associated with this bus +* @devices_kset - the list of devices associated with this bus +* @klist_devices - the klist to iterate over the @devices_kset +* @klist_drivers - the klist to iterate over the @drivers_kset +* @bus_notifier - the bus notifier list for anything that cares about things +* on this bus. +* @bus - pointer back to the struct bus_type that this structure is associated +* with. +* +* This structure is the one that is the actual kobject allowing struct +* bus_type to be statically allocated safely. Nothing outside of the driver +* core should ever touch these fields. +*/ +struct bus_type_private { +struct kset subsys; +struct kset *drivers_kset; +struct kset *devices_kset; +struct klist klist_devices; +struct klist klist_drivers; +struct blocking_notifier_head bus_notifier; +unsigned int drivers_autoprobe:1 ; +struct bus_type *bus; +}; + +/* initialisation functions */ extern int devices_init (void );extern int buses_init (void );extern int classes_init (void );
drivers/base/bus.c +65 -51
314 lines not on this page · raw message
drivers/base/core.c +3 -3
@@ -769,7 +769,7 @@ int device_add(struct device *dev)/* notify clients of device entry (new way) */ if (dev->bus) -blocking_notifier_call_chain (&dev->bus->bus_notifier, +blocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_ADD_DEVICE , dev); error =device_create_file (dev, &uevent_attr);
@@ -820,7 +820,7 @@ int device_add(struct device *dev)dpm_sysfs_remove (dev); PMError:if (dev->bus) -blocking_notifier_call_chain (&dev->bus->bus_notifier, +blocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_DEL_DEVICE , dev);device_remove_attrs (dev); AttrsError:
@@ -999,7 +999,7 @@ void device_del(struct device * dev)if (platform_notify_remove)platform_notify_remove (dev);if (dev->bus) -blocking_notifier_call_chain (&dev->bus->bus_notifier, +blocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_DEL_DEVICE , dev);kobject_uevent (&dev->kobj,KOBJ_REMOVE );kobject_del (&dev->kobj);
drivers/base/dd.c +2 -2
@@ -38,7 +38,7 @@ static void driver_bound(struct device *dev) dev->bus_id, dev->driver->name);if (dev->bus) -blocking_notifier_call_chain (&dev->bus->bus_notifier, +blocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_BOUND_DRIVER , dev);klist_add_tail (&dev->knode_driver, &dev->driver->klist_devices);
@@ -296,7 +296,7 @@ static void __device_release_driver(struct device * dev)klist_remove (&dev->knode_driver);if (dev->bus) -blocking_notifier_call_chain (&dev->bus->bus_notifier, +blocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_UNBIND_DRIVER , dev);
drivers/base/driver.c +1 -1
@@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv)*/ struct device_driver *driver_find (const char *name,struct bus_type *bus) { -struct kobject *k =kset_find_obj (bus->drivers_kset, name); +struct kobject *k =kset_find_obj (bus->p->drivers_kset, name);if (k)return to_drv (k);return NULL ;
drivers/base/platform.c +2 -2
@@ -497,12 +497,12 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,* if the probe was successful, and make sure any forced probes of * new devices fail. */ -spin_lock (&platform_bus_type.klist_drivers.k_lock); +spin_lock (&platform_bus_type.p->klist_drivers.k_lock); drv->probe =NULL ;if (code ==0 &&list_empty (&drv->driver.klist_devices.k_list)) retval = -ENODEV ; drv->driver.probe = platform_drv_probe_fail; -spin_unlock (&platform_bus_type.klist_drivers.k_lock); +spin_unlock (&platform_bus_type.p->klist_drivers.k_lock);if (code != retval)platform_driver_unregister (drv);
include/linux/device.h +2 -10
@@ -35,6 +35,7 @@ struct device_driver;struct class ;struct class_device ;struct bus_type ; +struct bus_type_private ;struct bus_attribute {struct attribute attr;
@@ -51,15 +52,6 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);struct bus_type {const char * name; - -struct kset subsys; -struct kset *drivers_kset; -struct kset *devices_kset; -struct klist klist_devices; -struct klist klist_drivers; - -struct blocking_notifier_head bus_notifier; -struct bus_attribute * bus_attrs;struct device_attribute * dev_attrs;struct driver_attribute * drv_attrs;
@@ -75,7 +67,7 @@ struct bus_type {int (*resume_early)(struct device * dev);int (*resume)(struct device * dev); - unsigned int drivers_autoprobe:1; +struct bus_type_private *p; };extern int __must_check bus_register (struct bus_type * bus);
Signature · 1 line
1.5.3.8
PATCH 141/196 USB: use proper call to driver_create_file
In reply to Greg KHDon't try to call the "raw" sysfs_create_file when we already have a helper function to do this kind of work for us.
--- drivers/usb/core/driver.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/usb/core/driver.c +4 -4
@@ -91,8 +91,8 @@ static int usb_create_newid_file(struct usb_driver *usb_drv) goto exit;if (usb_drv->probe !=NULL ) - error =sysfs_create_file (&usb_drv->drvwrap.driver.kobj, - &driver_attr_new_id.attr); + error =driver_create_file (&usb_drv->drvwrap.driver, + &driver_attr_new_id); exit:return error; }
@@ -103,8 +103,8 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv)return ;if (usb_drv->probe !=NULL ) -sysfs_remove_file (&usb_drv->drvwrap.driver.kobj, - &driver_attr_new_id.attr); +driver_remove_file (&usb_drv->drvwrap.driver, + &driver_attr_new_id); }static void usb_free_dynids (struct usb_driver *usb_drv)
Signature · 1 line
1.5.3.8
PATCH 142/196 PCMCIA: use proper call to driver_create_file
In reply to Greg KHDon't try to call the "raw" sysfs_create_file when we already have a helper function to do this kind of work for us.
--- drivers/pcmcia/ds.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pcmcia/ds.c +1 -2
@@ -312,8 +312,7 @@ pcmcia_create_newid_file(struct pcmcia_driver *drv) {int error =0 ;if (drv->probe !=NULL ) - error =sysfs_create_file (&drv->drv.kobj, - &driver_attr_new_id.attr); + error =driver_create_file (&drv->drv, &driver_attr_new_id);return error; }
Signature · 1 line
1.5.3.8
PATCH 143/196 PCI: use proper call to driver_create_file
In reply to Greg KHDon't try to call the "raw" sysfs_create_file when we already have a helper function to do this kind of work for us.
--- drivers/pci/pci-driver.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/pci/pci-driver.c +7 -2
@@ -96,17 +96,21 @@ pci_create_newid_file(struct pci_driver *drv) {int error =0 ;if (drv->probe !=NULL ) - error =sysfs_create_file (&drv->driver.kobj, - &driver_attr_new_id.attr); + error =driver_create_file (&drv->driver, &driver_attr_new_id);return error; } +static void pci_remove_newid_file (struct pci_driver *drv) +{ +driver_remove_file (&drv->driver, &driver_attr_new_id); +}#else /* !CONFIG_HOTPLUG */ static inline void pci_free_dynids (struct pci_driver *drv) {}static inline int pci_create_newid_file (struct pci_driver *drv) {return 0 ; } +static inline void pci_remove_newid_file (struct pci_driver *drv) {}#endif /**
@@ -447,6 +451,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,void pci_unregister_driver (struct pci_driver *drv) { +pci_remove_newid_file (drv);driver_unregister (&drv->driver);pci_free_dynids (drv); }
Signature · 1 line
1.5.3.8
PATCH 144/196 PCI: remove foolish code from pci-driver.c
In reply to Greg KHThe PCI bus should not be trying to declare its own attribute type. Especially as this code could never ever be called because the driver core overwrites the driver kobject type to be its own internal type. Delete all of this code as it was never being used and is not correct.
Also update my copyright on the file while I'm touching things there.
--- drivers/pci/pci-driver.c | 50 ++++----------------------------------------- 1 files changed, 5 insertions(+), 45 deletions(-)
drivers/pci/pci-driver.c +5 -45
@@ -1,6 +1,11 @@/* * drivers/pci/pci-driver.c * +* (C) Copyright 2002-2004, 2007 Greg Kroah-Hartman <[email protected]> +* (C) Copyright 2007 Novell Inc. +* +* Released under the GPL v2 only. +* */ #include <linux/pci.h>
@@ -356,50 +361,6 @@ static void pci_device_shutdown(struct device *dev) drv->shutdown (pci_dev); } -#define kobj_to_pci_driver (obj) container_of(obj, struct device_driver, kobj) -#define attr_to_driver_attribute (obj) container_of(obj, struct driver_attribute, attr) - -static ssize_t -pci_driver_attr_show (struct kobject * kobj,struct attribute *attr,char *buf) -{ -struct device_driver *driver =kobj_to_pci_driver (kobj); -struct driver_attribute *dattr =attr_to_driver_attribute (attr); -ssize_t ret; - -if (!get_driver (driver)) -return -ENODEV ; - - ret = dattr->show ? dattr->show (driver, buf) : -EIO ; - -put_driver (driver); -return ret; -} - -static ssize_t -pci_driver_attr_store (struct kobject * kobj,struct attribute *attr, -const char *buf,size_t count) -{ -struct device_driver *driver =kobj_to_pci_driver (kobj); -struct driver_attribute *dattr =attr_to_driver_attribute (attr); -ssize_t ret; - -if (!get_driver (driver)) -return -ENODEV ; - - ret = dattr->store ? dattr->store (driver, buf, count) : -EIO ; - -put_driver (driver); -return ret; -} - -static struct sysfs_ops pci_driver_sysfs_ops = { - .show = pci_driver_attr_show, - .store = pci_driver_attr_store, -}; -static struct kobj_type pci_driver_kobj_type = { - .sysfs_ops = &pci_driver_sysfs_ops, -}; -/** * __pci_register_driver - register a new pci driver * @drv: the driver structure to register
@@ -421,7 +382,6 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner, drv->driver.bus = &pci_bus_type; drv->driver.owner = owner; drv->driver.mod_name = mod_name; - drv->driver.kobj.ktype = &pci_driver_kobj_type;spin_lock_init (&drv->dynids.lock);INIT_LIST_HEAD (&drv->dynids.list);
Signature · 1 line
1.5.3.8
PATCH 145/196 driver core: Introduce default attribute groups.
In reply to Greg KHFrom: Cornelia Huck <[email protected]>
This is lot like default attributes for devices (and indeed, a lot of the code is lifted from there).
--- drivers/base/driver.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/linux/device.h | 1 + 2 files changed, 42 insertions(+), 1 deletions(-)
drivers/base/driver.c +41 -1
@@ -142,6 +142,37 @@ void put_driver(struct device_driver * drv)kobject_put (&drv->kobj); } +static int driver_add_groups (struct device_driver *drv, +struct attribute_group **groups) +{ +int error =0 ; +int i; + +if (groups) { +for (i =0 ; groups[i]; i++) { + error =sysfs_create_group (&drv->kobj, groups[i]); +if (error) { +while (--i >=0 ) +sysfs_remove_group (&drv->kobj, + groups[i]); +break ; + } + } + } +return error; +} + +static void driver_remove_groups (struct device_driver *drv, +struct attribute_group **groups) +{ +int i; + +if (groups) +for (i =0 ; groups[i]; i++) +sysfs_remove_group (&drv->kobj, groups[i]); +} + +/** * driver_register - register driver with bus * @drv: driver to register
@@ -152,13 +183,21 @@ void put_driver(struct device_driver * drv)*/ int driver_register (struct device_driver * drv) { +int ret; +if ((drv->bus->probe && drv->probe) || (drv->bus->remove && drv->remove) || (drv->bus->shutdown && drv->shutdown)) {printk (KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n" , drv->name); }klist_init (&drv->klist_devices,NULL ,NULL ); -return bus_add_driver (drv); + ret =bus_add_driver (drv); +if (ret) +return ret; + ret =driver_add_groups (drv, drv->groups); +if (ret) +bus_remove_driver (drv); +return ret; }/**
@@ -170,6 +209,7 @@ int driver_register(struct device_driver * drv)void driver_unregister (struct device_driver * drv) { +driver_remove_groups (drv, drv->groups);bus_remove_driver (drv); }
include/linux/device.h +1 -0
@@ -129,6 +129,7 @@ struct device_driver {void (*shutdown) (struct device * dev);int (*suspend) (struct device * dev,pm_message_t state);int (*resume) (struct device * dev); +struct attribute_group **groups; };
Signature · 1 line
1.5.3.8
PATCH 146/196 netiucv: Use device_driver default attribute groups.
In reply to Greg KHFrom: Cornelia Huck <[email protected]>
--- drivers/s390/net/netiucv.c | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-)
drivers/s390/net/netiucv.c +6 -10
@@ -2089,6 +2089,11 @@ static struct attribute_group netiucv_drv_attr_group = { .attrs = netiucv_drv_attrs, }; +static struct attribute_group *netiucv_drv_attr_groups[] = { + &netiucv_drv_attr_group, +NULL , +}; +static void netiucv_banner (void ) {PRINT_INFO ("NETIUCV driver initialized\n" );
@@ -2113,7 +2118,6 @@ static void __exit netiucv_exit(void)netiucv_unregister_device (dev); } -sysfs_remove_group (&netiucv_driver.kobj, &netiucv_drv_attr_group);driver_unregister (&netiucv_driver);iucv_unregister (&netiucv_handler,1 );iucv_unregister_dbf_views ();
@@ -2133,6 +2137,7 @@ static int __init netiucv_init(void)if (rc) goto out_dbf;IUCV_DBF_TEXT (trace,3 , __FUNCTION__); + netiucv_driver.groups = netiucv_drv_attr_groups; rc =driver_register (&netiucv_driver);if (rc) {PRINT_ERR ("NETIUCV: failed to register driver.\n" );
@@ -2140,18 +2145,9 @@ static int __init netiucv_init(void) goto out_iucv; } - rc =sysfs_create_group (&netiucv_driver.kobj, &netiucv_drv_attr_group); -if (rc) { -PRINT_ERR ("NETIUCV: failed to add driver attributes.\n" ); -IUCV_DBF_TEXT_ (setup,2 , -"ret %d - netiucv_drv_attr_group\n" , rc); - goto out_driver; - }netiucv_banner ();return rc; -out_driver: -driver_unregister (&netiucv_driver); out_iucv:iucv_unregister (&netiucv_handler,1 ); out_dbf:
Signature · 1 line
1.5.3.8
PATCH 147/196 zfcp: Use device_driver default attribute groups.
In reply to Greg KHFrom: Cornelia Huck <[email protected]>
--- drivers/s390/scsi/zfcp_ccw.c | 14 ++++---------- drivers/s390/scsi/zfcp_ext.h | 3 +-- drivers/s390/scsi/zfcp_sysfs_driver.c | 27 ++++----------------------- 3 files changed, 9 insertions(+), 35 deletions(-)
drivers/s390/scsi/zfcp_ccw.c +4 -10
@@ -52,6 +52,9 @@ static struct ccw_driver zfcp_ccw_driver = { .set_offline = zfcp_ccw_set_offline, .notify = zfcp_ccw_notify, .shutdown = zfcp_ccw_shutdown, + .driver = { + .groups = zfcp_driver_attr_groups, + }, };MODULE_DEVICE_TABLE (ccw, zfcp_ccw_device_id);
@@ -251,16 +254,7 @@ zfcp_ccw_notify(struct ccw_device *ccw_device, int event)int __init zfcp_ccw_register (void ) { -int retval; - - retval =ccw_driver_register (&zfcp_ccw_driver); -if (retval) - goto out; - retval =zfcp_sysfs_driver_create_files (&zfcp_ccw_driver.driver); -if (retval) -ccw_driver_unregister (&zfcp_ccw_driver); - out: -return retval; +return ccw_driver_register (&zfcp_ccw_driver); }/**
drivers/s390/scsi/zfcp_ext.h +1 -2
@@ -27,8 +27,7 @@extern struct zfcp_data zfcp_data;/******************************** SYSFS *************************************/ -extern int zfcp_sysfs_driver_create_files (struct device_driver *); -extern void zfcp_sysfs_driver_remove_files (struct device_driver *); +extern struct attribute_group *zfcp_driver_attr_groups[];extern int zfcp_sysfs_adapter_create_files (struct device *);extern void zfcp_sysfs_adapter_remove_files (struct device *);extern int zfcp_sysfs_port_create_files (struct device *,u32 );
drivers/s390/scsi/zfcp_sysfs_driver.c +4 -23
@@ -98,28 +98,9 @@ static struct attribute_group zfcp_driver_attr_group = { .attrs = zfcp_driver_attrs, }; -/** -* zfcp_sysfs_create_driver_files - create sysfs driver files -* @dev: pointer to belonging device -* -* Create all sysfs attributes of the zfcp device driver -*/ -int -zfcp_sysfs_driver_create_files (struct device_driver *drv) -{ -return sysfs_create_group (&drv->kobj, &zfcp_driver_attr_group); -} - -/** -* zfcp_sysfs_remove_driver_files - remove sysfs driver files -* @dev: pointer to belonging device -* -* Remove all sysfs attributes of the zfcp device driver -*/ -void -zfcp_sysfs_driver_remove_files (struct device_driver *drv) -{ -sysfs_remove_group (&drv->kobj, &zfcp_driver_attr_group); -} +struct attribute_group *zfcp_driver_attr_groups[] = { + &zfcp_driver_attr_group, +NULL , +};#undef ZFCP_LOG_AREA
Signature · 1 line
1.5.3.8
PATCH 148/196 Infiniband: make ipath driver use default driver groups.
In reply to Greg KHMake the ipath driver use the new driver functions so that it does not touch the sysfs portion of the driver structure.
We also remove the redundant symlink from the device back to the driver, as it is already in the sysfs tree. Any userspace tools should be using the standard symlink, not some driver specific one.
--- drivers/infiniband/hw/ehca/ehca_main.c | 13 +++++++---- drivers/infiniband/hw/ipath/ipath_driver.c | 17 +++------------ drivers/infiniband/hw/ipath/ipath_kernel.h | 3 +- drivers/infiniband/hw/ipath/ipath_sysfs.c | 30 ++++----------------------- 4 files changed, 18 insertions(+), 45 deletions(-)
drivers/infiniband/hw/ehca/ehca_main.c +8 -5
@@ -590,6 +590,11 @@ static struct attribute_group ehca_drv_attr_grp = { .attrs = ehca_drv_attrs }; +static struct attribute_group *ehca_drv_attr_groups[] = { + &ehca_drv_attr_grp, +NULL , +}; +#define EHCA_RESOURCE_ATTR (name) \ static ssize_t ehca_show_##name(struct device *dev, \ struct device_attribute *attr, \
@@ -899,6 +904,9 @@ static struct of_platform_driver ehca_driver = { .match_table = ehca_device_table, .probe = ehca_probe, .remove = ehca_remove, + .driver = { + .groups = ehca_drv_attr_groups, + }, };void ehca_poll_eqs (unsigned long data)
@@ -957,10 +965,6 @@ int __init ehca_module_init(void) goto module_init2; } - ret =sysfs_create_group (&ehca_driver.driver.kobj, &ehca_drv_attr_grp); -if (ret)/* only complain; we can live without attributes */ -ehca_gen_err ("Cannot create driver attributes ret=%d" , ret); -if (ehca_poll_all_eqs !=1 ) {ehca_gen_err ("WARNING!!!" );ehca_gen_err ("It is possible to lose interrupts." );
@@ -986,7 +990,6 @@ void __exit ehca_module_exit(void)if (ehca_poll_all_eqs ==1 )del_timer_sync (&poll_eqs_timer); -sysfs_remove_group (&ehca_driver.driver.kobj, &ehca_drv_attr_grp);ibmebus_unregister_driver (&ehca_driver);ehca_destroy_slab_caches ();
drivers/infiniband/hw/ipath/ipath_driver.c +4 -13
@@ -121,6 +121,9 @@ static struct pci_driver ipath_driver = { .probe = ipath_init_one, .remove = __devexit_p(ipath_remove_one), .id_table = ipath_pci_tbl, + .driver = { + .groups = ipath_driver_attr_groups, + }, };static void ipath_check_status (struct work_struct *work)
@@ -2217,25 +2220,15 @@ static int __init infinipath_init(void) goto bail_unit; } - ret =ipath_driver_create_group (&ipath_driver.driver); -if (ret <0 ) { - printk(KERN_ERR IPATH_DRV_NAME ": Unable to create driver " - "sysfs entries: error %d\n", -ret); - goto bail_pci; - } - ret =ipath_init_ipathfs ();if (ret <0 ) { printk(KERN_ERR IPATH_DRV_NAME ": Unable to create " "ipathfs: error %d\n", -ret); - goto bail_group; + goto bail_pci; } goto bail; -bail_group: -ipath_driver_remove_group (&ipath_driver.driver); - bail_pci:pci_unregister_driver (&ipath_driver);
@@ -2250,8 +2243,6 @@ static void __exit infinipath_cleanup(void) {ipath_exit_ipathfs (); -ipath_driver_remove_group (&ipath_driver.driver); -ipath_cdbg (VERBOSE ,"Unregistering pci driver\n" );pci_unregister_driver (&ipath_driver);
drivers/infiniband/hw/ipath/ipath_kernel.h +1 -2
@@ -938,8 +938,7 @@ struct device_driver;extern const char ib_ipath_version[]; -int ipath_driver_create_group (struct device_driver *); -void ipath_driver_remove_group (struct device_driver *); +extern struct attribute_group *ipath_driver_attr_groups[];int ipath_device_create_group (struct device *,struct ipath_devdata *);void ipath_device_remove_group (struct device *,struct ipath_devdata *);
drivers/infiniband/hw/ipath/ipath_sysfs.c +5 -25
@@ -683,6 +683,11 @@ static struct attribute_group driver_attr_group = { .attrs = driver_attributes }; +struct attribute_group *ipath_driver_attr_groups[] = { + &driver_attr_group, +NULL , +}; + static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid); static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc); static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
@@ -753,24 +758,9 @@ int ipath_expose_reset(struct device *dev)return ret; } -int ipath_driver_create_group (struct device_driver *drv) -{ -int ret; - - ret =sysfs_create_group (&drv->kobj, &driver_attr_group); - -return ret; -} - -void ipath_driver_remove_group (struct device_driver *drv) -{ -sysfs_remove_group (&drv->kobj, &driver_attr_group); -} -int ipath_device_create_group (struct device *dev,struct ipath_devdata *dd) {int ret; -char unit[5 ]; ret =sysfs_create_group (&dev->kobj, &dev_attr_group);if (ret)
@@ -780,11 +770,6 @@ int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)if (ret) goto bail_attrs; -snprintf (unit,sizeof (unit),"%02d" , dd->ipath_unit); - ret =sysfs_create_link (&dev->driver->kobj, &dev->kobj, unit); -if (ret ==0 ) - goto bail; -sysfs_remove_group (&dev->kobj, &dev_counter_attr_group); bail_attrs:sysfs_remove_group (&dev->kobj, &dev_attr_group);
@@ -794,11 +779,6 @@ bail:void ipath_device_remove_group (struct device *dev,struct ipath_devdata *dd) { -char unit[5 ]; - -snprintf (unit,sizeof (unit),"%02d" , dd->ipath_unit); -sysfs_remove_link (&dev->driver->kobj, unit); -sysfs_remove_group (&dev->kobj, &dev_counter_attr_group);sysfs_remove_group (&dev->kobj, &dev_attr_group);
Signature · 1 line
1.5.3.8
Re: [PATCH 148/196] Infiniband: make ipath driver use default driver groups.
Hey Greg,
with Linus's latest kernel v2.6.24-412-gb47711b (which includes the patch in the email I'm replying to), I see the following when I do "modprobe -r ib_ipath" (on a system that actually has ipath hardware):
kernel BUG at fs/sysfs/group.c:74!
invalid opcode: 0000 [1] SMP
CPU 1
Modules linked in: fan ac battery ipv6 nfs lockd nfs_acl sunrpc dm_snapshot dm_mirror dm_mod loop ide_cd cdrom e1000 amd74xx generic psmouse shpchp pci_hotplug thermal ib_ipath serio_raw ehci_hcd ohci_hcd evdev button i2c_nforce2 ide_core processor ib_core k8temp i2c_core Pid: 3975, comm: modprobe Not tainted 2.6.24 #24 RIP: 0010:[<ffffffff802bdbdb>] [<ffffffff802bdbdb>] sysfs_remove_group+0x25/0x94 RSP: 0000:ffff8101fbc33db8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffff81007d8bc070 RDX: ffff81007d634272 RSI: ffff81007d634d00 RDI: ffffffff80503090 RBP: ffffffff880a7220 R08: 0000000000000000 R09: ffff81007d8bc070 R10: 0000000000000000 R11: 00000000fd812590 R12: ffff81007d8bc070 R13: 00007fffc6f88c80 R14: 0000000000000000 R15: 0000000000000000 FS: 00002acbe409b6e0(0000) GS:ffff81007e001a00(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 00002acbe3e59de0 CR3: 000000007d482000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process modprobe (pid: 3975, threadinfo ffff8101fbc32000, task ffff8101fbead590) Stack: 000000000e9000ff ffff81007d8bc160 ffff81007d8bc070 ffffffff88087574 ffffc20001734000 ffffc20001734000 ffffffff880a7050 ffffffff88074b26 ffffffff804bd39a ffff81007d8bc000 ffffffff880a7050 ffffffff804bd39a Call Trace: [<ffffffff88087574>] :ib_ipath:ipath_device_remove_group+0x20/0x42 [<ffffffff88074b26>] :ib_ipath:ipath_remove_one+0x9f/0x431 [<ffffffff803235e5>] pci_device_remove+0x24/0x47 [<ffffffff8036ec01>] __device_release_driver+0x74/0x97 [<ffffffff8036f075>] driver_detach+0x96/0xd5 [<ffffffff8036e568>] bus_remove_driver+0x7b/0x9e [<ffffffff803238da>] pci_unregister_driver+0x29/0x7d [<ffffffff8809093f>] :ib_ipath:infinipath_cleanup+0x33/0x40 [<ffffffff8025032a>] sys_delete_module+0x199/0x1cf [<ffffffff80318400>] __up_read+0x2/0x8a [<ffffffff8020befe>] system_call+0x7e/0x83 Code: 0f 0b eb fe 48 85 db 74 2e 83 3b 00 75 26 48 c7 c1 d8 ae 43 RIP [<ffffffff802bdbdb>] sysfs_remove_group+0x25/0x94 RSP <ffff8101fbc33db8>
The BUG() in question is the one here:
void sysfs_remove_group(struct kobject * kobj,
const struct attribute_group * grp)
{
struct sysfs_dirent *dir_sd = kobj->sd;
struct sysfs_dirent *sd;
if (grp->name) {
sd = sysfs_get_dirent(dir_sd, grp->name);
BUG_ON(!sd);Any ideas here? I'll continue to try to relearn all the sysfs stuff but a hint my make things go faster.
Thanks,
Roland
Re: [PATCH 148/196] Infiniband: make ipath driver use default driver groups.
So I think it is coming from the following code in ipath_sysfs.c:
int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
{
int ret;
ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
if (ret)
goto bail;
ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
if (ret)
goto bail_attrs;
sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
bail_attrs:
sysfs_remove_group(&dev->kobj, &dev_attr_group);
bail:
return ret;
}note that the success path falls through into the error path and removes the groups it just created, which means that on initialization the groups are already removed, so we hit the BUG on the second try to remove the groups on module exit.
And I think this chunk of your patch:
- snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); - ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit); - if (ret == 0) - goto bail; -
was what broke it. (Note the "if (ret == 0) then skip error unwinding" code that got deleted by mistake -- not surprising given how hard to read that construction is)
My bad for not testing -mm better. I'll queue this up to fix it:
drivers/infiniband/hw/ipath/ipath_sysfs.c +2 -1
@@ -770,7 +770,8 @@ int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)if (ret) goto bail_attrs; -sysfs_remove_group (&dev->kobj, &dev_counter_attr_group); +return 0 ; + bail_attrs:sysfs_remove_group (&dev->kobj, &dev_attr_group); bail:
Re: [PATCH 148/196] Infiniband: make ipath driver use default driver groups.
Quoted 34 lines · Roland Dreier
So I think it is coming from the following code in
ipath_sysfs.c:int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd) { int ret; ret = sysfs_create_group(&dev->kobj, &dev_attr_group); if (ret) goto bail; ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group); if (ret) goto bail_attrs; sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); bail_attrs: sysfs_remove_group(&dev->kobj, &dev_attr_group); bail: return ret; }note that the success path falls through into the error path and removes the groups it just created, which means that on initialization the groups are already removed, so we hit the BUG on the second try to remove the groups on module exit.
And I think this chunk of your patch:
- snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); - ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit); - if (ret == 0) - goto bail; -
Quoted 5 lines
was what broke it. (Note the "if (ret == 0) then skip error unwinding" code that got deleted by mistake -- not surprising given how hard to read that construction is)
My bad for not testing -mm better. I'll queue this up to fix it:
Thanks for the fix, and sorry for causing that, it was a complex error path :)
Although a BUG() for when we try to remove a file that is no longer there seems pretty harsh, I think I'll change that to a WARN_ON() so that people just know to fix up their code, not kill the kernel entirely.
thanks,
greg k-h
PATCH 149/196 Driver: add driver_add_kobj for looney iseries_veth driver
In reply to Greg KHThe iseries driver wants to hang kobjects off of its driver, so, to preserve backwards compatibility, we need to add a call to the driver core to allow future changes to work properly.
Hopefully no one uses this function in the future and the iseries_veth driver authors come to their senses so I can remove this hack...
--- drivers/base/driver.c | 24 ++++++++++++++++++++++++ drivers/net/iseries_veth.c | 2 +- include/linux/device.h | 4 ++++ 3 files changed, 29 insertions(+), 1 deletions(-)
drivers/base/driver.c +24 -0
@@ -124,6 +124,30 @@ void driver_remove_file(struct device_driver * drv, struct driver_attribute * at/** +* driver_add_kobj - add a kobject below the specified driver +* +* You really don't want to do this, this is only here due to one looney +* iseries driver, go poke those developers if you are annoyed about +* this... +*/ +int driver_add_kobj (struct device_driver *drv,struct kobject *kobj, +const char *fmt, ...) +{ +va_list args; +char *name; + +va_start (args, fmt); + name =kvasprintf (GFP_KERNEL , fmt, args); +va_end (args); + +if (!name) +return -ENOMEM ; + +return kobject_add_ng (kobj, &drv->kobj,"%s" , name); +} +EXPORT_SYMBOL_GPL (driver_add_kobj); + +/** * get_driver - increment driver reference count. * @drv: driver. */
drivers/net/iseries_veth.c +1 -1
@@ -1705,7 +1705,7 @@ static int __init veth_module_init(void) kobj = &veth_cnx[i]->kobject;/* If the add failes, complain but otherwise continue */ -if (0 !=kobject_add_ng (kobj, &veth_driver.driver.kobj, +if (0 !=driver_add_kobj (&veth_driver.driver, kobj,"cnx%.2d" , veth_cnx[i]->remote_lp))veth_error ("cnx %d: Failed adding to sysfs.\n" , i); }
include/linux/device.h +4 -0
@@ -156,6 +156,10 @@ extern int __must_check driver_create_file(struct device_driver *, struct driver_attribute *);extern void driver_remove_file (struct device_driver *,struct driver_attribute *); +extern int __must_check driver_add_kobj (struct device_driver *drv, +struct kobject *kobj, +const char *fmt, ...); +extern int __must_check driver_for_each_device (struct device_driver * drv,struct device *start,void *data,int (*fn)(struct device *,void *));
Signature · 1 line
1.5.3.8
PATCH 150/196 Driver core: move the driver specific module code into the driver core
In reply to Greg KHThe module driver specific code should belong in the driver core, not in the kernel/ directory. So move this code. This is done in preparation for some struct device_driver rework that should be confined to the driver core code only.
This also lets us keep from exporting these functions, as no external code should ever be calling it.
Thanks to Andrew Morton for the !CONFIG_MODULES fix.
--- drivers/base/Makefile | 1 + drivers/base/base.h | 9 +++++ drivers/base/module.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/module.h | 15 -------- kernel/module.c | 87 -------------------------------------------- 5 files changed, 104 insertions(+), 102 deletions(-) create mode 100644 drivers/base/module.c
drivers/base/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o obj-$(CONFIG_SMP) += topology.o +obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o ifeq ($(CONFIG_DEBUG_DRIVER),y)
drivers/base/base.h +9 -0
@@ -73,3 +73,12 @@ extern char *make_class_name(const char *name, struct kobject *kobj);extern int devres_release_all (struct device *dev);extern struct kset *devices_kset; + +#ifdef CONFIG_MODULES +extern void module_add_driver (struct module *mod,struct device_driver *drv); +extern void module_remove_driver (struct device_driver *drv); +#else +static inline void module_add_driver (struct module *mod, +struct device_driver *drv) { } +static inline void module_remove_driver (struct device_driver *drv) { } +#endif
drivers/base/module.c new file +94 -0
94 lines not on this page · raw message
include/linux/module.h +0 -15
@@ -609,21 +609,6 @@ static inline void module_remove_modinfo_attrs(struct module *mod)#endif /* CONFIG_SYSFS */ -#if defined(CONFIG_SYSFS ) && defined(CONFIG_MODULES ) - -void module_add_driver (struct module *mod,struct device_driver *drv); -void module_remove_driver (struct device_driver *drv); - -#else /* not both CONFIG_SYSFS && CONFIG_MODULES */ - -static inline void module_add_driver (struct module *mod,struct device_driver *drv) -{ } - -static inline void module_remove_driver (struct device_driver *drv) -{ } - -#endif -#define symbol_request (x) try_then_request_module(symbol_get(x), "symbol:" #x)/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
kernel/module.c +0 -87
93 lines not on this page · raw message
Signature · 1 line
1.5.3.8
PATCH 151/196 Driver core: move the static kobject out of struct driver
In reply to Greg KHThis patch removes the kobject, and a few other driver-core-only fields out of struct driver and into the driver core only. Now drivers can be safely create on the stack or statically (like they currently are.)
--- drivers/base/base.h | 8 +++++ drivers/base/bus.c | 71 +++++++++++++++++++++++++--------------------- drivers/base/dd.c | 24 ++++++++-------- drivers/base/driver.c | 40 +++++++++++++++++--------- drivers/base/module.c | 12 ++++---- drivers/base/platform.c | 2 +- include/linux/device.h | 16 ++++------ 7 files changed, 99 insertions(+), 74 deletions(-)
drivers/base/base.h +8 -0
@@ -27,6 +27,14 @@ struct bus_type_private {struct bus_type *bus; }; +struct driver_private { +struct kobject kobj; +struct klist klist_devices; +struct klist_node knode_bus; +struct module_kobject *mkobj; +struct device_driver *driver; +}; +#define to_driver (obj) container_of(obj, struct driver_private, kobj)/* initialisation functions */ extern int devices_init (void );
drivers/base/bus.c +39 -32
161 lines not on this page · raw message
drivers/base/dd.c +12 -12
@@ -11,6 +11,8 @@* * Copyright (c) 2002-5 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs +* Copyright (c) 2007 Greg Kroah-Hartman <[email protected]> +* Copyright (c) 2007 Novell Inc. * * This file is released under the GPLv2 */
@@ -23,8 +25,6 @@#include "base.h" #include "power/power.h" -#define to_drv (node) container_of(node, struct device_driver, kobj.entry) -static void driver_bound (struct device *dev) {
@@ -41,20 +41,20 @@ static void driver_bound(struct device *dev)blocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_BOUND_DRIVER , dev); -klist_add_tail (&dev->knode_driver, &dev->driver->klist_devices); +klist_add_tail (&dev->knode_driver, &dev->driver->p->klist_devices); }static int driver_sysfs_add (struct device *dev) {int ret; - ret =sysfs_create_link (&dev->driver->kobj, &dev->kobj, + ret =sysfs_create_link (&dev->driver->p->kobj, &dev->kobj,kobject_name (&dev->kobj));if (ret ==0 ) { - ret =sysfs_create_link (&dev->kobj, &dev->driver->kobj, + ret =sysfs_create_link (&dev->kobj, &dev->driver->p->kobj,"driver" );if (ret) -sysfs_remove_link (&dev->driver->kobj, +sysfs_remove_link (&dev->driver->p->kobj,kobject_name (&dev->kobj)); }return ret;
@@ -65,7 +65,7 @@ static void driver_sysfs_remove(struct device *dev)struct device_driver *drv = dev->driver;if (drv) { -sysfs_remove_link (&drv->kobj,kobject_name (&dev->kobj)); +sysfs_remove_link (&drv->p->kobj,kobject_name (&dev->kobj));sysfs_remove_link (&dev->kobj,"driver" ); } }
@@ -339,15 +339,15 @@ void driver_detach(struct device_driver * drv)struct device * dev;for (;;) { -spin_lock (&drv->klist_devices.k_lock); -if (list_empty (&drv->klist_devices.k_list)) { -spin_unlock (&drv->klist_devices.k_lock); +spin_lock (&drv->p->klist_devices.k_lock); +if (list_empty (&drv->p->klist_devices.k_list)) { +spin_unlock (&drv->p->klist_devices.k_lock);break ; } - dev =list_entry (drv->klist_devices.k_list.prev, + dev =list_entry (drv->p->klist_devices.k_list.prev, struct device, knode_driver.n_node);get_device (dev); -spin_unlock (&drv->klist_devices.k_lock); +spin_unlock (&drv->p->klist_devices.k_lock);if (dev->parent)/* Needed for USB */ down (&dev->parent->sem);
drivers/base/driver.c +26 -14
@@ -3,6 +3,8 @@* * Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs +* Copyright (c) 2007 Greg Kroah-Hartman <[email protected]> +* Copyright (c) 2007 Novell Inc. * * This file is released under the GPLv2 *
@@ -15,7 +17,6 @@#include "base.h" #define to_dev (node) container_of(node, struct device, driver_list) -#define to_drv (obj) container_of(obj, struct device_driver, kobj)static struct device *next_device (struct klist_iter * i)
@@ -44,7 +45,7 @@ int driver_for_each_device(struct device_driver * drv, struct device * start,if (!drv)return -EINVAL ; -klist_iter_init_node (&drv->klist_devices, &i, +klist_iter_init_node (&drv->p->klist_devices, &i, start ? &start->knode_driver :NULL );while ((dev =next_device (&i)) && !error) error =fn (dev, data);
@@ -80,7 +81,7 @@ struct device * driver_find_device(struct device_driver *drv,if (!drv)return NULL ; -klist_iter_init_node (&drv->klist_devices, &i, +klist_iter_init_node (&drv->p->klist_devices, &i, (start ? &start->knode_driver :NULL ));while ((dev =next_device (&i)))if (match (dev, data) &&get_device (dev))
@@ -100,7 +101,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att {int error;if (get_driver (drv)) { - error =sysfs_create_file (&drv->kobj, &attr->attr); + error =sysfs_create_file (&drv->p->kobj, &attr->attr);put_driver (drv); }else error = -EINVAL ;
@@ -117,7 +118,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * attvoid driver_remove_file (struct device_driver * drv,struct driver_attribute * attr) {if (get_driver (drv)) { -sysfs_remove_file (&drv->kobj, &attr->attr); +sysfs_remove_file (&drv->p->kobj, &attr->attr);put_driver (drv); } }
@@ -143,7 +144,7 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,if (!name)return -ENOMEM ; -return kobject_add_ng (kobj, &drv->kobj,"%s" , name); +return kobject_add_ng (kobj, &drv->p->kobj,"%s" , name); }EXPORT_SYMBOL_GPL (driver_add_kobj);
@@ -153,7 +154,15 @@ EXPORT_SYMBOL_GPL(driver_add_kobj);*/ struct device_driver *get_driver (struct device_driver * drv) { -return drv ?to_drv (kobject_get (&drv->kobj)) :NULL ; +if (drv) { +struct driver_private *priv; +struct kobject *kobj; + + kobj =kobject_get (&drv->p->kobj); + priv =to_driver (kobj); +return priv->driver; + } +return NULL ; }
@@ -163,7 +172,7 @@ struct device_driver * get_driver(struct device_driver * drv)*/ void put_driver (struct device_driver * drv) { -kobject_put (&drv->kobj); +kobject_put (&drv->p->kobj); } static int driver_add_groups(struct device_driver *drv,
@@ -174,10 +183,10 @@ static int driver_add_groups(struct device_driver *drv,if (groups) {for (i =0 ; groups[i]; i++) { - error =sysfs_create_group (&drv->kobj, groups[i]); + error =sysfs_create_group (&drv->p->kobj, groups[i]);if (error) {while (--i >=0 ) -sysfs_remove_group (&drv->kobj, +sysfs_remove_group (&drv->p->kobj, groups[i]);break ; }
@@ -193,7 +202,7 @@ static void driver_remove_groups(struct device_driver *drv,if (groups)for (i =0 ; groups[i]; i++) -sysfs_remove_group (&drv->kobj, groups[i]); +sysfs_remove_group (&drv->p->kobj, groups[i]); }
@@ -214,7 +223,6 @@ int driver_register(struct device_driver * drv) (drv->bus->shutdown && drv->shutdown)) {printk (KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n" , drv->name); } -klist_init (&drv->klist_devices,NULL ,NULL ); ret =bus_add_driver (drv);if (ret)return ret;
@@ -250,8 +258,12 @@ void driver_unregister(struct device_driver * drv)struct device_driver *driver_find (const char *name,struct bus_type *bus) {struct kobject *k =kset_find_obj (bus->p->drivers_kset, name); -if (k) -return to_drv (k); +struct driver_private *priv; + +if (k) { + priv =to_driver (k); +return priv->driver; + }return NULL ; }
drivers/base/module.c +6 -6
@@ -50,7 +50,7 @@ void module_add_driver(struct module *mod, struct device_driver *drv)if (mkobj) { mk = container_of(mkobj, struct module_kobject, kobj);/* remember our module structure */ - drv->mkobj = mk; + drv->p->mkobj = mk;/* kset_find_obj took a reference */ kobject_put (mkobj); }
@@ -60,11 +60,11 @@ void module_add_driver(struct module *mod, struct device_driver *drv)return ;/* Don't check return codes; these calls are idempotent */ - no_warn =sysfs_create_link (&drv->kobj, &mk->kobj,"module" ); + no_warn =sysfs_create_link (&drv->p->kobj, &mk->kobj,"module" ); driver_name =make_driver_name (drv);if (driver_name) {module_create_drivers_dir (mk); - no_warn =sysfs_create_link (mk->drivers_dir, &drv->kobj, + no_warn =sysfs_create_link (mk->drivers_dir, &drv->p->kobj, driver_name);kfree (driver_name); }
@@ -78,12 +78,12 @@ void module_remove_driver(struct device_driver *drv)if (!drv)return ; -sysfs_remove_link (&drv->kobj,"module" ); +sysfs_remove_link (&drv->p->kobj,"module" );if (drv->owner) mk = &drv->owner->mkobj; -else if (drv->mkobj) - mk = drv->mkobj; +else if (drv->p->mkobj) + mk = drv->p->mkobj;if (mk && mk->drivers_dir) { driver_name =make_driver_name (drv);if (driver_name) {
drivers/base/platform.c +1 -1
@@ -499,7 +499,7 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,*/ spin_lock (&platform_bus_type.p->klist_drivers.k_lock); drv->probe =NULL ; -if (code ==0 &&list_empty (&drv->driver.klist_devices.k_list)) +if (code ==0 &&list_empty (&drv->driver.p->klist_devices.k_list)) retval = -ENODEV ; drv->driver.probe = platform_drv_probe_fail;spin_unlock (&platform_bus_type.p->klist_drivers.k_lock);
include/linux/device.h +7 -9
@@ -32,6 +32,7 @@struct device ;struct device_driver ; +struct driver_private ;struct class ;struct class_device ;struct bus_type ;
@@ -113,16 +114,11 @@ extern struct kset *bus_get_kset(struct bus_type *bus);extern struct klist *bus_get_device_klist (struct bus_type *bus);struct device_driver { -const char * name; -struct bus_type * bus; - -struct kobject kobj; -struct klist klist_devices; -struct klist_node knode_bus; +const char *name; +struct bus_type *bus; -struct module * owner; -const char * mod_name;/* used for built-in modules */ -struct module_kobject * mkobj; +struct module *owner; +const char *mod_name;/* used for built-in modules */ int (*probe) (struct device * dev);int (*remove) (struct device * dev);
@@ -130,6 +126,8 @@ struct device_driver {int (*suspend) (struct device * dev,pm_message_t state);int (*resume) (struct device * dev);struct attribute_group **groups; + +struct driver_private *p; };
Signature · 1 line
1.5.3.8
PATCH 152/196 Driver core: clean up debugging messages
In reply to Greg KHThe driver core debugging messages are a mess. This provides a unified message that makes them actually useful.
The format for new kobject debug messages should be:
driver/bus/class: 'OBJECT_NAME': FUNCTION_NAME: message.\n
Note, the class code is not changed in this patch due to pending patches in my queue that this would conflict with. A later patch will clean them up.
--- drivers/base/bus.c | 14 +++++++------- drivers/base/core.c | 23 +++++++++++++---------- drivers/base/dd.c | 16 ++++++++-------- 3 files changed, 28 insertions(+), 25 deletions(-)
drivers/base/bus.c +7 -7
@@ -80,7 +80,7 @@ static void driver_release(struct kobject *kobj) {struct driver_private *drv_priv =to_driver (kobj); -pr_debug ("%s: freeing %s\n" , __FUNCTION__,kobject_name (kobj)); +pr_debug ("driver: '%s': %s\n" ,kobject_name (kobj), __FUNCTION__);kfree (drv_priv); }
@@ -446,7 +446,7 @@ int bus_add_device(struct device * dev)int error =0 ;if (bus) { -pr_debug ("bus %s: add device %s\n" , bus->name, dev->bus_id); +pr_debug ("bus: '%s': add device %s\n" , bus->name, dev->bus_id); error =device_add_attrs (bus, dev);if (error) goto out_put;
@@ -519,7 +519,7 @@ void bus_remove_device(struct device * dev) dev->is_registered =0 ;klist_del (&dev->knode_bus); } -pr_debug ("bus %s: remove device %s\n" , dev->bus->name, dev->bus_id); +pr_debug ("bus: '%s': remove device %s\n" , dev->bus->name, dev->bus_id);device_release_driver (dev);bus_put (dev->bus); }
@@ -637,7 +637,7 @@ int bus_add_driver(struct device_driver *drv)if (!bus)return -EINVAL ; -pr_debug ("bus %s: add driver %s\n" , bus->name, drv->name); +pr_debug ("bus: '%s': add driver %s\n" , bus->name, drv->name); priv =kzalloc (sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -707,7 +707,7 @@ void bus_remove_driver(struct device_driver * drv)driver_remove_attrs (drv->bus, drv);driver_remove_file (drv, &driver_attr_uevent);klist_remove (&drv->p->knode_bus); -pr_debug ("bus %s: remove driver %s\n" , drv->bus->name, drv->name); +pr_debug ("bus: '%s': remove driver %s\n" , drv->bus->name, drv->name);driver_detach (drv);module_remove_driver (drv);kobject_unregister (&drv->p->kobj);
@@ -907,7 +907,7 @@ int bus_register(struct bus_type * bus)if (retval) goto bus_attrs_fail; -pr_debug ("bus type '%s' registered\n" , bus->name); +pr_debug ("bus: '%s': registered\n" , bus->name);return 0 ; bus_attrs_fail:
@@ -934,7 +934,7 @@ out:*/ void bus_unregister (struct bus_type * bus) { -pr_debug ("bus %s: unregistering\n" , bus->name); +pr_debug ("bus: '%s': unregistering\n" , bus->name);bus_remove_attrs (bus);remove_probe_files (bus);kset_unregister (bus->p->drivers_kset);
drivers/base/core.c +13 -10
@@ -193,15 +193,16 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,if (dev->bus && dev->bus->uevent) { retval = dev->bus->uevent (dev, env);if (retval) -pr_debug ("%s: bus uevent() returned %d\n" , - __FUNCTION__, retval); +pr_debug ("device: '%s': %s: bus uevent() returned %d\n" , + dev->bus_id, __FUNCTION__, retval); }/* have the class specific function add its stuff */ if (dev->class && dev->class->dev_uevent) { retval = dev->class->dev_uevent (dev, env);if (retval) -pr_debug ("%s: class uevent() returned %d\n" , +pr_debug ("device: '%s': %s: class uevent() " +"returned %d\n" , dev->bus_id, __FUNCTION__, retval); }
@@ -209,7 +210,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,if (dev->type && dev->type->uevent) { retval = dev->type->uevent (dev, env);if (retval) -pr_debug ("%s: dev_type uevent() returned %d\n" , +pr_debug ("device: '%s': %s: dev_type uevent() " +"returned %d\n" , dev->bus_id, __FUNCTION__, retval); }
@@ -751,7 +753,7 @@ int device_add(struct device *dev) goto Error; } -pr_debug ("DEV: registering device: ID = '%s'\n" , dev->bus_id); +pr_debug ("device: '%s': %s\n" , dev->bus_id, __FUNCTION__); parent =get_device (dev->parent); error =setup_parent (dev, parent);
@@ -1020,7 +1022,7 @@ void device_del(struct device * dev)*/ void device_unregister (struct device * dev) { -pr_debug ("DEV: Unregistering device. ID = '%s'\n" , dev->bus_id); +pr_debug ("device: '%s': %s\n" , dev->bus_id, __FUNCTION__);device_del (dev);put_device (dev); }
@@ -1116,7 +1118,7 @@ EXPORT_SYMBOL_GPL(device_remove_file);static void device_create_release (struct device *dev) { -pr_debug ("%s called for %s\n" , __FUNCTION__, dev->bus_id); +pr_debug ("device: '%s': %s\n" , dev->bus_id, __FUNCTION__);kfree (dev); }
@@ -1259,7 +1261,8 @@ int device_rename(struct device *dev, char *new_name)if (!dev)return -EINVAL ; -pr_debug ("DEVICE: renaming '%s' to '%s'\n" , dev->bus_id, new_name); +pr_debug ("device: '%s': %s: renaming to '%s'\n" , dev->bus_id, + __FUNCTION__, new_name);#ifdef CONFIG_SYSFS_DEPRECATED if ((dev->class) && (dev->parent))
@@ -1378,8 +1381,8 @@ int device_move(struct device *dev, struct device *new_parent)put_device (new_parent); goto out; } -pr_debug ("DEVICE: moving '%s' to '%s'\n" , dev->bus_id, - new_parent ? new_parent->bus_id :"<NULL>" ); +pr_debug ("device: '%s': %s: moving to '%s'\n" , dev->bus_id, + __FUNCTION__, new_parent ? new_parent->bus_id :"<NULL>" ); error =kobject_move (&dev->kobj, new_parent_kobj);if (error) {put_device (new_parent);
drivers/base/dd.c +8 -8
@@ -34,8 +34,8 @@ static void driver_bound(struct device *dev)return ; } -pr_debug ("bound device '%s' to driver '%s'\n" , - dev->bus_id, dev->driver->name); +pr_debug ("driver: '%s': %s: bound to device '%s'\n" , dev->bus_id, + __FUNCTION__, dev->driver->name);if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -102,8 +102,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)int ret =0 ;atomic_inc (&probe_count); -pr_debug ("%s: Probing driver %s with device %s\n" , - drv->bus->name, drv->name, dev->bus_id); +pr_debug ("bus: '%s': %s: probing driver %s with device %s\n" , + drv->bus->name, __FUNCTION__, drv->name, dev->bus_id);WARN_ON (!list_empty (&dev->devres_head)); dev->driver = drv;
@@ -125,8 +125,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)driver_bound (dev); ret =1 ; -pr_debug ("%s: Bound Device %s to Driver %s\n" , - drv->bus->name, dev->bus_id, drv->name); +pr_debug ("bus: '%s': %s: bound device %s to driver %s\n" , + drv->bus->name, __FUNCTION__, dev->bus_id, drv->name); goto done; probe_failed:
@@ -192,8 +192,8 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)if (drv->bus->match && !drv->bus->match (dev, drv)) goto done; -pr_debug ("%s: Matched Device %s with Driver %s\n" , - drv->bus->name, dev->bus_id, drv->name); +pr_debug ("bus: '%s': %s: matched device %s with driver %s\n" , + drv->bus->name, __FUNCTION__, dev->bus_id, drv->name); ret =really_probe (dev, drv);
Signature · 1 line
1.5.3.8
PATCH 153/196 Kobject: change drivers/base/bus to use kobject_init_and_add
In reply to Greg KHStop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized.
--- drivers/base/bus.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)
drivers/base/bus.c +4 -6
@@ -643,15 +643,12 @@ int bus_add_driver(struct device_driver *drv)if (!priv)return -ENOMEM ; - error =kobject_set_name (&priv->kobj,"%s" , drv->name); -if (error) - goto out_put_bus; - priv->kobj.kset = bus->p->drivers_kset; - priv->kobj.ktype = &driver_ktype;klist_init (&priv->klist_devices,NULL ,NULL ); priv->driver = drv; drv->p = priv; - error =kobject_register (&priv->kobj); + priv->kobj.kset = bus->p->drivers_kset; + error =kobject_init_and_add (&priv->kobj, &driver_ktype,NULL , +"%s" , drv->name);if (error) goto out_put_bus;
@@ -681,6 +678,7 @@ int bus_add_driver(struct device_driver *drv) __FUNCTION__, drv->name); } +kobject_uevent (&priv->kobj,KOBJ_ADD );return error; out_unregister:kobject_unregister (&priv->kobj);
Signature · 1 line
1.5.3.8
PATCH 154/196 Driver core: fix race in __device_release_driver
In reply to Greg KHFrom: Alan Stern <[email protected]>
This patch (as1013) was suggested by David Woodhouse; it fixes a race in the driver core. If a device is unregistered at the same time as its driver is unloaded, the driver's code pages may be unmapped while the remove method is still running. The calls to get_driver() and put_driver() were intended to prevent this, but they don't work if the driver's module count has already dropped to 0.
Instead, the patch keeps the device on the driver's list until after the remove method has returned. This forces the necessary synchronization to occur.
--- drivers/base/dd.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/base/dd.c +2 -3
@@ -289,11 +289,10 @@ static void __device_release_driver(struct device * dev) {struct device_driver * drv; - drv =get_driver (dev->driver); + drv = dev->driver;if (drv) {driver_sysfs_remove (dev);sysfs_remove_link (&dev->kobj,"driver" ); -klist_remove (&dev->knode_driver);if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -306,7 +305,7 @@ static void __device_release_driver(struct device * dev) drv->remove (dev);devres_release_all (dev); dev->driver =NULL ; -put_driver (drv); +klist_remove (&dev->knode_driver); } }
Signature · 1 line
1.5.3.8
PATCH 155/196 Driver core: fix class glue dir cleanup logic
In reply to Greg KHFrom: Kay Sievers <[email protected]>
We should remove the glue directory between the class and the bus device _after_ we sent out the 'remove' event for the device, otherwise the parent relationship is no longer valid, and composing the path with deleted sysfs entries will not work.
--- drivers/base/core.c | 206 +++++++++++++++++++++++---------------------------- 1 files changed, 94 insertions(+), 112 deletions(-)
drivers/base/core.c +94 -112
@@ -18,7 +18,7 @@#include <linux/string.h> #include <linux/kdev_t.h> #include <linux/notifier.h> - +#include <linux/genhd.h> #include <asm/semaphore.h> #include "base.h"
@@ -538,22 +538,20 @@ void device_initialize(struct device *dev) }#ifdef CONFIG_SYSFS_DEPRECATED -static struct kobject *get_device_parent (struct device *dev, -struct device *parent) +static struct kobject *get_device_parent (struct device *dev, +struct device *parent) { -/* -* Set the parent to the class, not the parent device -* for topmost devices in class hierarchy. -* This keeps sysfs from having a symlink to make old -* udevs happy -*/ +/* class devices without a parent live in /sys/class/<classname>/ */ if (dev->class && (!parent || parent->class != dev->class))return &dev->class->subsys.kobj; +/* all other devices keep their parent */ else if (parent)return &parent->kobj;return NULL ; } + +static inline void cleanup_device_parent (struct device *dev) {}#else static struct kobject *virtual_device_parent (struct device *dev) {
@@ -566,8 +564,8 @@ static struct kobject *virtual_device_parent(struct device *dev)return virtual_dir; } -static struct kobject *get_device_parent (struct device *dev, -struct device *parent) +static struct kobject *get_device_parent (struct device *dev, +struct device *parent) {int retval;
@@ -618,6 +616,34 @@ static struct kobject * get_device_parent(struct device *dev,return &parent->kobj;return NULL ; } + +static void cleanup_device_parent (struct device *dev) +{ +struct device *d; +int other =0 ; + +if (!dev->class) +return ; + +/* see if we live in a parent class directory */ +if (dev->kobj.parent->kset != &dev->class->class_dirs) +return ; + +/* if we are the last child of our class, delete the directory */ +down (&dev->class->sem); +list_for_each_entry (d, &dev->class->devices, node) { +if (d == dev) +continue ; +if (d->kobj.parent == dev->kobj.parent) { + other =1 ; +break ; + } + } +if (!other) +kobject_del (dev->kobj.parent); +kobject_put (dev->kobj.parent); +up (&dev->class->sem); +}#endif static int setup_parent (struct device *dev,struct device *parent)
@@ -637,65 +663,74 @@ static int device_add_class_symlinks(struct device *dev)if (!dev->class)return 0 ; + error =sysfs_create_link (&dev->kobj, &dev->class->subsys.kobj,"subsystem" );if (error) goto out; -/* -* If this is not a "fake" compatible device, then create the -* symlink from the class to the device. -*/ + +#ifdef CONFIG_SYSFS_DEPRECATED +/* stacked class devices need a symlink in the class directory */ if (dev->kobj.parent != &dev->class->subsys.kobj) { error =sysfs_create_link (&dev->class->subsys.kobj, &dev->kobj, dev->bus_id);if (error) goto out_subsys; } +if (dev->parent) { -#ifdef CONFIG_SYSFS_DEPRECATED - { -struct device *parent = dev->parent; -char *class_name; - -/* -* In old sysfs stacked class devices had 'device' -* link pointing to real device instead of parent -*/ -while (parent->class && !parent->bus && parent->parent) - parent = parent->parent; - - error =sysfs_create_link (&dev->kobj, - &parent->kobj, -"device" ); -if (error) - goto out_busid; +struct device *parent = dev->parent; +char *class_name; - class_name =make_class_name (dev->class->name, - &dev->kobj); -if (class_name) - error =sysfs_create_link (&dev->parent->kobj, - &dev->kobj, class_name); -kfree (class_name); -if (error) - goto out_device; - } -#else - error =sysfs_create_link (&dev->kobj, &dev->parent->kobj, +/* +* stacked class devices have the 'device' link +* pointing to the bus device instead of the parent +*/ +while (parent->class && !parent->bus && parent->parent) + parent = parent->parent; + + error =sysfs_create_link (&dev->kobj, + &parent->kobj,"device" );if (error) goto out_busid; -#endif + + class_name =make_class_name (dev->class->name, + &dev->kobj); +if (class_name) + error =sysfs_create_link (&dev->parent->kobj, + &dev->kobj, class_name); +kfree (class_name); +if (error) + goto out_device; }return 0 ; -#ifdef CONFIG_SYSFS_DEPRECATED out_device:if (dev->parent)sysfs_remove_link (&dev->kobj,"device" ); -#endif out_busid:if (dev->kobj.parent != &dev->class->subsys.kobj)sysfs_remove_link (&dev->class->subsys.kobj, dev->bus_id); +#else +/* link in the class directory pointing to the device */ + error =sysfs_create_link (&dev->class->subsys.kobj, &dev->kobj, + dev->bus_id); +if (error) + goto out_subsys; + +if (dev->parent) { + error =sysfs_create_link (&dev->kobj, &dev->parent->kobj, +"device" ); +if (error) + goto out_busid; + } +return 0 ; + +out_busid: +sysfs_remove_link (&dev->class->subsys.kobj, dev->bus_id); +#endif + out_subsys:sysfs_remove_link (&dev->kobj,"subsystem" ); out:
@@ -706,8 +741,9 @@ static void device_remove_class_symlinks(struct device *dev) {if (!dev->class)return ; -if (dev->parent) { +#ifdef CONFIG_SYSFS_DEPRECATED +if (dev->parent) {char *class_name; class_name =make_class_name (dev->class->name, &dev->kobj);
@@ -715,11 +751,18 @@ static void device_remove_class_symlinks(struct device *dev)sysfs_remove_link (&dev->parent->kobj, class_name); kfree(class_name); } -#endif sysfs_remove_link (&dev->kobj,"device" ); } +if (dev->kobj.parent != &dev->class->subsys.kobj)sysfs_remove_link (&dev->class->subsys.kobj, dev->bus_id); +#else +if (dev->parent) +sysfs_remove_link (&dev->kobj,"device" ); + +sysfs_remove_link (&dev->class->subsys.kobj, dev->bus_id); +#endif +sysfs_remove_link (&dev->kobj,"subsystem" ); }
@@ -830,26 +873,6 @@ int device_add(struct device *dev) SymlinkError:if (MAJOR (dev->devt))device_remove_file (dev, &devt_attr); - -if (dev->class) { -sysfs_remove_link (&dev->kobj,"subsystem" ); -/* If this is not a "fake" compatible device, remove the -* symlink from the class to the device. */ -if (dev->kobj.parent != &dev->class->subsys.kobj) -sysfs_remove_link (&dev->class->subsys.kobj, - dev->bus_id); -if (parent) { -#ifdef CONFIG_SYSFS_DEPRECATED -char *class_name =make_class_name (dev->class->name, - &dev->kobj); -if (class_name) -sysfs_remove_link (&dev->parent->kobj, - class_name); -kfree (class_name); -#endif -sysfs_remove_link (&dev->kobj,"device" ); - } - } ueventattrError:device_remove_file (dev, &uevent_attr); attrError:
@@ -932,23 +955,7 @@ void device_del(struct device * dev)if (MAJOR (dev->devt))device_remove_file (dev, &devt_attr);if (dev->class) { -sysfs_remove_link (&dev->kobj,"subsystem" ); -/* If this is not a "fake" compatible device, remove the -* symlink from the class to the device. */ -if (dev->kobj.parent != &dev->class->subsys.kobj) -sysfs_remove_link (&dev->class->subsys.kobj, - dev->bus_id); -if (parent) { -#ifdef CONFIG_SYSFS_DEPRECATED -char *class_name =make_class_name (dev->class->name, - &dev->kobj); -if (class_name) -sysfs_remove_link (&dev->parent->kobj, - class_name); -kfree (class_name); -#endif -sysfs_remove_link (&dev->kobj,"device" ); - } +device_remove_class_symlinks (dev);down (&dev->class->sem);/* notify any interfaces that the device is now gone */
@@ -958,31 +965,6 @@ void device_del(struct device * dev)/* remove the device from the class list */ list_del_init (&dev->node);up (&dev->class->sem); - -/* If we live in a parent class-directory, unreference it */ -if (dev->kobj.parent->kset == &dev->class->class_dirs) { -struct device *d; -int other =0 ; - -/* -* if we are the last child of our class, delete -* our class-directory at this parent -*/ -down (&dev->class->sem); -list_for_each_entry (d, &dev->class->devices, node) { -if (d == dev) -continue ; -if (d->kobj.parent == dev->kobj.parent) { - other =1 ; -break ; - } - } -if (!other) -kobject_del (dev->kobj.parent); - -kobject_put (dev->kobj.parent); -up (&dev->class->sem); - } }device_remove_file (dev, &uevent_attr);device_remove_attrs (dev);
@@ -1004,9 +986,9 @@ void device_del(struct device * dev)blocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_DEL_DEVICE , dev);kobject_uevent (&dev->kobj,KOBJ_REMOVE ); +cleanup_device_parent (dev);kobject_del (&dev->kobj); -if (parent) -put_device (parent); +put_device (parent); }/**
Signature · 1 line
1.5.3.8
PATCH 156/196 sysfs: fix /sys/module/*/holders after sysfs logic change
In reply to Greg KHFrom: Kay Sievers <[email protected]>
Sysfs symlinks now require fully registered kobjects as a target, otherwise the call to create a symlink will fail. Here we register the kobject before we request the symlink in the holders directory.
--- kernel/module.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
kernel/module.c +7 -8
@@ -1227,6 +1227,8 @@ int mod_sysfs_init(struct module *mod)kobject_init (&mod->mkobj.kobj); +/* delay uevent until full sysfs population */ + err =kobject_add (&mod->mkobj.kobj); out:return err; }
@@ -1237,11 +1239,6 @@ int mod_sysfs_setup(struct module *mod, {int err; -/* delay uevent until full sysfs population */ - err =kobject_add (&mod->mkobj.kobj); -if (err) - goto out; - mod->holders_dir =kobject_create_and_add ("holders" , &mod->mkobj.kobj);if (!mod->holders_dir) { err = -ENOMEM ;
@@ -1266,7 +1263,6 @@ out_unreg_holders: out_unreg:kobject_del (&mod->mkobj.kobj);kobject_put (&mod->mkobj.kobj); -out: return err; }#endif
@@ -1883,10 +1879,10 @@ static struct module *load_module(void __user *umod,/* Now we've moved module, initialize linked lists, etc. */ module_unload_init (mod); -/* Initialize kobject, so we can reference it. */ +/* add kobject, so we can reference it. */ err =mod_sysfs_init (mod);if (err) - goto cleanup; + goto free_unload;/* Set up license info based on the info section */ set_license (mod,get_modinfo (sechdrs, infoindex,"license" ));
@@ -2056,6 +2052,9 @@ static struct module *load_module(void __user *umod, arch_cleanup:module_arch_cleanup (mod); cleanup: +kobject_del (&mod->mkobj.kobj); +kobject_put (&mod->mkobj.kobj); + free_unload:module_unload_free (mod);module_free (mod, mod->module_init); free_core:
Signature · 1 line
1.5.3.8
PATCH 157/196 Kobject: drop child->parent ref at unregistration
In reply to Greg KHFrom: Alan Stern <[email protected]>
This patch (as1015) reverts changes that were made to the driver core about four years ago. The intent back then was to avoid certain kinds of invalid memory accesses by leaving kernel objects allocated as long as any of their children were still allocated. The original and correct approach was to wait only as long as any children were still _registered_; that's what this patch reinstates.
This fixes a problem in the SCSI core made visible by the class_device to regular device conversion: A reference loop (scsi_device holds reference to request_queue, which is the child of a gendisk, which is the child of the scsi_device) prevents the data structures from being released, even though they are deregistered okay.
It's possible that this change will cause a few bugs to surface, things that have been hidden for several years. They can be fixed easily enough by having the child device take an explicit reference to the parent whenever needed.
--- lib/kobject.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
lib/kobject.c +4 -3
@@ -149,12 +149,16 @@ void kobject_init(struct kobject * kobj)static void unlink (struct kobject * kobj) { +struct kobject *parent = kobj->parent; +if (kobj->kset) {spin_lock (&kobj->kset->list_lock);list_del_init (&kobj->entry);spin_unlock (&kobj->kset->list_lock); } + kobj->parent =NULL ;kobject_put (kobj); +kobject_put (parent); }/**
@@ -208,7 +212,6 @@ int kobject_add(struct kobject * kobj)if (error) {/* unlink does the kobject_put() for us */ unlink (kobj); -kobject_put (parent);/* be noisy on error issues */ if (error == -EEXIST )
@@ -590,7 +593,6 @@ static void kobject_cleanup(struct kobject *kobj) {struct kobj_type * t =get_ktype (kobj);struct kset * s = kobj->kset; -struct kobject * parent = kobj->parent;const char *name = kobj->k_name; pr_debug("kobject: '%s' (%p): %s\n",
@@ -604,7 +606,6 @@ static void kobject_cleanup(struct kobject *kobj) }if (s)kset_put (s); -kobject_put (parent); }static void kobject_release (struct kref *kref)
Signature · 1 line
1.5.3.8
PATCH 158/196 Driver core: convert block from raw kobjects to core devices
In reply to Greg KHFrom: Kay Sievers <[email protected]>
This moves the block devices to /sys/class/block. It will create a flat list of all block devices, with the disks and partitions in one directory. For compatibility /sys/block is created and contains symlinks to the disks.
/sys/class/block
|-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1 |-- sda10 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10 |-- sda5 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5 |-- sda6 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6 |-- sda7 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7 |-- sda8 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8 |-- sda9 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9
`-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
/sys/block/
|-- sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda `-- sr0 -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
--- block/genhd.c | 416 +++++++++++++++++++------------------------- block/ll_rw_blk.c | 4 +- drivers/base/class.c | 7 + drivers/base/core.c | 20 ++- drivers/block/aoe/aoeblk.c | 51 +++--- drivers/block/nbd.c | 15 +- drivers/ide/ide-probe.c | 2 +- drivers/md/dm.c | 4 +- drivers/md/md.c | 8 +- fs/block_dev.c | 8 +- fs/partitions/check.c | 315 +++++++++++---------------------- include/linux/genhd.h | 37 +++-- init/do_mounts.c | 108 +----------- 13 files changed, 385 insertions(+), 610 deletions(-)
block/genhd.c +183 -233
@@ -17,9 +17,10 @@#include <linux/buffer_head.h> #include <linux/mutex.h> -struct kset *block_kset; -static struct kset_uevent_ops block_uevent_ops; -static DEFINE_MUTEX (block_subsys_lock); +static DEFINE_MUTEX (block_class_lock); +#ifndef CONFIG_SYSFS_DEPRECATED +struct kobject *block_depr; +#endif /* * Can be deleted altogether. Later.
@@ -38,19 +39,17 @@ static inline int major_to_index(int major) }#ifdef CONFIG_PROC_FS -void blkdev_show (struct seq_file *f,off_t offset) {struct blk_major_name *dp;if (offset <BLKDEV_MAJOR_HASH_SIZE ) { -mutex_lock (&block_subsys_lock); +mutex_lock (&block_class_lock);for (dp = major_names[offset]; dp; dp = dp->next)seq_printf (f,"%3d %s\n" , dp->major, dp->name); -mutex_unlock (&block_subsys_lock); +mutex_unlock (&block_class_lock); } } -#endif /* CONFIG_PROC_FS */ int register_blkdev (unsigned int major,const char *name)
@@ -58,7 +57,7 @@ int register_blkdev(unsigned int major, const char *name)struct blk_major_name **n, *p;int index, ret =0 ; -mutex_lock (&block_subsys_lock); +mutex_lock (&block_class_lock);/* temporary */ if (major ==0 ) {
@@ -103,7 +102,7 @@ int register_blkdev(unsigned int major, const char *name)kfree (p); } out: -mutex_unlock (&block_subsys_lock); +mutex_unlock (&block_class_lock);return ret; }
@@ -115,7 +114,7 @@ void unregister_blkdev(unsigned int major, const char *name)struct blk_major_name *p =NULL ;int index =major_to_index (major); -mutex_lock (&block_subsys_lock); +mutex_lock (&block_class_lock);for (n = &major_names[index]; *n; n = &(*n)->next)if ((*n)->major == major)break ;
@@ -125,7 +124,7 @@ void unregister_blkdev(unsigned int major, const char *name) p = *n; *n = p->next; } -mutex_unlock (&block_subsys_lock); +mutex_unlock (&block_class_lock);kfree (p); }
@@ -138,29 +137,30 @@ static struct kobj_map *bdev_map;* range must be nonzero * The hash chain is sorted on range, so that subranges can override. */ -void blk_register_region (dev_t dev,unsigned long range,struct module *module, +void blk_register_region (dev_t devt,unsigned long range,struct module *module,struct kobject *(*probe)(dev_t ,int *,void *),int (*lock)(dev_t ,void *),void *data) { -kobj_map (bdev_map, dev, range, module, probe, lock, data); +kobj_map (bdev_map, devt, range, module, probe, lock, data); }EXPORT_SYMBOL (blk_register_region); -void blk_unregister_region (dev_t dev,unsigned long range) +void blk_unregister_region (dev_t devt,unsigned long range) { -kobj_unmap (bdev_map, dev, range); +kobj_unmap (bdev_map, devt, range); }EXPORT_SYMBOL (blk_unregister_region); -static struct kobject *exact_match (dev_t dev,int *part,void *data) +static struct kobject *exact_match (dev_t devt,int *part,void *data) {struct gendisk *p = data; -return &p->kobj; + +return &p->dev.kobj; } -static int exact_lock (dev_t dev,void *data) +static int exact_lock (dev_t devt,void *data) {struct gendisk *p = data;
@@ -195,8 +195,6 @@ void unlink_gendisk(struct gendisk *disk) disk->minors); } -#define to_disk (obj) container_of(obj,struct gendisk,kobj) -/** * get_gendisk - get partitioning information for a given device * @dev: device to get partitioning information for
@@ -204,10 +202,12 @@ void unlink_gendisk(struct gendisk *disk)* This function gets the structure containing partitioning * information for the given device @dev. */ -struct gendisk *get_gendisk (dev_t dev,int *part) +struct gendisk *get_gendisk (dev_t devt,int *part) { -struct kobject *kobj =kobj_lookup (bdev_map, dev, part); -return kobj ?to_disk (kobj) :NULL ; +struct kobject *kobj =kobj_lookup (bdev_map, devt, part); +struct device *dev =kobj_to_dev (kobj); + +return kobj ?dev_to_disk (dev) :NULL ; }/*
@@ -217,13 +217,17 @@ struct gendisk *get_gendisk(dev_t dev, int *part)*/ void __init printk_all_partitions (void ) { -int n; +struct device *dev;struct gendisk *sgp; +char buf[BDEVNAME_SIZE ]; +int n; -mutex_lock (&block_subsys_lock); +mutex_lock (&block_class_lock);/* For each block device... */ -list_for_each_entry (sgp, &block_kset->list, kobj.entry) { -char buf[BDEVNAME_SIZE ]; +list_for_each_entry (dev, &block_class.devices, node) { +if (dev->type != &disk_type) +continue ; + sgp =dev_to_disk (dev);/* * Don't show empty devices or things that have been surpressed */
@@ -256,38 +260,46 @@ void __init printk_all_partitions(void) sgp->major, n +1 + sgp->first_minor, (unsigned long long )sgp->part[n]->nr_sects >>1 , disk_name(sgp, n + 1, buf)); - }/* partition subloop */ - }/* Block device loop */ + } + } -mutex_unlock (&block_subsys_lock); -return ; +mutex_unlock (&block_class_lock); }#ifdef CONFIG_PROC_FS /* iterator */ static void *part_start (struct seq_file *part,loff_t *pos) { -struct list_head *p; -loff_t l = *pos; +loff_t k = *pos; +struct device *dev; -mutex_lock (&block_subsys_lock); -list_for_each (p, &block_kset->list) -if (!l--) - return list_entry(p, struct gendisk, kobj.entry); +mutex_lock (&block_class_lock); +list_for_each_entry (dev, &block_class.devices, node) { +if (dev->type != &disk_type) +continue ; +if (!k--) +return dev_to_disk (dev); + }return NULL ; }static void *part_next (struct seq_file *part,void *v,loff_t *pos) { -struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; +struct gendisk *gp = v; +struct device *dev; ++*pos; -return p==&block_kset->list ?NULL : - list_entry(p, struct gendisk, kobj.entry); +list_for_each_entry (dev, &gp->dev.node, node) { +if (&dev->node == &block_class.devices) +return NULL ; +if (dev->type == &disk_type) +return dev_to_disk (dev); + } +return NULL ; }static void part_stop (struct seq_file *part,void *v) { -mutex_unlock (&block_subsys_lock); +mutex_unlock (&block_class_lock); }static int show_partition (struct seq_file *part,void *v)
@@ -296,7 +308,7 @@ static int show_partition(struct seq_file *part, void *v)int n;char buf[BDEVNAME_SIZE ]; -if (&sgp->kobj.entry == block_kset->list.next) +if (&sgp->dev.node == block_class.devices.next)seq_puts (part,"major minor #blocks name\n\n" );/* Don't show non-partitionable removeable devices or empty devices */
@@ -326,109 +338,81 @@ static int show_partition(struct seq_file *part, void *v) }struct seq_operations partitions_op = { - .start =part_start, - .next = part_next, - .stop = part_stop, - .show = show_partition + .start = part_start, + .next = part_next, + .stop = part_stop, + .show = show_partition };#endif extern int blk_dev_init (void ); -static struct kobject *base_probe (dev_t dev,int *part,void *data) +static struct kobject *base_probe (dev_t devt,int *part,void *data) { -if (request_module ("block-major-%d-%d" ,MAJOR (dev),MINOR (dev)) >0 ) +if (request_module ("block-major-%d-%d" ,MAJOR (devt),MINOR (devt)) >0 )/* Make old-style 2.4 aliases work */ -request_module ("block-major-%d" ,MAJOR (dev)); +request_module ("block-major-%d" ,MAJOR (devt));return NULL ; }static int __init genhd_device_init (void ) { - bdev_map =kobj_map_init (base_probe, &block_subsys_lock); +class_register (&block_class); + bdev_map =kobj_map_init (base_probe, &block_class_lock);blk_dev_init (); - block_kset =kset_create_and_add ("block" , &block_uevent_ops,NULL ); -if (!block_kset) { -printk (KERN_WARNING "%s: kset_create error\n" , __FUNCTION__); -return -ENOMEM ; - } + +#ifndef CONFIG_SYSFS_DEPRECATED +/* create top-level block dir */ + block_depr =kobject_create_and_add ("block" ,NULL ); +#endif return 0 ; }subsys_initcall (genhd_device_init); - - -/* -* kobject & sysfs bindings for block devices -*/ -static ssize_t disk_attr_show (struct kobject *kobj,struct attribute *attr, -char *page) +static ssize_t disk_range_show (struct device *dev, +struct device_attribute *attr,char *buf) { -struct gendisk *disk =to_disk (kobj); -struct disk_attribute *disk_attr = - container_of(attr,struct disk_attribute,attr); -ssize_t ret = -EIO ; +struct gendisk *disk =dev_to_disk (dev); -if (disk_attr->show) - ret = disk_attr->show (disk,page); -return ret; +return sprintf (buf,"%d\n" , disk->minors); } -static ssize_t disk_attr_store (struct kobject * kobj,struct attribute * attr, -const char *page,size_t count) +static ssize_t disk_removable_show (struct device *dev, +struct device_attribute *attr,char *buf) { -struct gendisk *disk =to_disk (kobj); -struct disk_attribute *disk_attr = - container_of(attr,struct disk_attribute,attr); -ssize_t ret =0 ; +struct gendisk *disk =dev_to_disk (dev); -if (disk_attr->store) - ret = disk_attr->store (disk, page, count); -return ret; +return sprintf (buf,"%d\n" , + (disk->flags &GENHD_FL_REMOVABLE ?1 :0 )); } -static struct sysfs_ops disk_sysfs_ops = { - .show = &disk_attr_show, - .store = &disk_attr_store, -}; - -static ssize_t disk_uevent_store (struct gendisk * disk, -const char *buf,size_t count) +static ssize_t disk_size_show (struct device *dev, +struct device_attribute *attr,char *buf) { -kobject_uevent (&disk->kobj,KOBJ_ADD ); -return count; -} -static ssize_t disk_dev_read (struct gendisk * disk,char *page) -{ -dev_t base =MKDEV (disk->major, disk->first_minor); -return print_dev_t (page, base); -} -static ssize_t disk_range_read (struct gendisk * disk,char *page) -{ -return sprintf (page,"%d\n" , disk->minors); -} -static ssize_t disk_removable_read (struct gendisk * disk,char *page) -{ -return sprintf (page,"%d\n" , - (disk->flags &GENHD_FL_REMOVABLE ?1 :0 )); +struct gendisk *disk =dev_to_disk (dev); +return sprintf (buf,"%llu\n" , (unsigned long long )get_capacity (disk)); } -static ssize_t disk_size_read (struct gendisk * disk,char *page) -{ -return sprintf (page,"%llu\n" , (unsigned long long )get_capacity (disk)); -} -static ssize_t disk_capability_read (struct gendisk *disk,char *page) + +static ssize_t disk_capability_show (struct device *dev, +struct device_attribute *attr,char *buf) { -return sprintf (page,"%x\n" , disk->flags); +struct gendisk *disk =dev_to_disk (dev); + +return sprintf (buf,"%x\n" , disk->flags); } -static ssize_t disk_stats_read (struct gendisk * disk,char *page) + +static ssize_t disk_stat_show (struct device *dev, +struct device_attribute *attr,char *buf) { +struct gendisk *disk =dev_to_disk (dev); +preempt_disable ();disk_round_stats (disk);preempt_enable (); -return sprintf (page, +return sprintf (buf,"%8lu %8lu %8llu %8u " "%8lu %8lu %8llu %8u " "%8u %8u %8u"
@@ -445,40 +429,21 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page)jiffies_to_msecs (disk_stat_read (disk, io_ticks)), jiffies_to_msecs(disk_stat_read(disk, time_in_queue))); } -static struct disk_attribute disk_attr_uevent = { - .attr = {.name ="uevent" , .mode =S_IWUSR }, - .store = disk_uevent_store -}; -static struct disk_attribute disk_attr_dev = { - .attr = {.name ="dev" , .mode =S_IRUGO }, - .show = disk_dev_read -}; -static struct disk_attribute disk_attr_range = { - .attr = {.name ="range" , .mode =S_IRUGO }, - .show = disk_range_read -}; -static struct disk_attribute disk_attr_removable = { - .attr = {.name ="removable" , .mode =S_IRUGO }, - .show = disk_removable_read -}; -static struct disk_attribute disk_attr_size = { - .attr = {.name ="size" , .mode =S_IRUGO }, - .show = disk_size_read -}; -static struct disk_attribute disk_attr_capability = { - .attr = {.name ="capability" , .mode =S_IRUGO }, - .show = disk_capability_read -}; -static struct disk_attribute disk_attr_stat = { - .attr = {.name ="stat" , .mode =S_IRUGO }, - .show = disk_stats_read -};#ifdef CONFIG_FAIL_MAKE_REQUEST +static ssize_t disk_fail_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct gendisk *disk =dev_to_disk (dev); + +return sprintf (buf,"%d\n" , disk->flags &GENHD_FL_FAIL ?1 :0 ); +} -static ssize_t disk_fail_store (struct gendisk * disk, +static ssize_t disk_fail_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) { +struct gendisk *disk =dev_to_disk (dev);int i;if (count >0 &&sscanf (buf,"%d" , &i) >0 ) {
@@ -490,134 +455,100 @@ static ssize_t disk_fail_store(struct gendisk * disk,return count; } -static ssize_t disk_fail_read (struct gendisk * disk,char *page) -{ -return sprintf (page,"%d\n" , disk->flags &GENHD_FL_FAIL ?1 :0 ); -} -static struct disk_attribute disk_attr_fail = { - .attr = {.name ="make-it-fail" , .mode =S_IRUGO |S_IWUSR }, - .store = disk_fail_store, - .show = disk_fail_read -};#endif -static struct attribute * default_attrs[] = { - &disk_attr_uevent.attr, - &disk_attr_dev.attr, - &disk_attr_range.attr, - &disk_attr_removable.attr, - &disk_attr_size.attr, - &disk_attr_stat.attr, - &disk_attr_capability.attr, +static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); +static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); +static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL); +static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL); +static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL);#ifdef CONFIG_FAIL_MAKE_REQUEST - &disk_attr_fail.attr, +static struct device_attribute dev_attr_fail = +__ATTR (make-it-fail,S_IRUGO |S_IWUSR , disk_fail_show, disk_fail_store);#endif -NULL , + +static struct attribute *disk_attrs[] = { + &dev_attr_range.attr, + &dev_attr_removable.attr, + &dev_attr_size.attr, + &dev_attr_capability.attr, + &dev_attr_stat.attr, +#ifdef CONFIG_FAIL_MAKE_REQUEST + &dev_attr_fail.attr, +#endif +NULL +}; + +static struct attribute_group disk_attr_group = { + .attrs = disk_attrs, +}; + +static struct attribute_group *disk_attr_groups[] = { + &disk_attr_group, +NULL }; -static void disk_release (struct kobject * kobj) +static void disk_release (struct device *dev) { -struct gendisk *disk =to_disk (kobj); +struct gendisk *disk =dev_to_disk (dev); +kfree (disk->random);kfree (disk->part);free_disk_stats (disk);kfree (disk); } - -static struct kobj_type ktype_block = { - .release = disk_release, - .sysfs_ops = &disk_sysfs_ops, - .default_attrs = default_attrs, +struct class block_class = { + .name ="block" , }; -extern struct kobj_type ktype_part; - -static int block_uevent_filter (struct kset *kset,struct kobject *kobj) -{ -struct kobj_type *ktype =get_ktype (kobj); - -return ((ktype == &ktype_block) || (ktype == &ktype_part)); -} - -static int block_uevent (struct kset *kset,struct kobject *kobj, -struct kobj_uevent_env *env) -{ -struct kobj_type *ktype =get_ktype (kobj); -struct device *physdev; -struct gendisk *disk; -struct hd_struct *part; - -if (ktype == &ktype_block) { - disk = container_of(kobj, struct gendisk, kobj); -add_uevent_var (env,"MINOR=%u" , disk->first_minor); - }else if (ktype == &ktype_part) { - disk = container_of(kobj->parent, struct gendisk, kobj); - part = container_of(kobj, struct hd_struct, kobj); -add_uevent_var (env,"MINOR=%u" , - disk->first_minor + part->partno); - }else -return 0 ; - -add_uevent_var (env,"MAJOR=%u" , disk->major); - -/* add physical device, backing this device */ - physdev = disk->driverfs_dev; -if (physdev) { -char *path =kobject_get_path (&physdev->kobj,GFP_KERNEL ); - -add_uevent_var (env,"PHYSDEVPATH=%s" , path); -kfree (path); - -if (physdev->bus) -add_uevent_var (env,"PHYSDEVBUS=%s" , physdev->bus->name); - -if (physdev->driver) -add_uevent_var (env, physdev->driver->name); - } - -return 0 ; -} - -static struct kset_uevent_ops block_uevent_ops = { - .filter = block_uevent_filter, - .uevent = block_uevent, +struct device_type disk_type = { + .name ="disk" , + .groups = disk_attr_groups, + .release = disk_release, };/* * aggregate disk stat collector. Uses the same stats that the sysfs * entries do, above, but makes them available through one seq_file. -* Watching a few disks may be efficient through sysfs, but watching -* all of them will be more efficient through this interface. * * The output looks suspiciously like /proc/partitions with a bunch of * extra fields. */ -/* iterator */ static void *diskstats_start (struct seq_file *part,loff_t *pos) {loff_t k = *pos; -struct list_head *p; +struct device *dev; -mutex_lock (&block_subsys_lock); -list_for_each (p, &block_kset->list) +mutex_lock (&block_class_lock); +list_for_each_entry (dev, &block_class.devices, node) { +if (dev->type != &disk_type) +continue ;if (!k--) - return list_entry(p, struct gendisk, kobj.entry); +return dev_to_disk (dev); + }return NULL ; }static void *diskstats_next (struct seq_file *part,void *v,loff_t *pos) { -struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; +struct gendisk *gp = v; +struct device *dev; + ++*pos; -return p==&block_kset->list ?NULL : - list_entry(p, struct gendisk, kobj.entry); +list_for_each_entry (dev, &gp->dev.node, node) { +if (&dev->node == &block_class.devices) +return NULL ; +if (dev->type == &disk_type) +return dev_to_disk (dev); + } +return NULL ; }static void diskstats_stop (struct seq_file *part,void *v) { -mutex_unlock (&block_subsys_lock); +mutex_unlock (&block_class_lock); }static int diskstats_show (struct seq_file *s,void *v)
@@ -627,7 +558,7 @@ static int diskstats_show(struct seq_file *s, void *v)int n =0 ;/* -if (&sgp->kobj.entry == block_kset->list.next) +if (&gp->dev.kobj.entry == block_class.devices.next) seq_puts(s, "major minor name" " rio rmerge rsect ruse wio wmerge " "wsect wuse running use aveq"
@@ -681,7 +612,7 @@ static void media_change_notify_thread(struct work_struct *work)* set enviroment vars to indicate which event this is for * so that user space will know to go check the media status. */ -kobject_uevent_env (&gd->kobj,KOBJ_CHANGE , envp); +kobject_uevent_env (&gd->dev.kobj,KOBJ_CHANGE , envp);put_device (gd->driverfs_dev); }
@@ -692,6 +623,25 @@ void genhd_media_change_notify(struct gendisk *disk) }EXPORT_SYMBOL_GPL (genhd_media_change_notify); +dev_t blk_lookup_devt (const char *name) +{ +struct device *dev; +dev_t devt =MKDEV (0 ,0 ); + +mutex_lock (&block_class_lock); +list_for_each_entry (dev, &block_class.devices, node) { +if (strcmp (dev->bus_id, name) ==0 ) { + devt = dev->devt; +break ; + } + } +mutex_unlock (&block_class_lock); + +return devt; +} + +EXPORT_SYMBOL (blk_lookup_devt); +struct gendisk *alloc_disk (int minors) {return alloc_disk_node (minors,-1 );
@@ -719,10 +669,10 @@ struct gendisk *alloc_disk_node(int minors, int node_id) } } disk->minors = minors; - disk->kobj.kset = block_kset; - disk->kobj.ktype = &ktype_block; -kobject_init (&disk->kobj);rand_initialize_disk (disk); + disk->dev.class = &block_class; + disk->dev.type = &disk_type; +device_initialize (&disk->dev);INIT_WORK (&disk->async_notify, media_change_notify_thread); }
@@ -742,7 +692,7 @@ struct kobject *get_disk(struct gendisk *disk) owner = disk->fops->owner;if (owner && !try_module_get (owner))return NULL ; - kobj =kobject_get (&disk->kobj); + kobj =kobject_get (&disk->dev.kobj);if (kobj ==NULL ) {module_put (owner);return NULL ;
@@ -756,7 +706,7 @@ EXPORT_SYMBOL(get_disk);void put_disk (struct gendisk *disk) {if (disk) -kobject_put (&disk->kobj); +kobject_put (&disk->dev.kobj); }EXPORT_SYMBOL (put_disk);
block/ll_rw_blk.c +2 -2
@@ -4182,7 +4182,7 @@ int blk_register_queue(struct gendisk *disk)if (!q || !q->request_fn)return -ENXIO ; - q->kobj.parent =kobject_get (&disk->kobj); + q->kobj.parent =kobject_get (&disk->dev.kobj); ret =kobject_add (&q->kobj);if (ret <0 )
@@ -4209,6 +4209,6 @@ void blk_unregister_queue(struct gendisk *disk)kobject_uevent (&q->kobj,KOBJ_REMOVE );kobject_del (&q->kobj); -kobject_put (&disk->kobj); +kobject_put (&disk->dev.kobj); } }
drivers/base/class.c +7 -0
@@ -17,6 +17,7 @@#include <linux/kdev_t.h> #include <linux/err.h> #include <linux/slab.h> +#include <linux/genhd.h> #include "base.h" #define to_class_attr (_attr) container_of(_attr, struct class_attribute, attr)
@@ -149,7 +150,13 @@ int class_register(struct class * cls)if (error)return error; +#ifdef CONFIG_SYSFS_DEPRECATED +/* let the block class directory show up in the root of sysfs */ +if (cls != &block_class) + cls->subsys.kobj.kset = class_kset; +#else cls->subsys.kobj.kset = class_kset; +#endif cls->subsys.kobj.ktype = &class_ktype; error =kset_register (&cls->subsys);
drivers/base/core.c +12 -8
@@ -671,14 +671,15 @@ static int device_add_class_symlinks(struct device *dev)#ifdef CONFIG_SYSFS_DEPRECATED /* stacked class devices need a symlink in the class directory */ -if (dev->kobj.parent != &dev->class->subsys.kobj) { +if (dev->kobj.parent != &dev->class->subsys.kobj && + dev->type != &part_type) { error =sysfs_create_link (&dev->class->subsys.kobj, &dev->kobj, dev->bus_id);if (error) goto out_subsys; } -if (dev->parent) { +if (dev->parent && dev->type != &part_type) {struct device *parent = dev->parent;char *class_name;
@@ -707,10 +708,11 @@ static int device_add_class_symlinks(struct device *dev)return 0 ; out_device: -if (dev->parent) +if (dev->parent && dev->type != &part_type)sysfs_remove_link (&dev->kobj,"device" ); out_busid: -if (dev->kobj.parent != &dev->class->subsys.kobj) +if (dev->kobj.parent != &dev->class->subsys.kobj && + dev->type != &part_type)sysfs_remove_link (&dev->class->subsys.kobj, dev->bus_id);#else /* link in the class directory pointing to the device */
@@ -719,7 +721,7 @@ out_busid:if (error) goto out_subsys; -if (dev->parent) { +if (dev->parent && dev->type != &part_type) { error =sysfs_create_link (&dev->kobj, &dev->parent->kobj,"device" );if (error)
@@ -743,7 +745,7 @@ static void device_remove_class_symlinks(struct device *dev)return ;#ifdef CONFIG_SYSFS_DEPRECATED -if (dev->parent) { +if (dev->parent && dev->type != &part_type) {char *class_name; class_name =make_class_name (dev->class->name, &dev->kobj);
@@ -754,10 +756,11 @@ static void device_remove_class_symlinks(struct device *dev) sysfs_remove_link(&dev->kobj, "device"); } -if (dev->kobj.parent != &dev->class->subsys.kobj) +if (dev->kobj.parent != &dev->class->subsys.kobj && + dev->type != &part_type)sysfs_remove_link (&dev->class->subsys.kobj, dev->bus_id);#else -if (dev->parent) +if (dev->parent && dev->type != &part_type)sysfs_remove_link (&dev->kobj,"device" );sysfs_remove_link (&dev->class->subsys.kobj, dev->bus_id);
@@ -925,6 +928,7 @@ struct device * get_device(struct device * dev)*/ void put_device (struct device * dev) { +/* might_sleep(); */ if (dev)kobject_put (&dev->kobj); }
drivers/block/aoe/aoeblk.c +25 -26
95 lines not on this page · raw message
drivers/block/nbd.c +9 -6
@@ -375,14 +375,17 @@ harderror:return NULL ; } -static ssize_t pid_show (struct gendisk *disk,char *page) +static ssize_t pid_show (struct device *dev, +struct device_attribute *attr,char *buf) { -return sprintf (page,"%ld\n" , +struct gendisk *disk =dev_to_disk (dev); + +return sprintf (buf,"%ld\n" , (long ) ((struct nbd_device *)disk->private_data)->pid); } -static struct disk_attribute pid_attr = { - .attr = { .name ="pid" , .mode =S_IRUGO }, +static struct device_attribute pid_attr = { + .attr = { .name ="pid" , .mode =S_IRUGO , .owner =THIS_MODULE }, .show = pid_show, };
@@ -394,7 +397,7 @@ static int nbd_do_it(struct nbd_device *lo)BUG_ON (lo->magic !=LO_MAGIC ); lo->pid = current->pid; - ret =sysfs_create_file (&lo->disk->kobj, &pid_attr.attr); + ret =sysfs_create_file (&lo->disk->dev.kobj, &pid_attr.attr);if (ret) {printk (KERN_ERR "nbd: sysfs_create_file failed!" );return ret;
@@ -403,7 +406,7 @@ static int nbd_do_it(struct nbd_device *lo)while ((req =nbd_read_stat (lo)) !=NULL )nbd_end_request (req); -sysfs_remove_file (&lo->disk->kobj, &pid_attr.attr); +sysfs_remove_file (&lo->disk->dev.kobj, &pid_attr.attr);return 0 ; }
drivers/ide/ide-probe.c +1 -1
@@ -1173,7 +1173,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data) {struct gendisk *p = data; *part &= (1 <<PARTN_BITS ) -1 ; -return &p->kobj; +return &p->dev.kobj; }static int exact_lock (dev_t dev,void *data)
drivers/md/dm.c +2 -2
@@ -1109,7 +1109,7 @@ static void event_callback(void *context)list_splice_init (&md->uevent_list, &uevents);spin_unlock_irqrestore (&md->uevent_lock, flags); -dm_send_uevents (&uevents, &md->disk->kobj); +dm_send_uevents (&uevents, &md->disk->dev.kobj);atomic_inc (&md->event_nr);wake_up (&md->eventq);
@@ -1530,7 +1530,7 @@ out:*---------------------------------------------------------------*/ void dm_kobject_uevent (struct mapped_device *md) { -kobject_uevent (&md->disk->kobj,KOBJ_CHANGE ); +kobject_uevent (&md->disk->dev.kobj,KOBJ_CHANGE ); }uint32_t dm_next_uevent_seq (struct mapped_device *md)
drivers/md/md.c +4 -4
@@ -1396,9 +1396,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) goto fail;if (rdev->bdev->bd_part) - ko = &rdev->bdev->bd_part->kobj; + ko = &rdev->bdev->bd_part->dev.kobj;else - ko = &rdev->bdev->bd_disk->kobj; + ko = &rdev->bdev->bd_disk->dev.kobj;if ((err =sysfs_create_link (&rdev->kobj, ko,"block" ))) {kobject_del (&rdev->kobj); goto fail;
@@ -3083,7 +3083,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)add_disk (disk); mddev->gendisk = disk;mutex_unlock (&disks_mutex); - error =kobject_init_and_add (&mddev->kobj, &md_ktype, &disk->kobj, + error =kobject_init_and_add (&mddev->kobj, &md_ktype, &disk->dev.kobj,"%s" ,"md" );if (error) printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
@@ -3361,7 +3361,7 @@ static int do_md_run(mddev_t * mddev) mddev->changed =1 ;md_new_event (mddev); -kobject_uevent (&mddev->gendisk->kobj,KOBJ_CHANGE ); +kobject_uevent (&mddev->gendisk->dev.kobj,KOBJ_CHANGE );return 0 ; }
fs/block_dev.c +4 -4
@@ -738,9 +738,9 @@ EXPORT_SYMBOL(bd_release);static struct kobject *bdev_get_kobj (struct block_device *bdev) {if (bdev->bd_contains != bdev) -return kobject_get (&bdev->bd_part->kobj); +return kobject_get (&bdev->bd_part->dev.kobj);else -return kobject_get (&bdev->bd_disk->kobj); +return kobject_get (&bdev->bd_disk->dev.kobj); }static struct kobject *bdev_get_holder (struct block_device *bdev)
@@ -1176,7 +1176,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) ret = -ENXIO ; goto out_first; } -kobject_get (&p->kobj); +kobject_get (&p->dev.kobj); bdev->bd_part = p;bd_set_size (bdev, (loff_t ) p->nr_sects <<9 ); }
@@ -1299,7 +1299,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part)module_put (owner);if (bdev->bd_contains != bdev) { -kobject_put (&bdev->bd_part->kobj); +kobject_put (&bdev->bd_part->dev.kobj); bdev->bd_part =NULL ; } bdev->bd_disk =NULL ;
fs/partitions/check.c +105 -210
439 lines not on this page · raw message
include/linux/genhd.h +23 -14
@@ -10,9 +10,19 @@*/ #include <linux/types.h> +#include <linux/kdev_t.h> #ifdef CONFIG_BLOCK +#define kobj_to_dev (k) container_of(k, struct device, kobj) +#define dev_to_disk (device) container_of(device, struct gendisk, dev) +#define dev_to_part (device) container_of(device, struct hd_struct, dev) + +extern struct device_type disk_type; +extern struct device_type part_type; +extern struct kobject *block_depr; +extern struct class block_class; +enum {/* These three have identical behaviour; use the second one if DOS FDISK gets confused about extended/logical partitions starting past cylinder 1023. */
@@ -84,7 +94,7 @@ struct partition {struct hd_struct {sector_t start_sect;sector_t nr_sects; -struct kobject kobj; +struct device dev;struct kobject *holder_dir;unsigned ios[2 ], sectors[2 ];/* READs and WRITEs */ int policy, partno;
@@ -117,15 +127,14 @@ struct gendisk {* disks that can't be partitioned. */ char disk_name[32 ];/* name of major driver */ struct hd_struct **part;/* [indexed by minor] */ -int part_uevent_suppress;struct block_device_operations *fops;struct request_queue *queue;void *private_data;sector_t capacity;int flags; -struct device *driverfs_dev; -struct kobject kobj; +struct device *driverfs_dev;// FIXME: remove +struct device dev;struct kobject *holder_dir;struct kobject *slave_dir;
@@ -143,13 +152,6 @@ struct gendisk {struct work_struct async_notify; }; -/* Structure for sysfs attributes on block devices */ -struct disk_attribute { -struct attribute attr; -ssize_t (*show)(struct gendisk *,char *); -ssize_t (*store)(struct gendisk *,const char *,size_t ); -}; -/* * Macros to operate on percpu disk statistics: *
@@ -411,7 +413,8 @@ struct unixware_disklabel {#define ADDPART_FLAG_RAID 1#define ADDPART_FLAG_WHOLEDISK 2 -char *disk_name (struct gendisk *hd,int part,char *buf); +extern dev_t blk_lookup_devt (const char *name); +extern char *disk_name (struct gendisk *hd,int part,char *buf);extern int rescan_partitions (struct gendisk *disk,struct block_device *bdev);extern void add_partition (struct gendisk *,int ,sector_t ,sector_t ,int );
@@ -423,12 +426,12 @@ extern struct gendisk *alloc_disk(int minors);extern struct kobject *get_disk (struct gendisk *disk);extern void put_disk (struct gendisk *disk);extern void genhd_media_change_notify (struct gendisk *disk); -extern void blk_register_region (dev_t dev,unsigned long range, +extern void blk_register_region (dev_t devt,unsigned long range,struct module *module,struct kobject *(*probe)(dev_t ,int *,void *),int (*lock)(dev_t ,void *),void *data); -extern void blk_unregister_region (dev_t dev,unsigned long range); +extern void blk_unregister_region (dev_t devt,unsigned long range);static inline struct block_device *bdget_disk (struct gendisk *disk,int index) {
@@ -441,6 +444,12 @@ static inline struct block_device *bdget_disk(struct gendisk *disk, int index)static inline void printk_all_partitions (void ) { } +static inline dev_t blk_lookup_devt (const char *name) +{ +dev_t devt =MKDEV (0 ,0 ); +return devt; +} +#endif /* CONFIG_BLOCK */ #endif
init/do_mounts.c +8 -100
143 lines not on this page · raw message
Signature · 1 line
1.5.3.8
PATCH 159/196 Kobject: convert block/elevator.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- block/elevator.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)
block/elevator.c +2 -6
@@ -185,9 +185,7 @@ static elevator_t *elevator_alloc(struct request_queue *q, eq->ops = &e->ops; eq->elevator_type = e; -kobject_init (&eq->kobj); -kobject_set_name (&eq->kobj,"%s" ,"iosched" ); - eq->kobj.ktype = &elv_ktype; +kobject_init_ng (&eq->kobj, &elv_ktype);mutex_init (&eq->sysfs_lock); eq->hash = kmalloc_node(sizeof(struct hlist_head) * ELV_HASH_ENTRIES,
@@ -931,9 +929,7 @@ int elv_register_queue(struct request_queue *q)elevator_t *e = q->elevator;int error; - e->kobj.parent = &q->kobj; - - error =kobject_add (&e->kobj); + error =kobject_add_ng (&e->kobj, &q->kobj,"%s" ,"iosched" );if (!error) {struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;if (attr) {
Signature · 1 line
1.5.3.8
PATCH 160/196 Kobject: convert block/ll_rw_blk.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- block/ll_rw_blk.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-)
block/ll_rw_blk.c +3 -6
@@ -1862,9 +1862,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)init_timer (&q->unplug_timer); -kobject_set_name (&q->kobj,"%s" ,"queue" ); - q->kobj.ktype = &queue_ktype; -kobject_init (&q->kobj); +kobject_init_ng (&q->kobj, &queue_ktype);mutex_init (&q->sysfs_lock);
@@ -4182,9 +4180,8 @@ int blk_register_queue(struct gendisk *disk)if (!q || !q->request_fn)return -ENXIO ; - q->kobj.parent =kobject_get (&disk->dev.kobj); - - ret =kobject_add (&q->kobj); + ret =kobject_add_ng (&q->kobj,kobject_get (&disk->dev.kobj), +"%s" ,"queue" );if (ret <0 )return ret;
Signature · 1 line
1.5.3.8
PATCH 161/196 Kobject: convert drivers/md/md.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- drivers/md/md.c | 13 ++++--------- 1 files changed, 4 insertions(+), 9 deletions(-)
drivers/md/md.c +4 -9
@@ -1383,16 +1383,13 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)return -EBUSY ; }bdevname (rdev->bdev,b); -if (kobject_set_name (&rdev->kobj,"dev-%s" , b) <0 ) -return -ENOMEM ; -while ( (s=strchr (rdev->kobj.k_name,'/' )) !=NULL ) +while ( (s=strchr (b,'/' )) !=NULL ) *s ='!' ; - + rdev->mddev = mddev;printk (KERN_INFO "md: bind<%s>\n" , b); - rdev->kobj.parent = &mddev->kobj; -if ((err =kobject_add (&rdev->kobj))) +if ((err =kobject_add_ng (&rdev->kobj, &mddev->kobj,"dev-%s" , b))) goto fail;if (rdev->bdev->bd_part)
@@ -2036,9 +2033,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_miif (err) goto abort_free; - rdev->kobj.parent =NULL ; - rdev->kobj.ktype = &rdev_ktype; -kobject_init (&rdev->kobj); +kobject_init_ng (&rdev->kobj, &rdev_ktype); rdev->desc_nr =-1 ; rdev->saved_raid_disk =-1 ;
Signature · 1 line
1.5.3.8
PATCH 162/196 Kobject: convert kernel/module.c to use kobject_init/add_ng()
In reply to Greg KHThis converts the code to use the new kobject functions, cleaning up the logic in doing so.
--- kernel/module.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
kernel/module.c +6 -8
@@ -1217,18 +1217,16 @@ int mod_sysfs_init(struct module *mod) err = -EINVAL ; goto out; } -memset (&mod->mkobj.kobj,0 ,sizeof (mod->mkobj.kobj)); - err =kobject_set_name (&mod->mkobj.kobj,"%s" , mod->name); -if (err) - goto out; - mod->mkobj.kobj.kset = module_kset; - mod->mkobj.kobj.ktype = &module_ktype; mod->mkobj.mod = mod; -kobject_init (&mod->mkobj.kobj); +memset (&mod->mkobj.kobj,0 ,sizeof (mod->mkobj.kobj)); + mod->mkobj.kobj.kset = module_kset; + err =kobject_init_and_add (&mod->mkobj.kobj, &module_ktype,NULL , +"%s" , mod->name); +if (err) +kobject_put (&mod->mkobj.kobj);/* delay uevent until full sysfs population */ - err =kobject_add (&mod->mkobj.kobj); out:return err; }
Signature · 1 line
1.5.3.8
PATCH 163/196 Kobject: remove kobject_add() as no one uses it anymore
In reply to Greg KHThe old kobject_add() function is on longer in use, so let us remove it from the public scope (kset mess in the kobject.c file still uses it, but that can be cleaned up later very simply.)
--- include/linux/kobject.h | 1 - lib/kobject.c | 22 ++++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-)
include/linux/kobject.h +0 -1
@@ -80,7 +80,6 @@ static inline const char * kobject_name(const struct kobject * kobj)extern void kobject_init (struct kobject *);extern void kobject_init_ng (struct kobject *kobj,struct kobj_type *ktype); -extern int __must_check kobject_add (struct kobject *);extern int __must_check kobject_add_ng (struct kobject *kobj,struct kobject *parent,const char *fmt, ...);
lib/kobject.c +8 -14
@@ -144,7 +144,7 @@ void kobject_init(struct kobject * kobj)* Remove the kobject from the kset list and decrement * its parent's refcount. * This is separated out, so we can use it in both -* kobject_del() and kobject_add() on error. +* kobject_del() and kobject_add_internal() on error. */ static void unlink (struct kobject * kobj)
@@ -161,12 +161,7 @@ static void unlink(struct kobject * kobj)kobject_put (parent); } -/** -* kobject_add - add an object to the hierarchy. -* @kobj: object. -*/ - -int kobject_add (struct kobject * kobj) +static int kobject_add_internal (struct kobject *kobj) {int error =0 ;struct kobject * parent;
@@ -215,13 +210,13 @@ int kobject_add(struct kobject * kobj)/* be noisy on error issues */ if (error == -EEXIST ) -printk (KERN_ERR "kobject_add failed for %s with " +printk (KERN_ERR "%s failed for %s with " "-EEXIST, don't try to register things with " "the same name in the same directory.\n" , -kobject_name (kobj)); + __FUNCTION__,kobject_name (kobj));else -printk (KERN_ERR "kobject_add failed for %s (%d)\n" , -kobject_name (kobj), error); +printk (KERN_ERR "%s failed for %s (%d)\n" , + __FUNCTION__,kobject_name (kobj), error);dump_stack (); }
@@ -351,7 +346,7 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,return retval; } kobj->parent = parent; -return kobject_add (kobj); +return kobject_add_internal (kobj); }/**
@@ -742,7 +737,7 @@ struct sysfs_ops kobj_sysfs_ops = {int kset_add (struct kset * k) { -return kobject_add (&k->kobj); +return kobject_add_internal (&k->kobj); }
@@ -897,7 +892,6 @@ EXPORT_SYMBOL(kobject_register);EXPORT_SYMBOL (kobject_unregister);EXPORT_SYMBOL (kobject_get);EXPORT_SYMBOL (kobject_put); -EXPORT_SYMBOL (kobject_add);EXPORT_SYMBOL (kobject_del);EXPORT_SYMBOL (kset_register);
Signature · 1 line
1.5.3.8
PATCH 164/196 Kobject: rename kobject_add_ng() to kobject_add()
In reply to Greg KHNow that the old kobject_add() function is gone, rename kobject_add_ng() to kobject_add() to clean up the namespace.
--- block/elevator.c | 2 +- block/ll_rw_blk.c | 4 ++-- drivers/base/class.c | 4 ++-- drivers/base/core.c | 6 +++--- drivers/base/driver.c | 2 +- drivers/md/md.c | 2 +- drivers/net/iseries_veth.c | 2 +- drivers/uio/uio.c | 2 +- include/linux/kobject.h | 6 +++--- lib/kobject.c | 14 +++++++------- 10 files changed, 22 insertions(+), 22 deletions(-)
block/elevator.c +1 -1
@@ -929,7 +929,7 @@ int elv_register_queue(struct request_queue *q)elevator_t *e = q->elevator;int error; - error =kobject_add_ng (&e->kobj, &q->kobj,"%s" ,"iosched" ); + error =kobject_add (&e->kobj, &q->kobj,"%s" ,"iosched" );if (!error) {struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;if (attr) {
block/ll_rw_blk.c +2 -2
@@ -4180,8 +4180,8 @@ int blk_register_queue(struct gendisk *disk)if (!q || !q->request_fn)return -ENXIO ; - ret =kobject_add_ng (&q->kobj,kobject_get (&disk->dev.kobj), -"%s" ,"queue" ); + ret =kobject_add (&q->kobj,kobject_get (&disk->dev.kobj), +"%s" ,"queue" );if (ret <0 )return ret;
drivers/base/class.c +2 -2
@@ -586,8 +586,8 @@ int class_device_add(struct class_device *class_dev)else class_dev->kobj.parent = &parent_class->subsys.kobj; - error =kobject_add_ng (&class_dev->kobj, class_dev->kobj.parent, -"%s" , class_dev->class_id); + error =kobject_add (&class_dev->kobj, class_dev->kobj.parent, +"%s" , class_dev->class_id);if (error) goto out2;
drivers/base/core.c +3 -3
@@ -602,7 +602,7 @@ static struct kobject *get_device_parent(struct device *dev,if (!k)return NULL ; k->kset = &dev->class->class_dirs; - retval =kobject_add_ng (k, parent_kobj,"%s" , dev->class->name); + retval =kobject_add (k, parent_kobj,"%s" , dev->class->name);if (retval <0 ) {kobject_put (k);return NULL ;
@@ -776,7 +776,7 @@ static void device_remove_class_symlinks(struct device *dev)* This is part 2 of device_register(), though may be called * separately _iff_ device_initialize() has been called separately. * -* This adds it to the kobject hierarchy via kobject_add_ng(), adds it +* This adds it to the kobject hierarchy via kobject_add(), adds it * to the global and sibling lists for the device, then * adds it to the other relevant subsystems of the driver model. */
@@ -807,7 +807,7 @@ int device_add(struct device *dev) goto Error;/* first, register with generic layer. */ - error =kobject_add_ng (&dev->kobj, dev->kobj.parent,"%s" , dev->bus_id); + error =kobject_add (&dev->kobj, dev->kobj.parent,"%s" , dev->bus_id);if (error) goto Error;
drivers/base/driver.c +1 -1
@@ -144,7 +144,7 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,if (!name)return -ENOMEM ; -return kobject_add_ng (kobj, &drv->p->kobj,"%s" , name); +return kobject_add (kobj, &drv->p->kobj,"%s" , name); }EXPORT_SYMBOL_GPL (driver_add_kobj);
drivers/md/md.c +1 -1
@@ -1389,7 +1389,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) rdev->mddev = mddev;printk (KERN_INFO "md: bind<%s>\n" , b); -if ((err =kobject_add_ng (&rdev->kobj, &mddev->kobj,"dev-%s" , b))) +if ((err =kobject_add (&rdev->kobj, &mddev->kobj,"dev-%s" , b))) goto fail;if (rdev->bdev->bd_part)
drivers/net/iseries_veth.c +1 -1
@@ -1084,7 +1084,7 @@ static struct net_device * __init veth_probe_one(int vlan, }kobject_init_ng (&port->kobject, &veth_port_ktype); -if (0 !=kobject_add_ng (&port->kobject, &dev->dev.kobj,"veth_port" )) +if (0 !=kobject_add (&port->kobject, &dev->dev.kobj,"veth_port" ))veth_error ("Failed adding port for %s to sysfs.\n" , dev->name); veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n",
drivers/uio/uio.c +1 -1
@@ -172,7 +172,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)kobject_init_ng (&map->kobj, &map_attr_type); map->mem = mem; mem->map = map; - ret =kobject_add_ng (&map->kobj, idev->map_dir,"map%d" , mi); + ret =kobject_add (&map->kobj, idev->map_dir,"map%d" , mi);if (ret) goto err; ret =kobject_uevent (&map->kobj,KOBJ_ADD );
include/linux/kobject.h +3 -3
@@ -80,9 +80,9 @@ static inline const char * kobject_name(const struct kobject * kobj)extern void kobject_init (struct kobject *);extern void kobject_init_ng (struct kobject *kobj,struct kobj_type *ktype); -extern int __must_check kobject_add_ng (struct kobject *kobj, -struct kobject *parent, -const char *fmt, ...); +extern int __must_check kobject_add (struct kobject *kobj, +struct kobject *parent, +const char *fmt, ...); extern int __must_check kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, struct kobject *parent,
lib/kobject.c +7 -7
@@ -350,7 +350,7 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, }/** -* kobject_add_ng - the main kobject add function +* kobject_add - the main kobject add function * @kobj: the kobject to add * @parent: pointer to the parent of the kobject. * @fmt: format to name the kobject with.
@@ -381,8 +381,8 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,* kobject_uevent() with the UEVENT_ADD parameter to ensure that * userspace is properly notified of this kobject's creation. */ -int kobject_add_ng (struct kobject *kobj,struct kobject *parent, -const char *fmt, ...) +int kobject_add (struct kobject *kobj,struct kobject *parent, +const char *fmt, ...) {va_list args;int retval;
@@ -396,7 +396,7 @@ int kobject_add_ng(struct kobject *kobj, struct kobject *parent,return retval; } -EXPORT_SYMBOL (kobject_add_ng); +EXPORT_SYMBOL (kobject_add);/** * kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy
@@ -406,8 +406,8 @@ EXPORT_SYMBOL(kobject_add_ng);* @fmt: the name of the kobject. * * This function combines the call to kobject_init_ng() and -* kobject_add_ng(). The same type of error handling after a call to -* kobject_add_ng() and kobject lifetime rules are the same here. +* kobject_add(). The same type of error handling after a call to +* kobject_add() and kobject lifetime rules are the same here. */ int kobject_init_and_add (struct kobject *kobj,struct kobj_type *ktype,struct kobject *parent,const char *fmt, ...)
@@ -677,7 +677,7 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)if (!kobj)return NULL ; - retval =kobject_add_ng (kobj, parent,"%s" , name); + retval =kobject_add (kobj, parent,"%s" , name);if (retval) {printk (KERN_WARNING "%s: kobject_add error: %d\n" , __FUNCTION__, retval);
Signature · 1 line
1.5.3.8
PATCH 165/196 Kobject: remove kobject_init() as no one uses it anymore
In reply to Greg KHThe old kobject_init() function is on longer in use, so let us remove it from the public scope (kset mess in the kobject.c file still uses it, but that can be cleaned up later very simply.)
--- include/linux/kobject.h | 1 - lib/kobject.c | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-)
include/linux/kobject.h +0 -1
@@ -78,7 +78,6 @@ static inline const char * kobject_name(const struct kobject * kobj)return kobj->k_name; } -extern void kobject_init (struct kobject *);extern void kobject_init_ng (struct kobject *kobj,struct kobj_type *ktype); extern int __must_check kobject_add(struct kobject *kobj, struct kobject *parent,
lib/kobject.c +3 -8
@@ -124,11 +124,7 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask) }EXPORT_SYMBOL_GPL (kobject_get_path); -/** -* kobject_init - initialize object. -* @kobj: object in question. -*/ -void kobject_init (struct kobject * kobj) +static void kobject_init_internal (struct kobject * kobj) {if (!kobj)return ;
@@ -232,7 +228,7 @@ int kobject_register(struct kobject * kobj) {int error = -EINVAL ;if (kobj) { -kobject_init (kobj); +kobject_init_internal (kobj); error =kobject_add (kobj);if (!error)kobject_uevent (kobj,KOBJ_ADD );
@@ -695,7 +691,7 @@ EXPORT_SYMBOL_GPL(kobject_create_and_add);void kset_init (struct kset * k) { -kobject_init (&k->kobj); +kobject_init_internal (&k->kobj);INIT_LIST_HEAD (&k->list);spin_lock_init (&k->list_lock); }
@@ -887,7 +883,6 @@ struct kset *kset_create_and_add(const char *name, }EXPORT_SYMBOL_GPL (kset_create_and_add); -EXPORT_SYMBOL (kobject_init);EXPORT_SYMBOL (kobject_register);EXPORT_SYMBOL (kobject_unregister);EXPORT_SYMBOL (kobject_get);
Signature · 1 line
1.5.3.8
PATCH 166/196 Kobject: rename kobject_init_ng() to kobject_init()
In reply to Greg KHNow that the old kobject_init() function is gone, rename kobject_init_ng() to kobject_init() to clean up the namespace.
--- block/elevator.c | 2 +- block/ll_rw_blk.c | 2 +- drivers/base/class.c | 2 +- drivers/base/core.c | 2 +- drivers/md/md.c | 2 +- drivers/net/iseries_veth.c | 4 ++-- drivers/uio/uio.c | 2 +- fs/char_dev.c | 4 ++-- include/linux/kobject.h | 2 +- lib/kobject.c | 14 +++++++------- 10 files changed, 18 insertions(+), 18 deletions(-)
block/elevator.c +1 -1
@@ -185,7 +185,7 @@ static elevator_t *elevator_alloc(struct request_queue *q, eq->ops = &e->ops; eq->elevator_type = e; -kobject_init_ng (&eq->kobj, &elv_ktype); +kobject_init (&eq->kobj, &elv_ktype);mutex_init (&eq->sysfs_lock); eq->hash = kmalloc_node(sizeof(struct hlist_head) * ELV_HASH_ENTRIES,
block/ll_rw_blk.c +1 -1
@@ -1862,7 +1862,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)init_timer (&q->unplug_timer); -kobject_init_ng (&q->kobj, &queue_ktype); +kobject_init (&q->kobj, &queue_ktype);mutex_init (&q->sysfs_lock);
drivers/base/class.c +1 -1
@@ -553,7 +553,7 @@ static struct class_device_attribute class_uevent_attr =void class_device_initialize (struct class_device *class_dev) { class_dev->kobj.kset = &class_obj_subsys; -kobject_init_ng (&class_dev->kobj, &class_device_ktype); +kobject_init (&class_dev->kobj, &class_device_ktype);INIT_LIST_HEAD (&class_dev->node); }
drivers/base/core.c +1 -1
@@ -525,7 +525,7 @@ static void klist_children_put(struct klist_node *n)void device_initialize (struct device *dev) { dev->kobj.kset = devices_kset; -kobject_init_ng (&dev->kobj, &device_ktype); +kobject_init (&dev->kobj, &device_ktype);klist_init (&dev->klist_children, klist_children_get, klist_children_put);INIT_LIST_HEAD (&dev->dma_pools);
drivers/md/md.c +1 -1
@@ -2033,7 +2033,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_miif (err) goto abort_free; -kobject_init_ng (&rdev->kobj, &rdev_ktype); +kobject_init (&rdev->kobj, &rdev_ktype); rdev->desc_nr =-1 ; rdev->saved_raid_disk =-1 ;
drivers/net/iseries_veth.c +2 -2
@@ -844,7 +844,7 @@ static int veth_init_connection(u8 rlp)/* This gets us 1 reference, which is held on behalf of the driver * infrastructure. It's released at module unload. */ -kobject_init_ng (&cnx->kobject, &veth_lpar_connection_ktype); +kobject_init (&cnx->kobject, &veth_lpar_connection_ktype); msgs =kcalloc (VETH_NUMBUFFERS ,sizeof (struct veth_msg ),GFP_KERNEL );if (! msgs) {
@@ -1083,7 +1083,7 @@ static struct net_device * __init veth_probe_one(int vlan,return NULL ; } -kobject_init_ng (&port->kobject, &veth_port_ktype); +kobject_init (&port->kobject, &veth_port_ktype);if (0 !=kobject_add (&port->kobject, &dev->dev.kobj,"veth_port" ))veth_error ("Failed adding port for %s to sysfs.\n" , dev->name);
drivers/uio/uio.c +1 -1
@@ -169,7 +169,7 @@ static int uio_dev_add_attributes(struct uio_device *idev) map =kzalloc (sizeof (*map),GFP_KERNEL );if (!map) goto err; -kobject_init_ng (&map->kobj, &map_attr_type); +kobject_init (&map->kobj, &map_attr_type); map->mem = mem; mem->map = map; ret =kobject_add (&map->kobj, idev->map_dir,"map%d" , mi);
fs/char_dev.c +2 -2
@@ -511,7 +511,7 @@ struct cdev *cdev_alloc(void)struct cdev *p =kzalloc (sizeof (struct cdev ),GFP_KERNEL );if (p) {INIT_LIST_HEAD (&p->list); -kobject_init_ng (&p->kobj, &ktype_cdev_dynamic); +kobject_init (&p->kobj, &ktype_cdev_dynamic); }return p; }
@@ -528,7 +528,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops) {memset (cdev,0 ,sizeof *cdev);INIT_LIST_HEAD (&cdev->list); -kobject_init_ng (&cdev->kobj, &ktype_cdev_default); +kobject_init (&cdev->kobj, &ktype_cdev_default); cdev->ops = fops; }
include/linux/kobject.h +1 -1
@@ -78,7 +78,7 @@ static inline const char * kobject_name(const struct kobject * kobj)return kobj->k_name; } -extern void kobject_init_ng (struct kobject *kobj,struct kobj_type *ktype); +extern void kobject_init (struct kobject *kobj,struct kobj_type *ktype);extern int __must_check kobject_add (struct kobject *kobj,struct kobject *parent,const char *fmt, ...);
lib/kobject.c +7 -7
@@ -287,7 +287,7 @@ int kobject_set_name(struct kobject *kobj, const char *fmt, ...)EXPORT_SYMBOL (kobject_set_name);/** -* kobject_init_ng - initialize a kobject structure +* kobject_init - initialize a kobject structure * @kobj: pointer to the kobject to initialize * @ktype: pointer to the ktype for this kobject. *
@@ -298,7 +298,7 @@ EXPORT_SYMBOL(kobject_set_name);* to kobject_put(), not by a call to kfree directly to ensure that all of * the memory is cleaned up properly. */ -void kobject_init_ng (struct kobject *kobj,struct kobj_type *ktype) +void kobject_init (struct kobject *kobj,struct kobj_type *ktype) {char *err_str;
@@ -326,7 +326,7 @@ error:printk (KERN_ERR "kobject: %s\n" , err_str);dump_stack (); } -EXPORT_SYMBOL (kobject_init_ng); +EXPORT_SYMBOL (kobject_init);static int kobject_add_varg (struct kobject *kobj,struct kobject *parent,const char *fmt,va_list vargs)
@@ -401,7 +401,7 @@ EXPORT_SYMBOL(kobject_add);* @parent: pointer to the parent of this kobject. * @fmt: the name of the kobject. * -* This function combines the call to kobject_init_ng() and +* This function combines the call to kobject_init() and * kobject_add(). The same type of error handling after a call to * kobject_add() and kobject lifetime rules are the same here. */
@@ -411,7 +411,7 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,va_list args;int retval; -kobject_init_ng (kobj, ktype); +kobject_init (kobj, ktype);va_start (args, fmt); retval =kobject_add_varg (kobj, parent, fmt, args);
@@ -636,7 +636,7 @@ static struct kobj_type dynamic_kobj_ktype = {* * If the kobject was not able to be created, NULL will be returned. * The kobject structure returned from here must be cleaned up with a -* call to kobject_put() and not kfree(), as kobject_init_ng() has +* call to kobject_put() and not kfree(), as kobject_init() has * already been called on this structure. */ struct kobject *kobject_create (void )
@@ -647,7 +647,7 @@ struct kobject *kobject_create(void)if (!kobj)return NULL ; -kobject_init_ng (kobj, &dynamic_kobj_ktype); +kobject_init (kobj, &dynamic_kobj_ktype);return kobj; }
Signature · 1 line
1.5.3.8
PATCH 167/196 Kobject: remove kobject_register()
In reply to Greg KHThe function is no longer used by anyone in the kernel, and it prevents the proper sending of the kobject uevent after the needed files are set up by the caller. kobject_init_and_add() can be used in its place.
--- include/linux/kobject.h | 1 - lib/kobject.c | 18 ------------------ 2 files changed, 0 insertions(+), 19 deletions(-)
include/linux/kobject.h +0 -1
@@ -96,7 +96,6 @@ extern struct kobject * __must_check kobject_create_and_add(const char *name,extern int __must_check kobject_rename (struct kobject *,const char *new_name);extern int __must_check kobject_move (struct kobject *,struct kobject *); -extern int __must_check kobject_register (struct kobject *);extern void kobject_unregister (struct kobject *);extern struct kobject *kobject_get (struct kobject *);
lib/kobject.c +0 -18
@@ -220,23 +220,6 @@ static int kobject_add_internal(struct kobject *kobj) }/** -* kobject_register - initialize and add an object. -* @kobj: object in question. -*/ - -int kobject_register (struct kobject * kobj) -{ -int error = -EINVAL ; -if (kobj) { -kobject_init_internal (kobj); - error =kobject_add (kobj); -if (!error) -kobject_uevent (kobj,KOBJ_ADD ); - } -return error; -} - -/** * kobject_set_name_vargs - Set the name of an kobject * @kobj: struct kobject to set the name of * @fmt: format string used to build the name
@@ -883,7 +866,6 @@ struct kset *kset_create_and_add(const char *name, }EXPORT_SYMBOL_GPL (kset_create_and_add); -EXPORT_SYMBOL (kobject_register);EXPORT_SYMBOL (kobject_unregister);EXPORT_SYMBOL (kobject_get);EXPORT_SYMBOL (kobject_put);
Signature · 1 line
1.5.3.8
PATCH 168/196 Kset: remove kset_add function
In reply to Greg KHNo one is calling this anymore, so just remove it and hard-code the one internal-use of it.
--- include/linux/kobject.h | 1 - lib/kobject.c | 13 +------------ 2 files changed, 1 insertions(+), 13 deletions(-)
include/linux/kobject.h +0 -1
@@ -158,7 +158,6 @@ struct kset { };extern void kset_init (struct kset * k); -extern int __must_check kset_add (struct kset * k);extern int __must_check kset_register (struct kset * k);extern void kset_unregister (struct kset * k); extern struct kset * __must_check kset_create_and_add(const char *name,
lib/kobject.c +1 -12
@@ -710,17 +710,6 @@ struct sysfs_ops kobj_sysfs_ops = { };/** -* kset_add - add a kset object to the hierarchy. -* @k: kset. -*/ - -int kset_add (struct kset * k) -{ -return kobject_add_internal (&k->kobj); -} - - -/** * kset_register - initialize and add a kset. * @k: kset. */
@@ -733,7 +722,7 @@ int kset_register(struct kset * k)return -EINVAL ;kset_init (k); - err =kset_add (k); + err =kobject_add_internal (&k->kobj);if (err)return err;kobject_uevent (&k->kobj,KOBJ_ADD );
Signature · 1 line
1.5.3.8
PATCH 169/196 Kobject: auto-cleanup on final unref
In reply to Greg KHFrom: Kay Sievers <[email protected]>
We save the current state in the object itself, so we can do proper cleanup when the last reference is dropped.
If the initial reference is dropped, the object will be removed from sysfs if needed, if an "add" event was sent, "remove" will be send, and the allocated resources are released.
This allows us to clean up some driver core usage as well as allowing us to do other such changes to the rest of the kernel.
--- drivers/base/core.c | 32 ++------- include/linux/kobject.h | 5 ++ lib/kobject.c | 170 ++++++++++++++++++++++++++-------------------- lib/kobject_uevent.c | 11 +++ 4 files changed, 119 insertions(+), 99 deletions(-)
drivers/base/core.c +7 -25
@@ -576,8 +576,8 @@ static struct kobject *get_device_parent(struct device *dev,/* * If we have no parent, we live in "virtual". -* Class-devices with a bus-device as parent, live -* in a class-directory to prevent namespace collisions. +* Class-devices with a non class-device as parent, live +* in a "glue" directory to prevent namespace collisions. */ if (parent ==NULL ) parent_kobj =virtual_device_parent (dev);
@@ -607,8 +607,7 @@ static struct kobject *get_device_parent(struct device *dev,kobject_put (k);return NULL ; } -/* Do not emit a uevent, as it's not needed for this -* "class glue" directory. */ +/* do not emit an uevent for this simple "glue" directory */ return k; }
@@ -619,30 +618,13 @@ static struct kobject *get_device_parent(struct device *dev,static void cleanup_device_parent (struct device *dev) { -struct device *d; -int other =0 ; +struct kobject *glue_dir = dev->kobj.parent; -if (!dev->class) -return ; - -/* see if we live in a parent class directory */ -if (dev->kobj.parent->kset != &dev->class->class_dirs) +/* see if we live in a "glue" directory */ +if (!dev->class || glue_dir->kset != &dev->class->class_dirs)return ; -/* if we are the last child of our class, delete the directory */ -down (&dev->class->sem); -list_for_each_entry (d, &dev->class->devices, node) { -if (d == dev) -continue ; -if (d->kobj.parent == dev->kobj.parent) { - other =1 ; -break ; - } - } -if (!other) -kobject_del (dev->kobj.parent); -kobject_put (dev->kobj.parent); -up (&dev->class->sem); +kobject_put (glue_dir); }#endif
include/linux/kobject.h +5 -0
@@ -68,6 +68,11 @@ struct kobject {struct kset * kset;struct kobj_type * ktype;struct sysfs_dirent * sd; + unsigned int state_initialized:1; + unsigned int state_name_set:1; + unsigned int state_in_sysfs:1; + unsigned int state_add_uevent_sent:1; + unsigned int state_remove_uevent_sent:1; };extern int kobject_set_name (struct kobject *,const char *, ...)
lib/kobject.c +96 -74
279 lines not on this page · raw message
lib/kobject_uevent.c +11 -0
@@ -180,6 +180,17 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, } } +/* +* Mark "add" and "remove" events in the object to ensure proper +* events to userspace during automatic cleanup. If the object did +* send an "add" event, "remove" will automatically generated by +* the core, if not already done by the caller. +*/ +if (action ==KOBJ_ADD ) + kobj->state_add_uevent_sent =1 ; +else if (action ==KOBJ_REMOVE ) + kobj->state_remove_uevent_sent =1 ; +/* we will send an event, so request a new sequence number */ spin_lock (&sequence_lock); seq = ++uevent_seqnum;
Signature · 1 line
1.5.3.8
PATCH 170/196 Modules: remove unneeded release function
In reply to Greg KHNow that kobjects properly clean up their name structures, no matter if they have a release function or not, we can drop this empty module kobject release function too (it was needed prior to this because of the way we handled static kobject names, we based the fact that if a release function was present, then we could safely free the name string, now we are more smart about things and only free names we have previously set.)
--- kernel/params.c | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-)
kernel/params.c +0 -10
@@ -694,18 +694,8 @@ static struct kset_uevent_ops module_uevent_ops = {struct kset *module_kset;int module_sysfs_initialized; -static void module_release (struct kobject *kobj) -{ -/* -* Stupid empty release function to allow the memory for the kobject to -* be properly cleaned up. This will not need to be present for 2.6.25 -* with the upcoming kobject core rework. -*/ -} -struct kobj_type module_ktype = { .sysfs_ops = &module_sysfs_ops, - .release = module_release, };/*
Signature · 1 line
1.5.3.8
PATCH 171/196 Kobject: convert arch/* from kobject_unregister() to kobject_put()
In reply to Greg KHThere is no need for kobject_unregister() anymore, thanks to Kay's kobject cleanup changes, so replace all instances of it with kobject_put().
--- arch/ia64/kernel/topology.c | 9 ++++----- arch/s390/hypfs/inode.c | 4 ++-- arch/sh/kernel/cpu/sh4/sq.c | 2 +- arch/x86/kernel/cpu/intel_cacheinfo.c | 9 ++++----- arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 6 +++--- 5 files changed, 14 insertions(+), 16 deletions(-)
arch/ia64/kernel/topology.c +4 -5
@@ -366,10 +366,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) "index%1lu", i);if (unlikely (retval)) {for (j =0 ; j < i; j++) { -kobject_unregister ( - &(LEAF_KOBJECT_PTR (cpu,j)->kobj)); +kobject_put (&(LEAF_KOBJECT_PTR (cpu,j)->kobj)); } -kobject_unregister (&all_cpu_cache_info[cpu].kobj); +kobject_put (&all_cpu_cache_info[cpu].kobj);cpu_cache_sysfs_exit (cpu);break ; }
@@ -386,10 +385,10 @@ static int __cpuinit cache_remove_dev(struct sys_device * sys_dev)unsigned long i;for (i =0 ; i < all_cpu_cache_info[cpu].num_cache_leaves; i++) -kobject_unregister (&(LEAF_KOBJECT_PTR (cpu,i)->kobj)); +kobject_put (&(LEAF_KOBJECT_PTR (cpu,i)->kobj));if (all_cpu_cache_info[cpu].kobj.parent) { -kobject_unregister (&all_cpu_cache_info[cpu].kobj); +kobject_put (&all_cpu_cache_info[cpu].kobj);memset (&all_cpu_cache_info[cpu].kobj,0 ,sizeof (struct kobject ));
arch/s390/hypfs/inode.c +2 -2
@@ -517,7 +517,7 @@ static int __init hypfs_init(void)return 0 ; fail_filesystem: -kobject_unregister (s390_kobj); +kobject_put (s390_kobj); fail_sysfs:if (!MACHINE_IS_VM )hypfs_diag_exit ();
@@ -531,7 +531,7 @@ static void __exit hypfs_exit(void)if (!MACHINE_IS_VM )hypfs_diag_exit ();unregister_filesystem (&hypfs_type); -kobject_unregister (s390_kobj); +kobject_put (s390_kobj); }module_init (hypfs_init)
arch/sh/kernel/cpu/sh4/sq.c +1 -1
@@ -360,7 +360,7 @@ static int __devexit sq_sysdev_remove(struct sys_device *sysdev)unsigned int cpu = sysdev->id;struct kobject *kobj = sq_kobject[cpu]; -kobject_unregister (kobj); +kobject_put (kobj);return 0 ; }
arch/x86/kernel/cpu/intel_cacheinfo.c +4 -5
@@ -749,10 +749,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) "index%1lu", i);if (unlikely (retval)) {for (j =0 ; j < i; j++) { -kobject_unregister ( - &(INDEX_KOBJECT_PTR (cpu,j)->kobj)); +kobject_put (&(INDEX_KOBJECT_PTR (cpu,j)->kobj)); } -kobject_unregister (cache_kobject[cpu]); +kobject_put (cache_kobject[cpu]);cpuid4_cache_sysfs_exit (cpu);break ; }
@@ -777,8 +776,8 @@ static void __cpuinit cache_remove_dev(struct sys_device * sys_dev)cpu_clear (cpu, cache_dev_map);for (i =0 ; i < num_cache_leaves; i++) -kobject_unregister (&(INDEX_KOBJECT_PTR (cpu,i)->kobj)); -kobject_unregister (cache_kobject[cpu]); +kobject_put (&(INDEX_KOBJECT_PTR (cpu,i)->kobj)); +kobject_put (cache_kobject[cpu]);cpuid4_cache_sysfs_exit (cpu); }
arch/x86/kernel/cpu/mcheck/mce_amd_64.c +3 -3
@@ -456,7 +456,7 @@ recurse: out_free:if (b) { -kobject_unregister (&b->kobj); +kobject_put (&b->kobj);kfree (b); }return err;
@@ -581,7 +581,7 @@ static void deallocate_threshold_block(unsigned int cpu,return ;list_for_each_entry_safe (pos, tmp, &head->blocks->miscj, miscj) { -kobject_unregister (&pos->kobj); +kobject_put (&pos->kobj);list_del (&pos->miscj);kfree (pos); }
@@ -627,7 +627,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)deallocate_threshold_block (cpu, bank); free_out: -kobject_unregister (b->kobj); +kobject_put (b->kobj);kfree (b);per_cpu (threshold_banks, cpu)[bank] =NULL ; }
Signature · 1 line
1.5.3.8
PATCH 172/196 Kobject: convert drivers/* from kobject_unregister() to kobject_put()
In reply to Greg KHThere is no need for kobject_unregister() anymore, thanks to Kay's kobject cleanup changes, so replace all instances of it with kobject_put().
--- drivers/base/bus.c | 4 ++-- drivers/base/sys.c | 2 +- drivers/block/pktcdvd.c | 2 +- drivers/cpufreq/cpufreq.c | 4 +--- drivers/cpuidle/sysfs.c | 4 ++-- drivers/edac/edac_device_sysfs.c | 10 +++++----- drivers/edac/edac_mc_sysfs.c | 12 ++++++------ drivers/edac/edac_pci_sysfs.c | 6 +++--- drivers/firmware/edd.c | 2 +- drivers/firmware/efivars.c | 6 +++--- drivers/infiniband/core/sysfs.c | 6 +++--- drivers/md/md.c | 2 +- drivers/net/ibmveth.c | 2 +- drivers/parisc/pdc_stable.c | 6 +++--- drivers/pci/hotplug/pci_hotplug_core.c | 2 +- drivers/pci/hotplug/rpadlpar_sysfs.c | 4 ++-- drivers/uio/uio.c | 8 ++++---- 17 files changed, 40 insertions(+), 42 deletions(-)
drivers/base/bus.c +2 -2
@@ -681,7 +681,7 @@ int bus_add_driver(struct device_driver *drv)kobject_uevent (&priv->kobj,KOBJ_ADD );return error; out_unregister: -kobject_unregister (&priv->kobj); +kobject_put (&priv->kobj); out_put_bus:bus_put (bus);return error;
@@ -708,7 +708,7 @@ void bus_remove_driver(struct device_driver * drv)pr_debug ("bus: '%s': remove driver %s\n" , drv->bus->name, drv->name);driver_detach (drv);module_remove_driver (drv); -kobject_unregister (&drv->p->kobj); +kobject_put (&drv->p->kobj);bus_put (drv->bus); }
drivers/base/sys.c +1 -1
@@ -264,7 +264,7 @@ void sysdev_unregister(struct sys_device * sysdev) }mutex_unlock (&sysdev_drivers_lock); -kobject_unregister (&sysdev->kobj); +kobject_put (&sysdev->kobj); }
drivers/block/pktcdvd.c +1 -1
@@ -130,7 +130,7 @@ static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd,static void pkt_kobj_remove (struct pktcdvd_kobj *p) {if (p) -kobject_unregister (&p->kobj); +kobject_put (&p->kobj); }/* * default release function for pktcdvd kernel objects.
drivers/cpufreq/cpufreq.c +1 -3
@@ -913,7 +913,7 @@ err_out_unregister: cpufreq_cpu_data[j] =NULL ;spin_unlock_irqrestore (&cpufreq_driver_lock, flags); -kobject_unregister (&policy->kobj); +kobject_put (&policy->kobj);wait_for_completion (&policy->kobj_unregister); err_out_driver_exit:
@@ -1030,8 +1030,6 @@ static int __cpufreq_remove_dev (struct sys_device * sys_dev)unlock_policy_rwsem_write (cpu); -kobject_unregister (&data->kobj); -kobject_put (&data->kobj);/* we need to make sure that the underlying kobj is actually
drivers/cpuidle/sysfs.c +2 -2
@@ -277,7 +277,7 @@ static struct kobj_type ktype_state_cpuidle = {static void inline cpuidle_free_state_kobj (struct cpuidle_device *device,int i) { -kobject_unregister (&device->kobjs[i]->kobj); +kobject_put (&device->kobjs[i]->kobj);wait_for_completion (&device->kobjs[i]->kobj_unregister);kfree (device->kobjs[i]); device->kobjs[i] =NULL ;
@@ -358,5 +358,5 @@ void cpuidle_remove_sysfs(struct sys_device *sysdev)struct cpuidle_device *dev; dev =per_cpu (cpuidle_devices, cpu); -kobject_unregister (&dev->kobj); +kobject_put (&dev->kobj); }
drivers/edac/edac_device_sysfs.c +5 -5
@@ -303,7 +303,7 @@ void edac_device_unregister_sysfs_main_kobj(* a) module_put() this module * b) 'kfree' the memory */ -kobject_unregister (&edac_dev->kobj); +kobject_put (&edac_dev->kobj); }/* edac_dev -> instance information */
@@ -574,7 +574,7 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,/* Error unwind stack */ err_on_attrib: -kobject_unregister (&block->kobj); +kobject_put (&block->kobj); err_out:return err;
@@ -605,7 +605,7 @@ static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev,/* unregister this block's kobject, SEE: * edac_device_ctrl_block_release() callback operation */ -kobject_unregister (&block->kobj); +kobject_put (&block->kobj); }/* instance ctor/dtor code */
@@ -672,7 +672,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,/* error unwind stack */ err_release_instance_kobj: -kobject_unregister (&instance->kobj); +kobject_put (&instance->kobj); err_out:return err;
@@ -697,7 +697,7 @@ static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev,/* unregister this instance's kobject, SEE: * edac_device_ctrl_instance_release() for callback operation */ -kobject_unregister (&instance->kobj); +kobject_put (&instance->kobj); }/*
drivers/edac/edac_mc_sysfs.c +6 -6
@@ -395,7 +395,7 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci, goto err_release_top_kobj;/* At this point, to release a csrow kobj, one must -* call the kobject_unregister and allow that tear down +* call the kobject_put and allow that tear down * to work the releasing */
@@ -406,7 +406,7 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci, err =edac_create_channel_files (&csrow->kobj, chan);if (err) {/* special case the unregister here */ -kobject_unregister (&csrow->kobj); +kobject_put (&csrow->kobj); goto err_out; } }
@@ -808,7 +808,7 @@ fail_out:void edac_mc_unregister_sysfs_main_kobj (struct mem_ctl_info *mci) {/* delete the kobj from the mc_kset */ -kobject_unregister (&mci->edac_mci_kobj); +kobject_put (&mci->edac_mci_kobj); }#define EDAC_DEVICE_SYMLINK "device"
@@ -923,7 +923,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) fail1:for (i--; i >=0 ; i--) {if (csrow->nr_pages >0 ) { -kobject_unregister (&mci->csrows[i].kobj); +kobject_put (&mci->csrows[i].kobj); } }
@@ -950,7 +950,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)for (i =0 ; i < mci->nr_csrows; i++) {if (mci->csrows[i].nr_pages >0 ) {debugf0 ("%s() unreg csrow-%d\n" , __func__, i); -kobject_unregister (&mci->csrows[i].kobj); +kobject_put (&mci->csrows[i].kobj); } }
@@ -967,7 +967,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)debugf0 ("%s() unregister this mci kobj\n" , __func__);/* unregister this instance's kobject */ -kobject_unregister (&mci->edac_mci_kobj); +kobject_put (&mci->edac_mci_kobj); }
drivers/edac/edac_pci_sysfs.c +3 -3
@@ -205,7 +205,7 @@ void edac_pci_unregister_sysfs_instance_kobj(struct edac_pci_ctl_info *pci)* function release the main reference count and then * kfree the memory */ -kobject_unregister (&pci->kobj); +kobject_put (&pci->kobj); }/***************************** EDAC PCI sysfs root **********************/
@@ -411,9 +411,9 @@ static void edac_pci_main_kobj_teardown(void)* main kobj */ if (atomic_dec_return (&edac_pci_sysfs_refcount) ==0 ) { -debugf0 ("%s() called kobject_unregister on main kobj\n" , +debugf0 ("%s() called kobject_put on main kobj\n" , __func__); -kobject_unregister (&edac_pci_top_main_kobj); +kobject_put (&edac_pci_top_main_kobj); } }
drivers/firmware/edd.c +1 -1
@@ -693,7 +693,7 @@ edd_create_symlink_to_pcidev(struct edd_device *edev)static inline void edd_device_unregister (struct edd_device *edev) { -kobject_unregister (&edev->kobj); +kobject_put (&edev->kobj); }static void edd_populate_dir (struct edd_device * edev)
drivers/firmware/efivars.c +3 -3
@@ -397,7 +397,7 @@ static struct kobj_type efivar_ktype = {static inline void efivar_unregister (struct efivar_entry *var) { -kobject_unregister (&var->kobj); +kobject_put (&var->kobj); }
@@ -732,7 +732,7 @@ efivars_init(void)kset_unregister (vars_kset); out_firmware_unregister: -kobject_unregister (efi_kobj); +kobject_put (efi_kobj); out_free:kfree (variable_name);
@@ -753,7 +753,7 @@ efivars_exit(void) }kset_unregister (vars_kset); -kobject_unregister (efi_kobj); +kobject_put (efi_kobj); }module_init (efivars_init);
drivers/infiniband/core/sysfs.c +3 -3
@@ -714,7 +714,7 @@ err_put:sysfs_remove_group (p, &pma_group);sysfs_remove_group (p, &port->pkey_group);sysfs_remove_group (p, &port->gid_group); -kobject_unregister (p); +kobject_put (p); } }
@@ -738,10 +738,10 @@ void ib_device_unregister_sysfs(struct ib_device *device)sysfs_remove_group (p, &pma_group);sysfs_remove_group (p, &port->pkey_group);sysfs_remove_group (p, &port->gid_group); -kobject_unregister (p); +kobject_put (p); } -kobject_unregister (device->ports_parent); +kobject_put (device->ports_parent);class_device_unregister (&device->class_dev); }
drivers/md/md.c +1 -1
@@ -231,7 +231,7 @@ static void mddev_put(mddev_t *mddev)list_del (&mddev->all_mddevs);spin_unlock (&all_mddevs_lock);blk_cleanup_queue (mddev->queue); -kobject_unregister (&mddev->kobj); +kobject_put (&mddev->kobj); }else spin_unlock (&all_mddevs_lock); }
drivers/net/ibmveth.c +1 -1
@@ -1236,7 +1236,7 @@ static int __devexit ibmveth_remove(struct vio_dev *dev)int i;for (i =0 ; i<IbmVethNumBufferPools; i++) -kobject_unregister (&adapter->rx_buff_pool[i].kobj); +kobject_put (&adapter->rx_buff_pool[i].kobj);unregister_netdev (netdev);
drivers/parisc/pdc_stable.c +3 -3
@@ -1026,7 +1026,7 @@ pdcs_unregister_pathentries(void)for (i =0 ; (entry = pdcspath_entries[i]); i++) {read_lock (&entry->rw_lock);if (entry->ready >=2 ) -kobject_unregister (&entry->kobj); +kobject_put (&entry->kobj);read_unlock (&entry->rw_lock); } }
@@ -1086,7 +1086,7 @@ fail_pdcsreg:kset_unregister (paths_kset); fail_ksetreg: -kobject_unregister (stable_kobj); +kobject_put (stable_kobj); fail_firmreg: printk(KERN_INFO PDCS_PREFIX " bailing out\n");
@@ -1098,7 +1098,7 @@ pdc_stable_exit(void) {pdcs_unregister_pathentries ();kset_unregister (paths_kset); -kobject_unregister (stable_kobj); +kobject_put (stable_kobj); }
drivers/pci/hotplug/pci_hotplug_core.c +1 -1
@@ -671,7 +671,7 @@ int pci_hp_deregister (struct hotplug_slot *slot)fs_remove_slot (slot);dbg ("Removed slot %s from the list\n" , slot->name); -kobject_unregister (&slot->kobj); +kobject_put (&slot->kobj);return 0 ; }
drivers/pci/hotplug/rpadlpar_sysfs.c +2 -2
@@ -114,12 +114,12 @@ int dlpar_sysfs_init(void) error =sysfs_create_group (dlpar_kobj, &dlpar_attr_group);if (error) -kobject_unregister (dlpar_kobj); +kobject_put (dlpar_kobj);return error; }void dlpar_sysfs_exit (void ) {sysfs_remove_group (dlpar_kobj, &dlpar_attr_group); -kobject_unregister (dlpar_kobj); +kobject_put (dlpar_kobj); }
drivers/uio/uio.c +4 -4
@@ -186,9 +186,9 @@ err:for (mi--; mi>=0 ; mi--) { mem = &idev->info->mem[mi]; map = mem->map; -kobject_unregister (&map->kobj); +kobject_put (&map->kobj); } -kobject_unregister (idev->map_dir); +kobject_put (idev->map_dir);sysfs_remove_group (&idev->dev->kobj, &uio_attr_grp); err_group:dev_err (idev->dev,"error creating sysfs files (%d)\n" , ret);
@@ -203,9 +203,9 @@ static void uio_dev_del_attributes(struct uio_device *idev) mem = &idev->info->mem[mi];if (mem->size ==0 )break ; -kobject_unregister (&mem->map->kobj); +kobject_put (&mem->map->kobj); } -kobject_unregister (idev->map_dir); +kobject_put (idev->map_dir);sysfs_remove_group (&idev->dev->kobj, &uio_attr_grp); }
Signature · 1 line
1.5.3.8
PATCH 173/196 Kobject: convert fs/* from kobject_unregister() to kobject_put()
In reply to Greg KHThere is no need for kobject_unregister() anymore, thanks to Kay's kobject cleanup changes, so replace all instances of it with kobject_put().
--- fs/configfs/mount.c | 6 +++--- fs/debugfs/inode.c | 4 ++-- fs/dlm/lockspace.c | 4 ++-- fs/ecryptfs/main.c | 4 ++-- fs/fuse/inode.c | 6 +++--- fs/gfs2/locking/dlm/sysfs.c | 2 +- fs/gfs2/sys.c | 4 ++-- fs/partitions/check.c | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-)
fs/configfs/mount.c +3 -3
@@ -150,7 +150,7 @@ static int __init configfs_init(void) err =register_filesystem (&configfs_fs_type);if (err) {printk (KERN_ERR "configfs: Unable to register filesystem!\n" ); -kobject_unregister (config_kobj); +kobject_put (config_kobj);kmem_cache_destroy (configfs_dir_cachep); configfs_dir_cachep =NULL ; goto out;
@@ -159,7 +159,7 @@ static int __init configfs_init(void) err =configfs_inode_init ();if (err) {unregister_filesystem (&configfs_fs_type); -kobject_unregister (config_kobj); +kobject_put (config_kobj);kmem_cache_destroy (configfs_dir_cachep); configfs_dir_cachep =NULL ; }
@@ -170,7 +170,7 @@ out: static void __exit configfs_exit(void) {unregister_filesystem (&configfs_fs_type); -kobject_unregister (config_kobj); +kobject_put (config_kobj);kmem_cache_destroy (configfs_dir_cachep); configfs_dir_cachep =NULL ;configfs_inode_exit ();
fs/debugfs/inode.c +2 -2
@@ -438,7 +438,7 @@ static int __init debugfs_init(void) retval =register_filesystem (&debug_fs_type);if (retval) -kobject_unregister (debug_kobj); +kobject_put (debug_kobj);return retval; }
@@ -446,7 +446,7 @@ static void __exit debugfs_exit(void) {simple_release_fs (&debugfs_mount, &debugfs_mount_count);unregister_filesystem (&debug_fs_type); -kobject_unregister (debug_kobj); +kobject_put (debug_kobj); }core_initcall (debugfs_init);
fs/dlm/lockspace.c +2 -2
@@ -579,7 +579,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,kfree (ls->ls_rsbtbl); out_lsfree:if (do_unreg) -kobject_unregister (&ls->ls_kobj); +kobject_put (&ls->ls_kobj);else kfree (ls); out:
@@ -728,7 +728,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)dlm_clear_members (ls);dlm_clear_members_gone (ls);kfree (ls->ls_node_array); -kobject_unregister (&ls->ls_kobj); +kobject_put (&ls->ls_kobj);/* The ls structure will be freed when the kobject is done with */ mutex_lock (&ls_lock);
fs/ecryptfs/main.c +2 -2
@@ -767,7 +767,7 @@ static int do_sysfs_registration(void)if (rc) {printk (KERN_ERR "Unable to create ecryptfs version attributes\n" ); -kobject_unregister (ecryptfs_kobj); +kobject_put (ecryptfs_kobj); } out:return rc;
@@ -776,7 +776,7 @@ out:static void do_sysfs_unregistration (void ) {sysfs_remove_group (ecryptfs_kobj, &attr_group); -kobject_unregister (ecryptfs_kobj); +kobject_put (ecryptfs_kobj); }static int __init ecryptfs_init (void )
fs/fuse/inode.c +3 -3
@@ -810,15 +810,15 @@ static int fuse_sysfs_init(void)return 0 ; out_fuse_unregister: -kobject_unregister (fuse_kobj); +kobject_put (fuse_kobj); out_err:return err; }static void fuse_sysfs_cleanup (void ) { -kobject_unregister (connections_kobj); -kobject_unregister (fuse_kobj); +kobject_put (connections_kobj); +kobject_put (fuse_kobj); }static int __init fuse_init (void )
fs/gfs2/locking/dlm/sysfs.c +1 -1
@@ -207,7 +207,7 @@ int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)void gdlm_kobject_release (struct gdlm_ls *ls) { -kobject_unregister (&ls->kobj); +kobject_put (&ls->kobj); }int gdlm_sysfs_init (void )
fs/gfs2/sys.c +2 -2
@@ -525,7 +525,7 @@ fail_counters: fail_lockstruct:sysfs_remove_group (&sdp->sd_kobj, &lockstruct_group); fail_reg: -kobject_unregister (&sdp->sd_kobj); +kobject_put (&sdp->sd_kobj); fail:fs_err (sdp,"error %d adding sysfs files" , error);return error;
@@ -537,7 +537,7 @@ void gfs2_sys_fs_del(struct gfs2_sbd *sdp)sysfs_remove_group (&sdp->sd_kobj, &args_group);sysfs_remove_group (&sdp->sd_kobj, &counters_group);sysfs_remove_group (&sdp->sd_kobj, &lockstruct_group); -kobject_unregister (&sdp->sd_kobj); +kobject_put (&sdp->sd_kobj); }int gfs2_sys_init (void )
fs/partitions/check.c +3 -3
@@ -314,7 +314,7 @@ void delete_partition(struct gendisk *disk, int part) p->nr_sects =0 ; p->ios[0 ] = p->ios[1 ] =0 ; p->sectors[0 ] = p->sectors[1 ] =0 ; -kobject_unregister (p->holder_dir); +kobject_put (p->holder_dir);device_del (&p->dev);put_device (&p->dev); }
@@ -505,8 +505,8 @@ void del_gendisk(struct gendisk *disk)disk_stat_set_all (disk,0 ); disk->stamp =0 ; -kobject_unregister (disk->holder_dir); -kobject_unregister (disk->slave_dir); +kobject_put (disk->holder_dir); +kobject_put (disk->slave_dir); disk->driverfs_dev =NULL ;#ifndef CONFIG_SYSFS_DEPRECATED sysfs_remove_link (block_depr, disk->dev.bus_id);
Signature · 1 line
1.5.3.8
PATCH 174/196 Kobject: convert remaining kobject_unregister() to kobject_put()
In reply to Greg KHThere is no need for kobject_unregister() anymore, thanks to Kay's kobject cleanup changes, so replace all instances of it with kobject_put().
--- kernel/ksysfs.c | 2 +- kernel/module.c | 9 ++++----- lib/kobject.c | 4 ++-- net/bridge/br_sysfs_br.c | 2 +- security/inode.c | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-)
kernel/ksysfs.c +1 -1
@@ -154,7 +154,7 @@ notes_exit: group_exit:sysfs_remove_group (kernel_kobj, &kernel_attr_group); kset_exit: -kobject_unregister (kernel_kobj); +kobject_put (kernel_kobj); exit:return error; }
kernel/module.c +4 -5
@@ -1257,9 +1257,8 @@ int mod_sysfs_setup(struct module *mod, out_unreg_param:module_param_sysfs_remove (mod); out_unreg_holders: -kobject_unregister (mod->holders_dir); +kobject_put (mod->holders_dir); out_unreg: -kobject_del (&mod->mkobj.kobj);kobject_put (&mod->mkobj.kobj);return err; }
@@ -1269,9 +1268,9 @@ static void mod_kobject_remove(struct module *mod) {module_remove_modinfo_attrs (mod);module_param_sysfs_remove (mod); -kobject_unregister (mod->mkobj.drivers_dir); -kobject_unregister (mod->holders_dir); -kobject_unregister (&mod->mkobj.kobj); +kobject_put (mod->mkobj.drivers_dir); +kobject_put (mod->holders_dir); +kobject_put (&mod->mkobj.kobj); }/*
lib/kobject.c +2 -2
@@ -664,7 +664,7 @@ struct kobject *kobject_create(void)* * This function creates a kset structure dynamically and registers it * with sysfs. When you are finished with this structure, call -* kobject_unregister() and the structure will be dynamically freed when +* kobject_put() and the structure will be dynamically freed when * it is no longer being used. * * If the kobject was not able to be created, NULL will be returned.
@@ -761,7 +761,7 @@ void kset_unregister(struct kset * k) {if (!k)return ; -kobject_unregister (&k->kobj); +kobject_put (&k->kobj); }
net/bridge/br_sysfs_br.c +1 -1
@@ -447,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)struct kobject *kobj = &dev->dev.kobj;struct net_bridge *br =netdev_priv (dev); -kobject_unregister (br->ifobj); +kobject_put (br->ifobj);sysfs_remove_bin_file (kobj, &bridge_forward);sysfs_remove_group (kobj, &bridge_group); }
security/inode.c +1 -1
@@ -327,7 +327,7 @@ static int __init securityfs_init(void) retval =register_filesystem (&fs_type);if (retval) -kobject_unregister (security_kobj); +kobject_put (security_kobj);return retval; }
Signature · 1 line
1.5.3.8
PATCH 175/196 Kobject: remove kobject_unregister() as no one uses it anymore
In reply to Greg KHThere are no in-kernel users of kobject_unregister() so it should be removed.
--- include/linux/kobject.h | 2 -- lib/kobject.c | 17 ----------------- 2 files changed, 0 insertions(+), 19 deletions(-)
include/linux/kobject.h +0 -2
@@ -101,8 +101,6 @@ extern struct kobject * __must_check kobject_create_and_add(const char *name,extern int __must_check kobject_rename (struct kobject *,const char *new_name);extern int __must_check kobject_move (struct kobject *,struct kobject *); -extern void kobject_unregister (struct kobject *); -extern struct kobject *kobject_get (struct kobject *);extern void kobject_put (struct kobject *);
lib/kobject.c +0 -17
@@ -533,22 +533,6 @@ void kobject_del(struct kobject * kobj) }/** -* kobject_unregister - remove object from hierarchy and decrement refcount. -* @kobj: object going away. -*/ - -void kobject_unregister (struct kobject * kobj) -{ -if (!kobj) -return ; -pr_debug ("kobject: '%s' (%p): %s\n" , -kobject_name (kobj), kobj, __FUNCTION__); -kobject_uevent (kobj,KOBJ_REMOVE ); -kobject_del (kobj); -kobject_put (kobj); -} - -/** * kobject_get - increment refcount for object. * @kobj: object. */
@@ -877,7 +861,6 @@ struct kset *kset_create_and_add(const char *name, }EXPORT_SYMBOL_GPL (kset_create_and_add); -EXPORT_SYMBOL (kobject_unregister);EXPORT_SYMBOL (kobject_get);EXPORT_SYMBOL (kobject_put);EXPORT_SYMBOL (kobject_del);
Signature · 1 line
1.5.3.8
PATCH 176/196 Driver core: change sysdev classes to use dynamic kobject names
In reply to Greg KHFrom: Kay Sievers <[email protected]>
All kobjects require a dynamically allocated name now. We no longer need to keep track if the name is statically assigned, we can just unconditionally free() all kobject names on cleanup.
--- arch/arm/kernel/time.c | 4 ++-- arch/arm/mach-integrator/integrator_ap.c | 2 +- arch/arm/mach-pxa/cm-x270.c | 2 +- arch/arm/mach-pxa/lpd270.c | 2 +- arch/arm/mach-pxa/lubbock.c | 2 +- arch/arm/mach-pxa/mainstone.c | 2 +- arch/arm/mach-s3c2410/s3c2410.c | 2 +- arch/arm/mach-s3c2412/s3c2412.c | 2 +- arch/arm/mach-s3c2440/mach-osiris.c | 2 +- arch/arm/mach-s3c2443/s3c2443.c | 2 +- arch/arm/mach-sa1100/irq.c | 2 +- arch/arm/oprofile/common.c | 2 +- arch/arm/plat-omap/gpio.c | 2 +- arch/arm/plat-s3c24xx/dma.c | 2 +- arch/arm/plat-s3c24xx/s3c244x.c | 4 ++-- arch/avr32/kernel/time.c | 2 +- arch/mips/kernel/i8259.c | 2 +- arch/powerpc/platforms/cell/spu_base.c | 2 +- arch/powerpc/platforms/powermac/pic.c | 2 +- arch/powerpc/sysdev/ipic.c | 2 +- arch/powerpc/sysdev/mpic.c | 2 +- arch/powerpc/sysdev/qe_lib/qe_ic.c | 2 +- arch/ppc/syslib/ipic.c | 2 +- arch/ppc/syslib/open_pic.c | 2 +- arch/ppc/syslib/open_pic2.c | 2 +- arch/s390/kernel/time.c | 2 +- arch/sh/drivers/dma/dma-sysfs.c | 2 +- arch/sh/kernel/time.c | 2 +- arch/x86/kernel/apic_32.c | 2 +- arch/x86/kernel/apic_64.c | 2 +- arch/x86/kernel/cpu/mcheck/mce_64.c | 2 +- arch/x86/kernel/i8237.c | 2 +- arch/x86/kernel/i8259_32.c | 2 +- arch/x86/kernel/i8259_64.c | 2 +- arch/x86/kernel/io_apic_32.c | 2 +- arch/x86/kernel/io_apic_64.c | 2 +- arch/x86/kernel/nmi_32.c | 2 +- arch/x86/kernel/nmi_64.c | 2 +- arch/x86/oprofile/nmi_int.c | 2 +- drivers/acpi/pci_link.c | 2 +- drivers/base/class.c | 2 +- drivers/base/cpu.c | 2 +- drivers/base/memory.c | 2 +- drivers/base/node.c | 2 +- drivers/base/sys.c | 1 + drivers/edac/edac_module.c | 2 +- drivers/kvm/kvm_main.c | 2 +- drivers/macintosh/via-pmu.c | 2 +- drivers/scsi/libsas/sas_scsi_host.c | 2 +- include/linux/kobject.h | 13 ++----------- include/linux/sysdev.h | 1 + kernel/rtmutex-tester.c | 2 +- kernel/time/clocksource.c | 2 +- kernel/time/timekeeping.c | 2 +- lib/kobject.c | 14 +++++--------- 55 files changed, 62 insertions(+), 73 deletions(-)
arch/arm/kernel/time.c +2 -2
@@ -195,7 +195,7 @@ static int leds_shutdown(struct sys_device *dev) }static struct sysdev_class leds_sysclass = { -set_kset_name ("leds" ), + .name ="leds" , .shutdown = leds_shutdown, .suspend = leds_suspend, .resume = leds_resume,
@@ -369,7 +369,7 @@ static int timer_resume(struct sys_device *dev)#endif static struct sysdev_class timer_sysclass = { -set_kset_name ("timer" ), + .name ="timer" , .suspend = timer_suspend, .resume = timer_resume, };
arch/arm/mach-integrator/integrator_ap.c +1 -1
@@ -214,7 +214,7 @@ static int irq_resume(struct sys_device *dev)#endif static struct sysdev_class irq_class = { -set_kset_name ("irq" ), + .name ="irq" , .suspend = irq_suspend, .resume = irq_resume, };
arch/arm/mach-pxa/cm-x270.c +1 -1
@@ -566,7 +566,7 @@ static int cmx270_resume(struct sys_device *dev) }static struct sysdev_class cmx270_pm_sysclass = { -set_kset_name ("pm" ), + .name ="pm" , .resume = cmx270_resume, .suspend = cmx270_suspend, };
arch/arm/mach-pxa/lpd270.c +1 -1
@@ -122,7 +122,7 @@ static int lpd270_irq_resume(struct sys_device *dev) }static struct sysdev_class lpd270_irq_sysclass = { -set_kset_name ("cpld_irq" ), + .name ="cpld_irq" , .resume = lpd270_irq_resume, };
arch/arm/mach-pxa/lubbock.c +1 -1
@@ -126,7 +126,7 @@ static int lubbock_irq_resume(struct sys_device *dev) }static struct sysdev_class lubbock_irq_sysclass = { -set_kset_name ("cpld_irq" ), + .name ="cpld_irq" , .resume = lubbock_irq_resume, };
arch/arm/mach-pxa/mainstone.c +1 -1
@@ -120,7 +120,7 @@ static int mainstone_irq_resume(struct sys_device *dev) }static struct sysdev_class mainstone_irq_sysclass = { -set_kset_name ("cpld_irq" ), + .name ="cpld_irq" , .resume = mainstone_irq_resume, };
arch/arm/mach-s3c2410/s3c2410.c +1 -1
@@ -100,7 +100,7 @@ void __init s3c2410_init_clocks(int xtal) }struct sysdev_class s3c2410_sysclass = { -set_kset_name ("s3c2410-core" ), + .name ="s3c2410-core" , };static struct sys_device s3c2410_sysdev = {
arch/arm/mach-s3c2412/s3c2412.c +1 -1
@@ -196,7 +196,7 @@ void __init s3c2412_init_clocks(int xtal)*/ struct sysdev_class s3c2412_sysclass = { -set_kset_name ("s3c2412-core" ), + .name ="s3c2412-core" , };static int __init s3c2412_core_init (void )
arch/arm/mach-s3c2440/mach-osiris.c +1 -1
@@ -312,7 +312,7 @@ static int osiris_pm_resume(struct sys_device *sd)#endif static struct sysdev_class osiris_pm_sysclass = { -set_kset_name ("mach-osiris" ), + .name ="mach-osiris" , .suspend = osiris_pm_suspend, .resume = osiris_pm_resume, };
arch/arm/mach-s3c2443/s3c2443.c +1 -1
@@ -43,7 +43,7 @@ static struct map_desc s3c2443_iodesc[] __initdata = { };struct sysdev_class s3c2443_sysclass = { -set_kset_name ("s3c2443-core" ), + .name ="s3c2443-core" , };static struct sys_device s3c2443_sysdev = {
arch/arm/mach-sa1100/irq.c +1 -1
@@ -283,7 +283,7 @@ static int sa1100irq_resume(struct sys_device *dev) }static struct sysdev_class sa1100irq_sysclass = { -set_kset_name ("sa11x0-irq" ), + .name ="sa11x0-irq" , .suspend = sa1100irq_suspend, .resume = sa1100irq_resume, };
arch/arm/oprofile/common.c +1 -1
@@ -96,7 +96,7 @@ static int op_arm_resume(struct sys_device *dev) }static struct sysdev_class oprofile_sysclass = { -set_kset_name ("oprofile" ), + .name ="oprofile" , .resume = op_arm_resume, .suspend = op_arm_suspend, };
arch/arm/plat-omap/gpio.c +1 -1
@@ -1455,7 +1455,7 @@ static int omap_gpio_resume(struct sys_device *dev) }static struct sysdev_class omap_gpio_sysclass = { -set_kset_name ("gpio" ), + .name ="gpio" , .suspend = omap_gpio_suspend, .resume = omap_gpio_resume, };
arch/arm/plat-s3c24xx/dma.c +1 -1
@@ -1265,7 +1265,7 @@ static int s3c2410_dma_resume(struct sys_device *dev)#endif /* CONFIG_PM */ struct sysdev_class dma_sysclass = { -set_kset_name ("s3c24xx-dma" ), + .name ="s3c24xx-dma" , .suspend = s3c2410_dma_suspend, .resume = s3c2410_dma_resume, };
arch/arm/plat-s3c24xx/s3c244x.c +2 -2
@@ -151,13 +151,13 @@ static int s3c244x_resume(struct sys_device *dev)/* Since the S3C2442 and S3C2440 share items, put both sysclasses here */ struct sysdev_class s3c2440_sysclass = { -set_kset_name ("s3c2440-core" ), + .name ="s3c2440-core" , .suspend = s3c244x_suspend, .resume = s3c244x_resume };struct sysdev_class s3c2442_sysclass = { -set_kset_name ("s3c2442-core" ), + .name ="s3c2442-core" , .suspend = s3c244x_suspend, .resume = s3c244x_resume };
arch/avr32/kernel/time.c +1 -1
@@ -214,7 +214,7 @@ void __init time_init(void) }static struct sysdev_class timer_class = { -set_kset_name ("timer" ), + .name ="timer" , };static struct sys_device timer_device = {
arch/mips/kernel/i8259.c +1 -1
@@ -238,7 +238,7 @@ static int i8259A_shutdown(struct sys_device *dev) }static struct sysdev_class i8259_sysdev_class = { -set_kset_name ("i8259" ), + .name ="i8259" , .resume = i8259A_resume, .shutdown = i8259A_shutdown, };
arch/powerpc/platforms/cell/spu_base.c +1 -1
@@ -459,7 +459,7 @@ static int spu_shutdown(struct sys_device *sysdev) }static struct sysdev_class spu_sysdev_class = { -set_kset_name ("spu" ), + .name ="spu" , .shutdown = spu_shutdown, };
arch/powerpc/platforms/powermac/pic.c +1 -1
@@ -663,7 +663,7 @@ static int pmacpic_resume(struct sys_device *sysdev)#endif /* CONFIG_PM && CONFIG_PPC32 */ static struct sysdev_class pmacpic_sysclass = { -set_kset_name ("pmac_pic" ), + .name ="pmac_pic" , };static struct sys_device device_pmacpic = {
arch/powerpc/sysdev/ipic.c +1 -1
@@ -725,7 +725,7 @@ unsigned int ipic_get_irq(void) }static struct sysdev_class ipic_sysclass = { -set_kset_name ("ipic" ), + .name ="ipic" , };static struct sys_device device_ipic = {
arch/powerpc/sysdev/mpic.c +1 -1
@@ -1584,7 +1584,7 @@ static struct sysdev_class mpic_sysclass = { .resume = mpic_resume, .suspend = mpic_suspend, #endif - set_kset_name("mpic"), + .name = "mpic", };static int mpic_init_sys (void )
arch/powerpc/sysdev/qe_lib/qe_ic.c +1 -1
@@ -483,7 +483,7 @@ int qe_ic_set_high_priority(unsigned int virq, unsigned int priority, int high) }static struct sysdev_class qe_ic_sysclass = { -set_kset_name ("qe_ic" ), + .name ="qe_ic" , };static struct sys_device device_qe_ic = {
arch/ppc/syslib/ipic.c +1 -1
@@ -614,7 +614,7 @@ int ipic_get_irq(void) }static struct sysdev_class ipic_sysclass = { -set_kset_name ("ipic" ), + .name ="ipic" , };static struct sys_device device_ipic = {
arch/ppc/syslib/open_pic.c +1 -1
@@ -1043,7 +1043,7 @@ int openpic_resume(struct sys_device *sysdev)#endif /* CONFIG_PM */ static struct sysdev_class openpic_sysclass = { -set_kset_name ("openpic" ), + .name ="openpic" , };static struct sys_device device_openpic = {
arch/ppc/syslib/open_pic2.c +1 -1
@@ -666,7 +666,7 @@ int openpic2_resume(struct sys_device *sysdev)/* HACK ALERT */ static struct sysdev_class openpic2_sysclass = { -set_kset_name ("openpic2" ), + .name ="openpic2" , };static struct sys_device device_openpic2 = {
arch/s390/kernel/time.c +1 -1
@@ -1145,7 +1145,7 @@ static void etr_work_fn(struct work_struct *work)* Sysfs interface functions */ static struct sysdev_class etr_sysclass = { -set_kset_name ("etr" ) + .name ="etr" , };static struct sys_device etr_port0_dev = {
arch/sh/drivers/dma/dma-sysfs.c +1 -1
@@ -19,7 +19,7 @@#include <asm/dma.h> static struct sysdev_class dma_sysclass = { -set_kset_name ("dma" ), + .name ="dma" , };EXPORT_SYMBOL (dma_sysclass);
arch/sh/kernel/time.c +1 -1
@@ -174,7 +174,7 @@ int timer_resume(struct sys_device *dev)#endif static struct sysdev_class timer_sysclass = { -set_kset_name ("timer" ), + .name ="timer" , .suspend = timer_suspend, .resume = timer_resume, };
arch/x86/kernel/apic_32.c +1 -1
@@ -1530,7 +1530,7 @@ static int lapic_resume(struct sys_device *dev)*/ static struct sysdev_class lapic_sysclass = { -set_kset_name ("lapic" ), + .name ="lapic" , .resume = lapic_resume, .suspend = lapic_suspend, };
arch/x86/kernel/apic_64.c +1 -1
@@ -639,7 +639,7 @@ static int lapic_resume(struct sys_device *dev) }static struct sysdev_class lapic_sysclass = { -set_kset_name ("lapic" ), + .name ="lapic" , .resume = lapic_resume, .suspend = lapic_suspend, };
arch/x86/kernel/cpu/mcheck/mce_64.c +1 -1
@@ -745,7 +745,7 @@ static void mce_restart(void)static struct sysdev_class mce_sysclass = { .resume = mce_resume, -set_kset_name ("machinecheck" ), + .name ="machinecheck" , }; DEFINE_PER_CPU(struct sys_device, device_mce);
arch/x86/kernel/i8237.c +1 -1
@@ -51,7 +51,7 @@ static int i8237A_suspend(struct sys_device *dev, pm_message_t state) }static struct sysdev_class i8237_sysdev_class = { -set_kset_name ("i8237" ), + .name ="i8237" , .suspend = i8237A_suspend, .resume = i8237A_resume, };
arch/x86/kernel/i8259_32.c +1 -1
@@ -258,7 +258,7 @@ static int i8259A_shutdown(struct sys_device *dev) }static struct sysdev_class i8259_sysdev_class = { -set_kset_name ("i8259" ), + .name ="i8259" , .suspend = i8259A_suspend, .resume = i8259A_resume, .shutdown = i8259A_shutdown,
arch/x86/kernel/i8259_64.c +1 -1
@@ -370,7 +370,7 @@ static int i8259A_shutdown(struct sys_device *dev) }static struct sysdev_class i8259_sysdev_class = { -set_kset_name ("i8259" ), + .name ="i8259" , .suspend = i8259A_suspend, .resume = i8259A_resume, .shutdown = i8259A_shutdown,
arch/x86/kernel/io_apic_32.c +1 -1
@@ -2401,7 +2401,7 @@ static int ioapic_resume(struct sys_device *dev) }static struct sysdev_class ioapic_sysdev_class = { -set_kset_name ("ioapic" ), + .name ="ioapic" , .suspend = ioapic_suspend, .resume = ioapic_resume, };
arch/x86/kernel/io_apic_64.c +1 -1
@@ -1850,7 +1850,7 @@ static int ioapic_resume(struct sys_device *dev) }static struct sysdev_class ioapic_sysdev_class = { -set_kset_name ("ioapic" ), + .name ="ioapic" , .suspend = ioapic_suspend, .resume = ioapic_resume, };
arch/x86/kernel/nmi_32.c +1 -1
@@ -176,7 +176,7 @@ static int lapic_nmi_resume(struct sys_device *dev)static struct sysdev_class nmi_sysclass = { -set_kset_name ("lapic_nmi" ), + .name ="lapic_nmi" , .resume = lapic_nmi_resume, .suspend = lapic_nmi_suspend, };
arch/x86/kernel/nmi_64.c +1 -1
@@ -211,7 +211,7 @@ static int lapic_nmi_resume(struct sys_device *dev) }static struct sysdev_class nmi_sysclass = { -set_kset_name ("lapic_nmi" ), + .name ="lapic_nmi" , .resume = lapic_nmi_resume, .suspend = lapic_nmi_suspend, };
arch/x86/oprofile/nmi_int.c +1 -1
@@ -51,7 +51,7 @@ static int nmi_resume(struct sys_device *dev)static struct sysdev_class oprofile_sysclass = { -set_kset_name ("oprofile" ), + .name ="oprofile" , .resume = nmi_resume, .suspend = nmi_suspend, };
drivers/acpi/pci_link.c +1 -1
@@ -911,7 +911,7 @@ __setup("acpi_irq_balance", acpi_irq_balance_set);/* FIXME: we will remove this interface after all drivers call pci_disable_device */ static struct sysdev_class irqrouter_sysdev_class = { -set_kset_name ("irqrouter" ), + .name ="irqrouter" , .resume = irqrouter_resume, };
drivers/base/class.c +1 -1
@@ -466,7 +466,6 @@ static struct kset_uevent_ops class_uevent_ops = {* entirely soon. */ static struct kset class_obj_subsys = { - .kobj = { .k_name ="class_obj" , }, .uevent_ops = &class_uevent_ops, };
@@ -872,6 +871,7 @@ int __init classes_init(void)/* ick, this is ugly, the things we go through to keep from showing up * in sysfs... */ kset_init (&class_obj_subsys); +kobject_set_name (&class_obj_subsys.kobj,"class_obj" );if (!class_obj_subsys.kobj.parent) class_obj_subsys.kobj.parent = &class_obj_subsys.kobj;return 0 ;
drivers/base/cpu.c +1 -1
@@ -14,7 +14,7 @@#include "base.h" struct sysdev_class cpu_sysdev_class = { -set_kset_name ("cpu" ), + .name ="cpu" , };EXPORT_SYMBOL (cpu_sysdev_class);
drivers/base/memory.c +1 -1
@@ -26,7 +26,7 @@#define MEMORY_CLASS_NAME "memory"static struct sysdev_class memory_sysdev_class = { -set_kset_name (MEMORY_CLASS_NAME ), + .name =MEMORY_CLASS_NAME , };static const char *memory_uevent_name (struct kset *kset,struct kobject *kobj)
drivers/base/node.c +1 -1
@@ -15,7 +15,7 @@#include <linux/device.h> static struct sysdev_class node_class = { -set_kset_name ("node" ), + .name ="node" , };
drivers/base/sys.c +1 -0
@@ -136,6 +136,7 @@ int sysdev_class_register(struct sysdev_class * cls) cls->kset.kobj.parent = &system_kset->kobj; cls->kset.kobj.ktype = &ktype_sysdev_class; cls->kset.kobj.kset = system_kset; +kobject_set_name (&cls->kset.kobj, cls->name);return kset_register (&cls->kset); }
drivers/edac/edac_module.c +1 -1
@@ -31,7 +31,7 @@ struct workqueue_struct *edac_workqueue;* need to export to other files in this modules */ static struct sysdev_class edac_class = { -set_kset_name ("edac" ), + .name ="edac" , };static int edac_class_valid;
drivers/kvm/kvm_main.c +1 -1
@@ -3451,7 +3451,7 @@ static int kvm_resume(struct sys_device *dev) }static struct sysdev_class kvm_sysdev_class = { -set_kset_name ("kvm" ), + .name ="kvm" , .suspend = kvm_suspend, .resume = kvm_resume, };
drivers/macintosh/via-pmu.c +1 -1
@@ -2796,7 +2796,7 @@ static int pmu_sys_resume(struct sys_device *sysdev)#endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */ static struct sysdev_class pmu_sysclass = { -set_kset_name ("pmu" ), + .name ="pmu" , };static struct sys_device device_pmu = {
drivers/scsi/libsas/sas_scsi_host.c +1 -1
@@ -464,7 +464,7 @@ int sas_eh_bus_reset_handler(struct scsi_cmnd *cmd) res =sas_phy_reset (phy,1 );if (res)SAS_DPRINTK ("Bus reset of %s failed 0x%x\n" , - phy->dev.kobj.k_name, +kobject_name (&phy->dev.kobj), res);if (res ==TMF_RESP_FUNC_SUCC || res ==TMF_RESP_FUNC_COMPLETE )return SUCCESS ;
include/linux/kobject.h +2 -11
@@ -61,7 +61,7 @@ enum kobject_action { };struct kobject { -const char * k_name; +const char *name;struct kref kref;struct list_head entry;struct kobject * parent;
@@ -69,7 +69,6 @@ struct kobject {struct kobj_type * ktype;struct sysfs_dirent * sd; unsigned int state_initialized:1; - unsigned int state_name_set:1; unsigned int state_in_sysfs:1; unsigned int state_add_uevent_sent:1; unsigned int state_remove_uevent_sent:1;
@@ -80,7 +79,7 @@ extern int kobject_set_name(struct kobject *, const char *, ...)static inline const char *kobject_name (const struct kobject * kobj) { -return kobj->k_name; +return kobj->name; }extern void kobject_init (struct kobject *kobj,struct kobj_type *ktype);
@@ -189,14 +188,6 @@ static inline struct kobj_type *get_ktype(struct kobject *kobj)extern struct kobject *kset_find_obj (struct kset *,const char *); - -/* -* Use this when initializing an embedded kset with no other -* fields to initialize. -*/ -#define set_kset_name (str) .kset = { .kobj = { .k_name = str } } - -/* The global /sys/kernel/ kobject for people to chain off of */ extern struct kobject *kernel_kobj;/* The global /sys/hypervisor/ kobject for people to chain off of */
include/linux/sysdev.h +1 -0
@@ -29,6 +29,7 @@struct sys_device ;struct sysdev_class { +const char *name;struct list_head drivers;/* Default operations for these types of devices */
kernel/rtmutex-tester.c +1 -1
@@ -394,7 +394,7 @@ static SYSDEV_ATTR(status, 0600, sysfs_test_status, NULL); static SYSDEV_ATTR(command, 0600, NULL, sysfs_test_command);static struct sysdev_class rttest_sysclass = { -set_kset_name ("rttest" ), + .name ="rttest" , };static int init_test_thread (int id)
kernel/time/clocksource.c +1 -1
@@ -441,7 +441,7 @@ static SYSDEV_ATTR(available_clocksource, 0600, sysfs_show_available_clocksources, NULL);static struct sysdev_class clocksource_sysclass = { -set_kset_name ("clocksource" ), + .name ="clocksource" , };static struct sys_device device_clocksource = {
kernel/time/timekeeping.c +1 -1
@@ -335,9 +335,9 @@ static int timekeeping_suspend(struct sys_device *dev, pm_message_t state)/* sysfs resume/suspend bits for timekeeping */ static struct sysdev_class timekeeping_sysclass = { + .name ="timekeeping" , .resume = timekeeping_resume, .suspend = timekeeping_suspend, -set_kset_name ("timekeeping" ), };static struct sys_device device_timer = {
lib/kobject.c +5 -9
@@ -165,7 +165,7 @@ static int kobject_add_internal(struct kobject *kobj)if (!kobj)return -ENOENT ; -if (!kobj->k_name || !kobj->k_name[0 ]) { +if (!kobj->name || !kobj->name[0 ]) {pr_debug ("kobject: (%p): attempted to be registered with empty " "name!\n" , kobj);WARN_ON (1 );
@@ -228,13 +228,11 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,if (!name)return -ENOMEM ; -/* Free the old name, if necessary. */ -kfree (kobj->k_name); +kfree (kobj->name);/* Now, set the new name */ - kobj->k_name = name; - kobj->state_name_set =1 ; + kobj->name = name;return 0 ; }
@@ -295,7 +293,6 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)kref_init (&kobj->kref);INIT_LIST_HEAD (&kobj->entry); kobj->ktype = ktype; - kobj->state_name_set =0 ; kobj->state_in_sysfs =0 ; kobj->state_add_uevent_sent =0 ; kobj->state_remove_uevent_sent =0 ;
@@ -551,8 +548,7 @@ struct kobject * kobject_get(struct kobject * kobj)static void kobject_cleanup (struct kobject *kobj) {struct kobj_type *t =get_ktype (kobj); -const char *name = kobj->k_name; -int name_set = kobj->state_name_set; +const char *name = kobj->name;pr_debug ("kobject: '%s' (%p): %s\n" ,kobject_name (kobj), kobj, __FUNCTION__);
@@ -583,7 +579,7 @@ static void kobject_cleanup(struct kobject *kobj) }/* free name if we allocated it */ -if (name_set && name) { +if (name) {pr_debug ("kobject: '%s': free name\n" , name);kfree (name); }
Signature · 1 line
1.5.3.8
PATCH 177/196 kobject: remove old, outdated documentation.
In reply to Greg KHAs we are replacing the documentation, it's easier to do this in a two stage pass, delete the old file and add the new one.
--- Documentation/kobject.txt | 289 --------------------------------------------- 1 files changed, 0 insertions(+), 289 deletions(-) delete mode 100644 Documentation/kobject.txt
Documentation/kobject.txt deleted +0 -289
@@ -1,289 +0,0 @@ -The kobject Infrastructure - -Patrick Mochel <[email protected]> - -Updated: 3 June 2003 - - -Copyright (c) 2003 Patrick Mochel -Copyright (c) 2003 Open Source Development Labs - - -0. Introduction - -The kobject infrastructure performs basic object management that larger -data structures and subsystems can leverage, rather than reimplement -similar functionality. This functionality primarily concerns: - -- Object reference counting. -- Maintaining lists (sets) of objects. -- Object set locking. -- Userspace representation. - -The infrastructure consists of a number of object types to support -this functionality. Their programming interfaces are described below -in detail, and briefly here: - -- kobjects a simple object. -- kset a set of objects of a certain type. -- ktype a set of helpers for objects of a common type. - - -The kobject infrastructure maintains a close relationship with the -sysfs filesystem. Each kobject that is registered with the kobject -core receives a directory in sysfs. Attributes about the kobject can -then be exported. Please see Documentation/filesystems/sysfs.txt for -more information. - -The kobject infrastructure provides a flexible programming interface, -and allows kobjects and ksets to be used without being registered -(i.e. with no sysfs representation). This is also described later. - - -1. kobjects - -1.1 Description - - -struct kobject is a simple data type that provides a foundation for -more complex object types. It provides a set of basic fields that -almost all complex data types share. kobjects are intended to be -embedded in larger data structures and replace fields they duplicate. - -1.2 Definition - -struct kobject { - const char * k_name; - struct kref kref; - struct list_head entry; - struct kobject * parent; - struct kset * kset; - struct kobj_type * ktype; - struct sysfs_dirent * sd; - wait_queue_head_t poll; -}; - -void kobject_init(struct kobject *); -int kobject_add(struct kobject *); -int kobject_register(struct kobject *); - -void kobject_del(struct kobject *); -void kobject_unregister(struct kobject *); - -struct kobject * kobject_get(struct kobject *); -void kobject_put(struct kobject *); - - -1.3 kobject Programming Interface - -kobjects may be dynamically added and removed from the kobject core -using kobject_register() and kobject_unregister(). Registration -includes inserting the kobject in the list of its dominant kset and -creating a directory for it in sysfs. - -Alternatively, one may use a kobject without adding it to its kset's list -or exporting it via sysfs, by simply calling kobject_init(). An -initialized kobject may later be added to the object hierarchy by -calling kobject_add(). An initialized kobject may be used for -reference counting. - -Note: calling kobject_init() then kobject_add() is functionally -equivalent to calling kobject_register(). - -When a kobject is unregistered, it is removed from its kset's list, -removed from the sysfs filesystem, and its reference count is decremented. -List and sysfs removal happen in kobject_del(), and may be called -manually. kobject_put() decrements the reference count, and may also -be called manually. - -A kobject's reference count may be incremented with kobject_get(), -which returns a valid reference to a kobject; and decremented with -kobject_put(). An object's reference count may only be incremented if -it is already positive. - -When a kobject's reference count reaches 0, the method struct -kobj_type::release() (which the kobject's kset points to) is called. -This allows any memory allocated for the object to be freed. - - -NOTE!!! - -It is _imperative_ that you supply a destructor for dynamically -allocated kobjects to free them if you are using kobject reference -counts. The reference count controls the lifetime of the object. -If it goes to 0, then it is assumed that the object will -be freed and cannot be used. - -More importantly, you must free the object there, and not immediately -after an unregister call. If someone else is referencing the object -(e.g. through a sysfs file), they will obtain a reference to the -object, assume it's valid and operate on it. If the object is -unregistered and freed in the meantime, the operation will then -reference freed memory and go boom. - -This can be prevented, in the simplest case, by defining a release -method and freeing the object from there only. Note that this will not -secure reference count/object management models that use a dual -reference count or do other wacky things with the reference count -(like the networking layer). - - -1.4 sysfs - -Each kobject receives a directory in sysfs. This directory is created -under the kobject's parent directory. - -If a kobject does not have a parent when it is registered, its parent -becomes its dominant kset. - -If a kobject does not have a parent nor a dominant kset, its directory -is created at the top-level of the sysfs partition. - - - -2. ksets - -2.1 Description - -A kset is a set of kobjects that are embedded in the same type. - - -struct kset { - struct kobj_type * ktype; - struct list_head list; - struct kobject kobj; - struct kset_uevent_ops * uevent_ops; -}; - - -void kset_init(struct kset * k); -int kset_add(struct kset * k); -int kset_register(struct kset * k); -void kset_unregister(struct kset * k); - -struct kset * kset_get(struct kset * k); -void kset_put(struct kset * k); - -struct kobject * kset_find_obj(struct kset *, char *); - - -The type that the kobjects are embedded in is described by the ktype -pointer. - -A kset contains a kobject itself, meaning that it may be registered in -the kobject hierarchy and exported via sysfs. More importantly, the -kset may be embedded in a larger data type, and may be part of another -kset (of that object type). - -For example, a block device is an object (struct gendisk) that is -contained in a set of block devices. It may also contain a set of -partitions (struct hd_struct) that have been found on the device. The -following code snippet illustrates how to express this properly. - - struct gendisk * disk; - ... - disk->kset.kobj.kset = &block_kset; - disk->kset.ktype = &partition_ktype; - kset_register(&disk->kset); - -- The kset that the disk's embedded object belongs to is the - block_kset, and is pointed to by disk->kset.kobj.kset. - -- The type of objects on the disk's _subordinate_ list are partitions, - and is set in disk->kset.ktype. - -- The kset is then registered, which handles initializing and adding - the embedded kobject to the hierarchy. - - -2.2 kset Programming Interface - -All kset functions, except kset_find_obj(), eventually forward the -calls to their embedded kobjects after performing kset-specific -operations. ksets offer a similar programming model to kobjects: they -may be used after they are initialized, without registering them in -the hierarchy. - -kset_find_obj() may be used to locate a kobject with a particular -name. The kobject, if found, is returned. - -There are also some helper functions which names point to the formerly -existing "struct subsystem", whose functions have been taken over by -ksets. - - -decl_subsys(name,type,uevent_ops) - -Declares a kset named '<name>_subsys' of type <type> with -uevent_ops <uevent_ops>. For example, - -decl_subsys(devices, &ktype_device, &device_uevent_ops); - -is equivalent to doing: - -struct kset devices_subsys = { - .ktype = &ktype_devices, - .uevent_ops = &device_uevent_ops, -}; -kobject_set_name(&devices_subsys, name); - -The objects that are registered with a subsystem that use the -subsystem's default list must have their kset ptr set properly. These -objects may have embedded kobjects or ksets. The -following helper makes setting the kset easier: - - -kobj_set_kset_s(obj,subsys) - -- Assumes that obj->kobj exists, and is a struct kobject. -- Sets the kset of that kobject to the kset <subsys>. - -int subsystem_register(struct kset *s); -void subsystem_unregister(struct kset *s); - -These are just wrappers around the respective kset_* functions. - -2.3 sysfs - -ksets are represented in sysfs when their embedded kobjects are -registered. They follow the same rules of parenting, with one -exception. If a kset does not have a parent, nor is its embedded -kobject part of another kset, the kset's parent becomes its dominant -subsystem. - -If the kset does not have a parent, its directory is created at the -sysfs root. This should only happen when the kset registered is -embedded in a subsystem itself. - - -3. struct ktype - -3.1. Description - -struct kobj_type { - void (*release)(struct kobject *); - struct sysfs_ops * sysfs_ops; - struct attribute ** default_attrs; -}; - - -Object types require specific functions for converting between the -generic object and the more complex type. struct kobj_type provides -the object-specific fields, which include: - -- release: Called when the kobject's reference count reaches 0. This - should convert the object to the more complex type and free it. - -- sysfs_ops: Provides conversion functions for sysfs access. Please - see the sysfs documentation for more information. - -- default_attrs: Default attributes to be exported via sysfs when the - object is registered.Note that the last attribute has to be - initialized to NULL ! You can find a complete implementation - in block/genhd.c - - -Instances of struct kobj_type are not registered; only referenced by -the kset. A kobj_type may be referenced by an arbitrary number of -ksets, as there may be disparate sets of identical objects. -
Signature · 1 line
1.5.3.8
PATCH 178/196 kobject: update the kobject/kset documentation
In reply to Greg KHThis provides a much-needed kobject and kset documentation update.
Thanks to Kay Sievers, Alan Stern, Jonathan Corbet, Randy Dunlap, Jan Engelhardt, and others for reviewing and providing help with this document.
--- Documentation/kobject.txt | 386 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 386 insertions(+), 0 deletions(-) create mode 100644 Documentation/kobject.txt
Documentation/kobject.txt new file +386 -0
@@ -0,0 +1,386 @@ +Everything you never wanted to know about kobjects, ksets, and ktypes + +Greg Kroah-Hartman <[email protected]> + +Based on an original article by Jon Corbet for lwn.net written October 1, +2003 and located at http://lwn.net/Articles/51437/ + +Last updated December 19, 2007 + + +Part of the difficulty in understanding the driver model - and the kobject +abstraction upon which it is built - is that there is no obvious starting +place. Dealing with kobjects requires understanding a few different types, +all of which make reference to each other. In an attempt to make things +easier, we'll take a multi-pass approach, starting with vague terms and +adding detail as we go. To that end, here are some quick definitions of +some terms we will be working with. + + - A kobject is an object of type struct kobject. Kobjects have a name + and a reference count. A kobject also has a parent pointer (allowing + objects to be arranged into hierarchies), a specific type, and, + usually, a representation in the sysfs virtual filesystem. + + Kobjects are generally not interesting on their own; instead, they are + usually embedded within some other structure which contains the stuff + the code is really interested in. + + No structure should EVER have more than one kobject embedded within it. + If it does, the reference counting for the object is sure to be messed + up and incorrect, and your code will be buggy. So do not do this. + + - A ktype is the type of object that embeds a kobject. Every structure + that embeds a kobject needs a corresponding ktype. The ktype controls + what happens to the kobject when it is created and destroyed. + + - A kset is a group of kobjects. These kobjects can be of the same ktype + or belong to different ktypes. The kset is the basic container type for + collections of kobjects. Ksets contain their own kobjects, but you can + safely ignore that implementation detail as the kset core code handles + this kobject automatically. + + When you see a sysfs directory full of other directories, generally each + of those directories corresponds to a kobject in the same kset. + +We'll look at how to create and manipulate all of these types. A bottom-up +approach will be taken, so we'll go back to kobjects. + + +Embedding kobjects + +It is rare for kernel code to create a standalone kobject, with one major +exception explained below. Instead, kobjects are used to control access to +a larger, domain-specific object. To this end, kobjects will be found +embedded in other structures. If you are used to thinking of things in +object-oriented terms, kobjects can be seen as a top-level, abstract class +from which other classes are derived. A kobject implements a set of +capabilities which are not particularly useful by themselves, but which are +nice to have in other objects. The C language does not allow for the +direct expression of inheritance, so other techniques - such as structure +embedding - must be used. + +So, for example, the UIO code has a structure that defines the memory +region associated with a uio device: + +struct uio_mem { + struct kobject kobj; + unsigned long addr; + unsigned long size; + int memtype; + void __iomem *internal_addr; +}; + +If you have a struct uio_mem structure, finding its embedded kobject is +just a matter of using the kobj member. Code that works with kobjects will +often have the opposite problem, however: given a struct kobject pointer, +what is the pointer to the containing structure? You must avoid tricks +(such as assuming that the kobject is at the beginning of the structure) +and, instead, use the container_of() macro, found in <linux/kernel.h>: + + container_of(pointer, type, member) + +where pointer is the pointer to the embedded kobject, type is the type of +the containing structure, and member is the name of the structure field to +which pointer points. The return value from container_of() is a pointer to +the given type. So, for example, a pointer "kp" to a struct kobject +embedded within a struct uio_mem could be converted to a pointer to the +containing uio_mem structure with: + + struct uio_mem *u_mem = container_of(kp, struct uio_mem, kobj); + +Programmers often define a simple macro for "back-casting" kobject pointers +to the containing type. + + +Initialization of kobjects + +Code which creates a kobject must, of course, initialize that object. Some +of the internal fields are setup with a (mandatory) call to kobject_init(): + + void kobject_init(struct kobject *kobj, struct kobj_type *ktype); + +The ktype is required for a kobject to be created properly, as every kobject +must have an associated kobj_type. After calling kobject_init(), to +register the kobject with sysfs, the function kobject_add() must be called: + + int kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...); + +This sets up the parent of the kobject and the name for the kobject +properly. If the kobject is to be associated with a specific kset, +kobj->kset must be assigned before calling kobject_add(). If a kset is +associated with a kobject, then the parent for the kobject can be set to +NULL in the call to kobject_add() and then the kobject's parent will be the +kset itself. + +As the name of the kobject is set when it is added to the kernel, the name +of the kobject should never be manipulated directly. If you must change +the name of the kobject, call kobject_rename(): + + int kobject_rename(struct kobject *kobj, const char *new_name); + +There is a function called kobject_set_name() but that is legacy cruft and +is being removed. If your code needs to call this function, it is +incorrect and needs to be fixed. + +To properly access the name of the kobject, use the function +kobject_name(): + + const char *kobject_name(const struct kobject * kobj); + +There is a helper function to both initialize and add the kobject to the +kernel at the same time, called supprisingly enough kobject_init_and_add(): + + int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, + struct kobject *parent, const char *fmt, ...); + +The arguments are the same as the individual kobject_init() and +kobject_add() functions described above. + + +Uevents + +After a kobject has been registered with the kobject core, you need to +announce to the world that it has been created. This can be done with a +call to kobject_uevent(): + + int kobject_uevent(struct kobject *kobj, enum kobject_action action); + +Use the KOBJ_ADD action for when the kobject is first added to the kernel. +This should be done only after any attributes or children of the kobject +have been initialized properly, as userspace will instantly start to look +for them when this call happens. + +When the kobject is removed from the kernel (details on how to do that is +below), the uevent for KOBJ_REMOVE will be automatically created by the +kobject core, so the caller does not have to worry about doing that by +hand. + + +Reference counts + +One of the key functions of a kobject is to serve as a reference counter +for the object in which it is embedded. As long as references to the object +exist, the object (and the code which supports it) must continue to exist. +The low-level functions for manipulating a kobject's reference counts are: + + struct kobject *kobject_get(struct kobject *kobj); + void kobject_put(struct kobject *kobj); + +A successful call to kobject_get() will increment the kobject's reference +counter and return the pointer to the kobject. + +When a reference is released, the call to kobject_put() will decrement the +reference count and, possibly, free the object. Note that kobject_init() +sets the reference count to one, so the code which sets up the kobject will +need to do a kobject_put() eventually to release that reference. + +Because kobjects are dynamic, they must not be declared statically or on +the stack, but instead, always allocated dynamically. Future versions of +the kernel will contain a run-time check for kobjects that are created +statically and will warn the developer of this improper usage. + +If all that you want to use a kobject for is to provide a reference counter +for your structure, please use the struct kref instead; a kobject would be +overkill. For more information on how to use struct kref, please see the +file Documentation/kref.txt in the Linux kernel source tree. + + +Creating "simple" kobjects + +Sometimes all that a developer wants is a way to create a simple directory +in the sysfs hierarchy, and not have to mess with the whole complication of +ksets, show and store functions, and other details. This is the one +exception where a single kobject should be created. To create such an +entry, use the function: + + struct kobject *kobject_create_and_add(char *name, struct kobject *parent); + +This function will create a kobject and place it in sysfs in the location +underneath the specified parent kobject. To create simple attributes +associated with this kobject, use: + + int sysfs_create_file(struct kobject *kobj, struct attribute *attr); +or + int sysfs_create_group(struct kobject *kobj, struct attribute_group *grp); + +Both types of attributes used here, with a kobject that has been created +with the kobject_create_and_add(), can be of type kobj_attribute, so no +special custom attribute is needed to be created. + +See the example module, samples/kobject/kobject-example.c for an +implementation of a simple kobject and attributes. + + + +ktypes and release methods + +One important thing still missing from the discussion is what happens to a +kobject when its reference count reaches zero. The code which created the +kobject generally does not know when that will happen; if it did, there +would be little point in using a kobject in the first place. Even +predictable object lifecycles become more complicated when sysfs is brought +in as other portions of the kernel can get a reference on any kobject that +is registered in the system. + +The end result is that a structure protected by a kobject cannot be freed +before its reference count goes to zero. The reference count is not under +the direct control of the code which created the kobject. So that code must +be notified asynchronously whenever the last reference to one of its +kobjects goes away. + +Once you registered your kobject via kobject_add(), you must never use +kfree() to free it directly. The only safe way is to use kobject_put(). It +is good practice to always use kobject_put() after kobject_init() to avoid +errors creeping in. + +This notification is done through a kobject's release() method. Usually +such a method has a form like: + + void my_object_release(struct kobject *kobj) + { + struct my_object *mine = container_of(kobj, struct my_object, kobj); + + /* Perform any additional cleanup on this object, then... */ + kfree(mine); + } + +One important point cannot be overstated: every kobject must have a +release() method, and the kobject must persist (in a consistent state) +until that method is called. If these constraints are not met, the code is +flawed. Note that the kernel will warn you if you forget to provide a +release() method. Do not try to get rid of this warning by providing an +"empty" release function; you will be mocked mercilessly by the kobject +maintainer if you attempt this. + +Note, the name of the kobject is available in the release function, but it +must NOT be changed within this callback. Otherwise there will be a memory +leak in the kobject core, which makes people unhappy. + +Interestingly, the release() method is not stored in the kobject itself; +instead, it is associated with the ktype. So let us introduce struct +kobj_type: + + struct kobj_type { + void (*release)(struct kobject *); + struct sysfs_ops *sysfs_ops; + struct attribute **default_attrs; + }; + +This structure is used to describe a particular type of kobject (or, more +correctly, of containing object). Every kobject needs to have an associated +kobj_type structure; a pointer to that structure must be specified when you +call kobject_init() or kobject_init_and_add(). + +The release field in struct kobj_type is, of course, a pointer to the +release() method for this type of kobject. The other two fields (sysfs_ops +and default_attrs) control how objects of this type are represented in +sysfs; they are beyond the scope of this document. + +The default_attrs pointer is a list of default attributes that will be +automatically created for any kobject that is registered with this ktype. + + +ksets + +A kset is merely a collection of kobjects that want to be associated with +each other. There is no restriction that they be of the same ktype, but be +very careful if they are not. + +A kset serves these functions: + + - It serves as a bag containing a group of objects. A kset can be used by + the kernel to track "all block devices" or "all PCI device drivers." + + - A kset is also a subdirectory in sysfs, where the associated kobjects + with the kset can show up. Every kset contains a kobject which can be + set up to be the parent of other kobjects; the top-level directories of + the sysfs hierarchy are constructed in this way. + + - Ksets can support the "hotplugging" of kobjects and influence how + uevent events are reported to user space. + +In object-oriented terms, "kset" is the top-level container class; ksets +contain their own kobject, but that kobject is managed by the kset code and +should not be manipulated by any other user. + +A kset keeps its children in a standard kernel linked list. Kobjects point +back to their containing kset via their kset field. In almost all cases, +the kobjects belonging to a ket have that kset (or, strictly, its embedded +kobject) in their parent. + +As a kset contains a kobject within it, it should always be dynamically +created and never declared statically or on the stack. To create a new +kset use: + struct kset *kset_create_and_add(const char *name, + struct kset_uevent_ops *u, + struct kobject *parent); + +When you are finished with the kset, call: + void kset_unregister(struct kset *kset); +to destroy it. + +An example of using a kset can be seen in the +samples/kobject/kset-example.c file in the kernel tree. + +If a kset wishes to control the uevent operations of the kobjects +associated with it, it can use the struct kset_uevent_ops to handle it: + +struct kset_uevent_ops { + int (*filter)(struct kset *kset, struct kobject *kobj); + const char *(*name)(struct kset *kset, struct kobject *kobj); + int (*uevent)(struct kset *kset, struct kobject *kobj, + struct kobj_uevent_env *env); +}; + + +The filter function allows a kset to prevent a uevent from being emitted to +userspace for a specific kobject. If the function returns 0, the uevent +will not be emitted. + +The name function will be called to override the default name of the kset +that the uevent sends to userspace. By default, the name will be the same +as the kset itself, but this function, if present, can override that name. + +The uevent function will be called when the uevent is about to be sent to +userspace to allow more environment variables to be added to the uevent. + +One might ask how, exactly, a kobject is added to a kset, given that no +functions which perform that function have been presented. The answer is +that this task is handled by kobject_add(). When a kobject is passed to +kobject_add(), its kset member should point to the kset to which the +kobject will belong. kobject_add() will handle the rest. + +If the kobject belonging to a kset has no parent kobject set, it will be +added to the kset's directory. Not all members of a kset do necessarily +live in the kset directory. If an explicit parent kobject is assigned +before the kobject is added, the kobject is registered with the kset, but +added below the parent kobject. + + +Kobject removal + +After a kobject has been registered with the kobject core successfully, it +must be cleaned up when the code is finished with it. To do that, call +kobject_put(). By doing this, the kobject core will automatically clean up +all of the memory allocated by this kobject. If a KOBJ_ADD uevent has been +sent for the object, a corresponding KOBJ_REMOVE uevent will be sent, and +any other sysfs housekeeping will be handled for the caller properly. + +If you need to do a two-stage delete of the kobject (say you are not +allowed to sleep when you need to destroy the object), then call +kobject_del() which will unregister the kobject from sysfs. This makes the +kobject "invisible", but it is not cleaned up, and the reference count of +the object is still the same. At a later time call kobject_put() to finish +the cleanup of the memory associated with the kobject. + +kobject_del() can be used to drop the reference to the parent object, if +circular references are constructed. It is valid in some cases, that a +parent objects references a child. Circular references _must_ be broken +with an explicit call to kobject_del(), so that a release functions will be +called, and the objects in the former circle release each other. + + +Example code to copy from + +For a more complete example of using ksets and kobjects properly, see the +sample/kobject/kset-example.c code.
Signature · 1 line
1.5.3.8
PATCH 179/196 kobject: add sample code for how to use kobjects in a simple manner.
In reply to Greg KHThis is a simple kobject module, showing how to use kobj_attributes in basic and more complex ways.
--- samples/Kconfig | 10 +++ samples/Makefile | 2 +- samples/kobject/Makefile | 1 + samples/kobject/kobject-example.c | 137 +++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 1 deletions(-) create mode 100644 samples/kobject/Makefile create mode 100644 samples/kobject/kobject-example.c
samples/Kconfig +10 -0
@@ -13,4 +13,14 @@ config SAMPLE_MARKERS help This build markers example modules. +config SAMPLE_KOBJECT + tristate "Build kobject examples" + help + This config option will allow you to build a number of + different kobject sample modules showing how to use kobjects, + ksets, and ktypes properly. + + If in doubt, say "N" here. + endif # SAMPLES +
samples/Makefile +1 -1
@@ -1,3 +1,3 @@ # Makefile for Linux samples code -obj-$(CONFIG_SAMPLES) += markers/ +obj-$(CONFIG_SAMPLES) += markers/ kobject/
samples/kobject/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_SAMPLE_KOBJECT) += kobject-example.o
samples/kobject/kobject-example.c new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
1.5.3.8
PATCH 180/196 kobject: add sample code for how to use ksets/ktypes/kobjects
In reply to Greg KHThis is a more complex example showing how to create a kset and a ktype and some default attributes for a group of kobjects.
--- samples/kobject/Makefile | 2 +- samples/kobject/kset-example.c | 278 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 279 insertions(+), 1 deletions(-) create mode 100644 samples/kobject/kset-example.c
samples/kobject/Makefile +1 -1
@@ -1 +1 @@ -obj-$(CONFIG_SAMPLE_KOBJECT) += kobject-example.o +obj-$(CONFIG_SAMPLE_KOBJECT) += kobject-example.o kset-example.o
samples/kobject/kset-example.c new file +278 -0
278 lines not on this page · raw message
Signature · 1 line
1.5.3.8
PATCH 181/196 Driver core: use LIST_HEAD instead of call to INIT_LIST_HEAD in __init
In reply to Greg KHFrom: Denis Cheng <[email protected]>
LIST_HEAD has been widely used, so switch to this simpler method.
--- drivers/base/attribute_container.c | 9 +-------- drivers/base/base.h | 1 - drivers/base/init.c | 1 - 3 files changed, 1 insertions(+), 10 deletions(-)
drivers/base/attribute_container.c +1 -8
@@ -61,7 +61,7 @@ attribute_container_classdev_to_container(struct class_device *classdev) }EXPORT_SYMBOL_GPL (attribute_container_classdev_to_container); -static struct list_head attribute_container_list; +static LIST_HEAD (attribute_container_list);static DEFINE_MUTEX (attribute_container_mutex);
@@ -429,10 +429,3 @@ attribute_container_find_class_device(struct attribute_container *cont,return cdev; }EXPORT_SYMBOL_GPL (attribute_container_find_class_device); - -int __init -attribute_container_init (void ) -{ -INIT_LIST_HEAD (&attribute_container_list); -return 0 ; -}
drivers/base/base.h +0 -1
@@ -49,7 +49,6 @@ static inline int hypervisor_init(void) { return 0; }extern int platform_bus_init (void );extern int system_bus_init (void );extern int cpu_dev_init (void ); -extern int attribute_container_init (void );extern int bus_add_device (struct device * dev);extern void bus_attach_device (struct device * dev);
drivers/base/init.c +0 -1
@@ -36,5 +36,4 @@ void __init driver_init(void)system_bus_init ();cpu_dev_init ();memory_dev_init (); -attribute_container_init (); }
Signature · 1 line
1.5.3.8
PATCH 182/196 sysfs: make SYSFS_DEPRECATED depend on SYSFS
In reply to Greg KHFrom: Randy Dunlap <[email protected]>
Make SYSFS_DEPRECATED depend on SYSFS since files that check CONFIG_SYSFS_DEPRECATED don't check for CONFIG_SYSFS first. Also don't prompt user about SYSFS_DEPRECATED if SYSFS=n.
--- init/Kconfig | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
init/Kconfig +1 -0
@@ -363,6 +363,7 @@ config CGROUP_CPUACCT config SYSFS_DEPRECATED bool "Create deprecated sysfs files" + depends on SYSFS default y help This option creates deprecated symlinks such as the
Signature · 1 line
1.5.3.8
PATCH 183/196 driver core: fix build with SYSFS=n
In reply to Greg KHFrom: Randy Dunlap <[email protected]>
When SYSFS=n and MODULES=y, build ends with:
linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function) make[3]: *** [drivers/base/module.o] Error 1
Below is one possible fix.
Build-tested with all 4 config combinations of SYSFS & MODULES.
--- drivers/base/Makefile | 2 ++ drivers/base/base.h | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-)
drivers/base/Makefile +2 -0
@@ -11,7 +11,9 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o obj-$(CONFIG_SMP) += topology.o +ifeq ($(CONFIG_SYSFS),y) obj-$(CONFIG_MODULES) += module.o +endif obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o ifeq ($(CONFIG_DEBUG_DRIVER),y)
drivers/base/base.h +1 -1
@@ -81,7 +81,7 @@ extern int devres_release_all(struct device *dev);extern struct kset *devices_kset; -#ifdef CONFIG_MODULES +#if defined(CONFIG_MODULES ) && defined(CONFIG_SYSFS )extern void module_add_driver (struct module *mod,struct device_driver *drv);extern void module_remove_driver (struct device_driver *drv);#else
Signature · 1 line
1.5.3.8
Re: [PATCH 183/196] driver core: fix build with SYSFS=n
Quoted 7 lines · Greg Kroah-Hartman
From: Randy Dunlap <[email protected]>
When SYSFS=n and MODULES=y, build ends with:
linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function) make[3]: *** [drivers/base/module.o] Error 1
_PLEASE_ fold such fixes into the patch that introduces the build bugs, prior sending your git trees upstream! (just like Andrew does it with all patches that come via -mm)
Changes like this (and it now leaked into Linus' tree as well) kill bisectability.
Thanks.
Ingo
Andrew Morton
maintainerRe: [PATCH 183/196] driver core: fix build with SYSFS=n
Quoted 12 lines · On Fri, 25 Jan 2008 23:25:30 +0100 Ingo Molnar <[email protected]> wrote:
Quoted 7 lines · Greg Kroah-Hartman
From: Randy Dunlap <[email protected]>
When SYSFS=n and MODULES=y, build ends with:
linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function) make[3]: *** [drivers/base/module.o] Error 1
Quoted 7 lines
_PLEASE_ fold such fixes into the patch that introduces the build bugs, prior sending your git trees upstream! (just like Andrew does it with all patches that come via -mm)
Changes like this (and it now leaked into Linus' tree as well) kill bisectability.
Absolutely - this is important. After several hours mucking about I just gave up trying to bisect a 2.6.24-rc1 regression due to hitting 100% build errors and runtime oopses during the bisection. Mainly from networking in that case.
Re: [PATCH 183/196] driver core: fix build with SYSFS=n
In reply to Ingo MolnarQuoted 7 lines · Ingo Molnar
Quoted 4 lines · Greg Kroah-Hartman
From: Randy Dunlap <[email protected]>
When SYSFS=n and MODULES=y, build ends with:
Quoted 7 lines
Quoted 3 lines
linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function) make[3]: *** [drivers/base/module.o] Error 1_PLEASE_ fold such fixes into the patch that introduces the build bugs, prior sending your git trees upstream! (just like Andrew does it with all patches that come via -mm)
For most of these issues I do merge them together.
However, for some odd kernel configurations, like this one, I didn't, my appologies. I'll try to be more careful in the future.
Quoted 2 lines
Changes like this (and it now leaked into Linus' tree as well) kill bisectability.
The odds that a "normal" person has sysfs turned off and modules enabled, trying to bisect things, is pretty slim :)
thanks,
greg k-h
Re: [PATCH 183/196] driver core: fix build with SYSFS=n
Quoted 5 lines · Greg KH
Quoted 2 lines
Changes like this (and it now leaked into Linus' tree as well) kill bisectability.
The odds that a "normal" person has sysfs turned off and modules enabled, trying to bisect things, is pretty slim :)
that "slim" combination is what i use for about 25% of all my bisections
- i build, boot and stress-test randconfig configs.
If i find a problem with a given .config, i do _not_ go around and change the .config to make a bisection point work. (and the automated bisection scripts definitely wont do it either.)
so what is a 'weird config' to you is a real testing barrier for others. And crap like that quickly mounts up. Having a buildable and bootable kernel at every bisection point is a _must_.
Please! :-)
Ingo
Re: [PATCH 183/196] driver core: fix build with SYSFS=n
Quoted 16 lines · Ingo Molnar
Quoted 5 lines · Greg KH
Quoted 2 lines
Changes like this (and it now leaked into Linus' tree as well) kill bisectability.
The odds that a "normal" person has sysfs turned off and modules enabled, trying to bisect things, is pretty slim :)
that "slim" combination is what i use for about 25% of all my bisections
- i build, boot and stress-test randconfig configs.If i find a problem with a given .config, i do _not_ go around and change the .config to make a bisection point work. (and the automated bisection scripts definitely wont do it either.)
Quoted 5 lines
so what is a 'weird config' to you is a real testing barrier for others. And crap like that quickly mounts up. Having a buildable and bootable kernel at every bisection point is a _must_.
Please! :-)
Yes, I do agree that this is important, I'll work to not let this happen again. Especially now that I have your build scripts, I'm working on setting up something like that myself here.
thanks,
greg k-h