[media] ddbridge: fix error handling in module_init_ddbridge()
authorAlexey Khoroshilov <khoroshilov@ispras.ru>
Thu, 16 Aug 2012 20:05:38 +0000 (17:05 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 11 Sep 2012 18:29:00 +0000 (15:29 -0300)
If pci_register_driver() failed, resources allocated in
ddb_class_create() are leaked. The patch fixes it
as well as it replaces -1 with correct error code
in ddb_class_create().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/pci/ddbridge/ddbridge-core.c

index ebf3f05839d2c5416488b77df70c825dc01ae467..feff57ee5a083b55ec1c822b69807d4d1df84851 100644 (file)
@@ -1497,7 +1497,7 @@ static int ddb_class_create(void)
        ddb_class = class_create(THIS_MODULE, DDB_NAME);
        if (IS_ERR(ddb_class)) {
                unregister_chrdev(ddb_major, DDB_NAME);
-               return -1;
+               return PTR_ERR(ddb_class);
        }
        ddb_class->devnode = ddb_devnode;
        return 0;
@@ -1701,11 +1701,18 @@ static struct pci_driver ddb_pci_driver = {
 
 static __init int module_init_ddbridge(void)
 {
+       int ret;
+
        printk(KERN_INFO "Digital Devices PCIE bridge driver, "
               "Copyright (C) 2010-11 Digital Devices GmbH\n");
-       if (ddb_class_create())
-               return -1;
-       return pci_register_driver(&ddb_pci_driver);
+
+       ret = ddb_class_create();
+       if (ret < 0)
+               return ret;
+       ret = pci_register_driver(&ddb_pci_driver);
+       if (ret < 0)
+               ddb_class_destroy();
+       return ret;
 }
 
 static __exit void module_exit_ddbridge(void)