Skip to content

Commit

Permalink
scsi: ses: do not add a device to an enclosure if enclosure_add_links…
Browse files Browse the repository at this point in the history
…() fails.

The enclosure_add_device() function should fail if it can't create the
relevant sysfs links.

Cc: <[email protected]>
Signed-off-by: Maurizio Lombardi <[email protected]>
Tested-by: Douglas Miller <[email protected]>
Acked-by: James Bottomley <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
maurizio-lombardi authored and martinkpetersen committed Jul 1, 2017
1 parent 8dc0da7 commit 62e62ff
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions drivers/misc/enclosure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 62e62ff

Please sign in to comment.