]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[S390] dasd: fix bug in dasd initialization cleanup
authorStefan Weinhuber <wein@de.ibm.com>
Mon, 5 Feb 2007 20:17:04 +0000 (21:17 +0100)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 5 Feb 2007 20:17:04 +0000 (21:17 +0100)
The initialization of the dasd_eer code is one of the last steps of the
dasd driver initialization. When initialization fails in one of the
earlier steps, the dasd_exit function is called to clean up what has been
done so far. So the dasd_eer_exit function may be called, although the
dasd_eer_init function wasn't called before and dasd_eer_exit tries to
unregister a misc device that wasn't registered, which results in a BUG.

Make sure that dasd_eer_exit can be called without initialization. Use a
dynamically allocated struct miscdevice instead of a static one, so we
only try to unregister the device if it exists and was actually registered.

Signed-off-by: Stefan Weinhuber <wein@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/block/dasd_eer.c

index e0bf30ebb21521106229348d610f6e182dc1a656..6cedc914077e7c3f33e7385a5c84be73ba3c2e8a 100644 (file)
@@ -658,18 +658,24 @@ static struct file_operations dasd_eer_fops = {
        .owner          = THIS_MODULE,
 };
 
-static struct miscdevice dasd_eer_dev = {
-       .minor      = MISC_DYNAMIC_MINOR,
-       .name       = "dasd_eer",
-       .fops       = &dasd_eer_fops,
-};
+static struct miscdevice *dasd_eer_dev = NULL;
 
 int __init dasd_eer_init(void)
 {
        int rc;
 
-       rc = misc_register(&dasd_eer_dev);
+       dasd_eer_dev = kzalloc(sizeof(*dasd_eer_dev), GFP_KERNEL);
+       if (!dasd_eer_dev)
+               return -ENOMEM;
+
+       dasd_eer_dev->minor = MISC_DYNAMIC_MINOR;
+       dasd_eer_dev->name  = "dasd_eer";
+       dasd_eer_dev->fops  = &dasd_eer_fops;
+
+       rc = misc_register(dasd_eer_dev);
        if (rc) {
+               kfree(dasd_eer_dev);
+               dasd_eer_dev = NULL;
                MESSAGE(KERN_ERR, "%s", "dasd_eer_init could not "
                       "register misc device");
                return rc;
@@ -680,5 +686,9 @@ int __init dasd_eer_init(void)
 
 void dasd_eer_exit(void)
 {
-       WARN_ON(misc_deregister(&dasd_eer_dev) != 0);
+       if (dasd_eer_dev) {
+               WARN_ON(misc_deregister(dasd_eer_dev) != 0);
+               kfree(dasd_eer_dev);
+               dasd_eer_dev = NULL;
+       }
 }