lkml.org 
[lkml]   [2007]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH 1/2] uevent: improve error checking and handling
From
Subject: uevent: improve error checking and handling
From: Eric Rannaud <eric.rannaud@gmail.com>

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@gmail.com>
---
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-03-04 01:59    [from the cache]
©2003-2011 Jasper Spaans