[PATCH] avoid problems with kobject_set_name and name with %

From: Stephen Hemminger
Date: Fri Oct 08 2004 - 13:44:45 EST


kobject_set_name takes a printf style argument list. There are many
callers that pass only one string, if this string contained a '%' character
than bad things would happen. The fix is simple.

Signed-off-by: Stephen Hemminger <shemminger@xxxxxxxx>

diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c 2004-10-08 11:32:52 -07:00
+++ b/drivers/base/bus.c 2004-10-08 11:32:52 -07:00
@@ -515,7 +515,7 @@

if (bus) {
pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
- error = kobject_set_name(&drv->kobj, drv->name);
+ error = kobject_set_name(&drv->kobj, "%s", drv->name);
if (error) {
put_bus(bus);
return error;
@@ -664,7 +664,7 @@
{
int retval;

- retval = kobject_set_name(&bus->subsys.kset.kobj, bus->name);
+ retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name);
if (retval)
goto out;

diff -Nru a/drivers/base/class.c b/drivers/base/class.c
--- a/drivers/base/class.c 2004-10-08 11:32:52 -07:00
+++ b/drivers/base/class.c 2004-10-08 11:32:52 -07:00
@@ -139,7 +139,7 @@

INIT_LIST_HEAD(&cls->children);
INIT_LIST_HEAD(&cls->interfaces);
- error = kobject_set_name(&cls->subsys.kset.kobj, cls->name);
+ error = kobject_set_name(&cls->subsys.kset.kobj, "%s", cls->name);
if (error)
return error;

@@ -368,7 +368,7 @@
class_dev->class_id);

/* first, register with generic layer. */
- kobject_set_name(&class_dev->kobj, class_dev->class_id);
+ kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
if (parent)
class_dev->kobj.parent = &parent->subsys.kset.kobj;

diff -Nru a/drivers/base/core.c b/drivers/base/core.c
--- a/drivers/base/core.c 2004-10-08 11:32:52 -07:00
+++ b/drivers/base/core.c 2004-10-08 11:32:52 -07:00
@@ -221,7 +221,7 @@
pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);

/* first, register with generic layer. */
- kobject_set_name(&dev->kobj, dev->bus_id);
+ kobject_set_name(&dev->kobj, "%s", dev->bus_id);
if (parent)
dev->kobj.parent = &parent->kobj;

diff -Nru a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
--- a/drivers/firmware/efivars.c 2004-10-08 11:32:52 -07:00
+++ b/drivers/firmware/efivars.c 2004-10-08 11:32:52 -07:00
@@ -640,7 +640,7 @@
*(short_name + strlen(short_name)) = '-';
efi_guid_unparse(vendor_guid, short_name + strlen(short_name));

- kobject_set_name(&new_efivar->kobj, short_name);
+ kobject_set_name(&new_efivar->kobj, "%s", short_name);
kobj_set_kset_s(new_efivar, vars_subsys);
kobject_register(&new_efivar->kobj);

diff -Nru a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
--- a/drivers/pci/hotplug/pci_hotplug_core.c 2004-10-08 11:32:52 -07:00
+++ b/drivers/pci/hotplug/pci_hotplug_core.c 2004-10-08 11:32:52 -07:00
@@ -568,7 +568,7 @@
if ((slot->info == NULL) || (slot->ops == NULL))
return -EINVAL;

- kobject_set_name(&slot->kobj, slot->name);
+ kobject_set_name(&slot->kobj, "%s", slot->name);
kobj_set_kset_s(slot, pci_hotplug_slots_subsys);

/* this can fail if we have already registered a slot with the same name */
diff -Nru a/fs/sysfs/dir.c b/fs/sysfs/dir.c
--- a/fs/sysfs/dir.c 2004-10-08 11:32:52 -07:00
+++ b/fs/sysfs/dir.c 2004-10-08 11:32:52 -07:00
@@ -181,7 +181,7 @@
new_dentry = sysfs_get_dentry(parent, new_name);
if (!IS_ERR(new_dentry)) {
if (!new_dentry->d_inode) {
- error = kobject_set_name(kobj,new_name);
+ error = kobject_set_name(kobj, "%s", new_name);
if (!error)
d_move(kobj->dentry, new_dentry);
}
diff -Nru a/kernel/module.c b/kernel/module.c
--- a/kernel/module.c 2004-10-08 11:32:52 -07:00
+++ b/kernel/module.c 2004-10-08 11:32:52 -07:00
@@ -1119,7 +1119,7 @@
return -ENOMEM;

memset(&mod->mkobj->kobj, 0, sizeof(mod->mkobj->kobj));
- err = kobject_set_name(&mod->mkobj->kobj, mod->name);
+ err = kobject_set_name(&mod->mkobj->kobj, "%s", mod->name);
if (err)
goto out;
kobj_set_kset_s(mod->mkobj, module_subsys);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/