[PATCH 1/2] uevent: improve error checking and handling
From: Eric Rannaud
Date: Sat Mar 03 2007 - 19:57:06 EST
Subject: uevent: improve error checking and handling
From: Eric Rannaud <eric.rannaud@xxxxxxxxx>
add_uevent_var() is used w/o checking for its return value, even though
it is possible for those calls to return -ENOMEM.
Signed-off-by: Eric Rannaud <eric.rannaud@xxxxxxxxx>
---
drivers/base/core.c | 93 ++++++++++++++++++++++++++++++++------------------
1 files changed, 59 insertions(+), 34 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index cf2a398..3a52332 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -162,18 +162,25 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
/* add the major/minor if present */
if (MAJOR(dev->devt)) {
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "MAJOR=%u", MAJOR(dev->devt));
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "MINOR=%u", MINOR(dev->devt));
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "MAJOR=%u", MAJOR(dev->devt));
+ if (retval)
+ return retval;
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "MINOR=%u", MINOR(dev->devt));
+ if (retval)
+ return retval;
}
- if (dev->driver)
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "DRIVER=%s", dev->driver->name);
+ if (dev->driver) {
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "DRIVER=%s", dev->driver->name);
+ if (retval)
+ return retval;
+ }
#ifdef CONFIG_SYSFS_DEPRECATED
if (dev->class) {
@@ -186,29 +193,41 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
const char *path;
path = kobject_get_path(&parent->kobj, GFP_KERNEL);
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "PHYSDEVPATH=%s", path);
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "PHYSDEVPATH=%s", path);
kfree(path);
-
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "PHYSDEVBUS=%s", parent->bus->name);
-
- if (parent->driver)
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "PHYSDEVDRIVER=%s", parent->driver->name);
+ if (retval)
+ return retval;
+
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "PHYSDEVBUS=%s", parent->bus->name);
+ if (retval)
+ return retval;
+
+ if (parent->driver) {
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "PHYSDEVDRIVER=%s", parent->driver->name);
+ if (retval)
+ return retval;
+ }
}
} else if (dev->bus) {
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "PHYSDEVBUS=%s", dev->bus->name);
-
- if (dev->driver)
- add_uevent_var(envp, num_envp, &i,
- buffer, buffer_size, &length,
- "PHYSDEVDRIVER=%s", dev->driver->name);
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "PHYSDEVBUS=%s", dev->bus->name);
+ if (retval)
+ return retval;
+
+ if (dev->driver) {
+ retval = add_uevent_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "PHYSDEVDRIVER=%s", dev->driver->name);
+ if (retval)
+ return retval;
+ }
}
#endif
@@ -222,27 +241,33 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
if (dev->bus && dev->bus->uevent) {
/* have the bus specific function add its stuff */
retval = dev->bus->uevent(dev, envp, num_envp, buffer, buffer_size);
- if (retval)
+ if (retval) {
pr_debug ("%s: bus uevent() returned %d\n",
__FUNCTION__, retval);
+ goto out;
+ }
}
if (dev->class && dev->class->dev_uevent) {
/* have the class specific function add its stuff */
retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size);
- if (retval)
+ if (retval) {
pr_debug("%s: class uevent() returned %d\n",
__FUNCTION__, retval);
+ goto out;
+ }
}
if (dev->type && dev->type->uevent) {
/* have the device type specific fuction add its stuff */
retval = dev->type->uevent(dev, envp, num_envp, buffer, buffer_size);
- if (retval)
+ if (retval) {
pr_debug("%s: dev_type uevent() returned %d\n",
__FUNCTION__, retval);
+ goto out;
+ }
}
-
+out:
return retval;
}
-
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/