Re: [PATCH] Driver Core update for 2.6.4-rc1

From: Greg KH
Date: Tue Mar 02 2004 - 23:56:37 EST


ChangeSet 1.1557.72.2, 2004/02/19 15:38:41-08:00, shemminger@xxxxxxxx

[PATCH] propogate errors from misc_register to caller

The patch to check for / in class_device is not enough.
The misc_register function needs to check return value of the things it calls!


drivers/char/misc.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)


diff -Nru a/drivers/char/misc.c b/drivers/char/misc.c
--- a/drivers/char/misc.c Tue Mar 2 19:52:14 2004
+++ b/drivers/char/misc.c Tue Mar 2 19:52:14 2004
@@ -212,6 +212,9 @@
int misc_register(struct miscdevice * misc)
{
struct miscdevice *c;
+ struct class_device *class;
+ dev_t dev;
+ int err;

down(&misc_sem);
list_for_each_entry(c, &misc_list, list) {
@@ -240,19 +243,30 @@
snprintf(misc->devfs_name, sizeof(misc->devfs_name),
"misc/%s", misc->name);
}
+ dev = MKDEV(MISC_MAJOR, misc->minor);

- class_simple_device_add(misc_class, MKDEV(MISC_MAJOR, misc->minor),
- misc->dev, misc->name);
- devfs_mk_cdev(MKDEV(MISC_MAJOR, misc->minor),
- S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP, misc->devfs_name);
+ class = class_simple_device_add(misc_class, dev,
+ misc->dev, misc->name);
+ if (IS_ERR(class)) {
+ err = PTR_ERR(class);
+ goto out;
+ }
+
+ err = devfs_mk_cdev(dev, S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP,
+ misc->devfs_name);
+ if (err) {
+ class_simple_device_remove(dev);
+ goto out;
+ }

/*
* Add it to the front, so that later devices can "override"
* earlier defaults
*/
list_add(&misc->list, &misc_list);
+ out:
up(&misc_sem);
- return 0;
+ return err;
}

/**

-
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/