scsi: ses: do not add a device to an enclosure if enclosure_add_links() fails.
authorMaurizio Lombardi <mlombard@redhat.com>
Tue, 27 Jun 2017 09:53:27 +0000 (11:53 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sat, 1 Jul 2017 20:52:38 +0000 (16:52 -0400)
The enclosure_add_device() function should fail if it can't create the
relevant sysfs links.

Cc: <stable@vger.kernel.org>
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Tested-by: Douglas Miller <dougmill@linux.vnet.ibm.com>
Acked-by: James Bottomley <jejb@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/misc/enclosure.c

index d3fe3ea902d4f03b3647d31b69d3b621658e4c15..eb29113e0bac2437f1714af1e4189b74fe992b6f 100644 (file)
@@ -375,6 +375,7 @@ int enclosure_add_device(struct enclosure_device *edev, int component,
                         struct device *dev)
 {
        struct enclosure_component *cdev;
+       int err;
 
        if (!edev || component >= edev->components)
                return -EINVAL;
@@ -384,12 +385,17 @@ int enclosure_add_device(struct enclosure_device *edev, int component,
        if (cdev->dev == dev)
                return -EEXIST;
 
-       if (cdev->dev)
+       if (cdev->dev) {
                enclosure_remove_links(cdev);
-
-       put_device(cdev->dev);
+               put_device(cdev->dev);
+       }
        cdev->dev = get_device(dev);
-       return enclosure_add_links(cdev);
+       err = enclosure_add_links(cdev);
+       if (err) {
+               put_device(cdev->dev);
+               cdev->dev = NULL;
+       }
+       return err;
 }
 EXPORT_SYMBOL_GPL(enclosure_add_device);