Re: [RFC 1/2] kobject_set_name - error handling

Maneesh Soni
2004-05-08T09:57:19Z

On Fri, May 07, 2004 at 03:25:49PM -0700, Greg KH wrote:
> On Tue, May 04, 2004 at 11:09:08AM +0530, Maneesh Soni wrote:
> >
> > Greg, Are the patches fit for inclusion? I need to know this as my sysfs backing
> > store patches are taking back seats because of these changes, particulary the
> > one in second patch :-(.
>
> I'm awash in different patches from you. Can you try sending me the
> ones you think are good enough for inclusion right now? We can work
> from there.
>

Sorry Greg, for confusing you by sending multiple copies. Here we are talking
about two patches which cleans up the kobject_set_name() usuage in the routines
as mentioned below. The first one is appended here and the second one in the
next mail. I have complied and tested (booting) both the patches and hope they
are good for inclusion.

1) kobject_set_name-cleanup-01.patch

This patch corrects the following by checking the reutrn code from
kobject_set_name().

bus_add_driver()
bus_register()
sys_dev_register()

o The following patch cleansup the kobject_set_name() users. Basically checking
return code from kobject_set_name(). There can be error returns like -ENOMEM
or -EFAULT from kobject_set_name() if the name length exceeds KOBJ_NAME_LEN.

drivers/base/bus.c | 14 +++++++++++---
drivers/base/sys.c | 5 ++++-
2 files changed, 15 insertions(+), 4 deletions(-)

diff -puN drivers/base/sys.c~kobject_set_name-cleanup-01 drivers/base/sys.c
--- linux-2.6.6-rc3-mm2/drivers/base/sys.c~kobject_set_name-cleanup-01 2004-05-06 12:13:22.000000000 +0530
+++ linux-2.6.6-rc3-mm2-maneesh/drivers/base/sys.c 2004-05-06 12:13:22.000000000 +0530
@@ -180,8 +180,11 @@ int sysdev_register(struct sys_device *

/* But make sure we point to the right type for sysfs translation */
sysdev->kobj.ktype = &ktype_sysdev;
- kobject_set_name(&sysdev->kobj,"%s%d",
+ 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 */
diff -puN drivers/base/bus.c~kobject_set_name-cleanup-01 drivers/base/bus.c
--- linux-2.6.6-rc3-mm2/drivers/base/bus.c~kobject_set_name-cleanup-01 2004-05-06 12:13:22.000000000 +0530
+++ linux-2.6.6-rc3-mm2-maneesh/drivers/base/bus.c 2004-05-06 12:13:42.000000000 +0530
@@ -451,7 +451,11 @@ int bus_add_driver(struct device_driver

if (bus) {
pr_debug("bus %s: add driver %s\n",bus->name,drv->name);
- kobject_set_name(&drv->kobj,drv->name);
+ error = kobject_set_name(&drv->kobj,drv->name);
+ if (error) {
+ put_bus(bus);
+ return error;
+ }
drv->kobj.kset = &bus->drivers;
if ((error = kobject_register(&drv->kobj))) {
put_bus(bus);
@@ -555,7 +559,11 @@ struct bus_type * find_bus(char * name)
*/
int bus_register(struct bus_type * bus)
{
- kobject_set_name(&bus->subsys.kset.kobj,bus->name);
+ int error = 0;
+
+ error = kobject_set_name(&bus->subsys.kset.kobj,bus->name);
+ if (error)
+ return error;
subsys_set_kset(bus,bus_subsys);
subsystem_register(&bus->subsys);

@@ -569,7 +577,7 @@ int bus_register(struct bus_type * bus)
kset_register(&bus->drivers);

pr_debug("bus type '%s' registered\n",bus->name);
- return 0;
+ return error;
}

_

--
Maneesh Soni
IBM Linux Technology Center,
IBM India Software Lab, Bangalore.
Phone: +91-80-5044999 email: maneesh@in.ibm.com