Commit dacfcf27 authored by Alan Stern's avatar Alan Stern Committed by James Bottomley

[PATCH] SCSI core: Fix refcounting error

This bug was present as of 2.6.9-bk7, apparently introduced along with the
addition of SCSI targets into sysfs.  The code takes a reference to the
host for each initialized sdev but only drops a reference when each
target is released.  As you might expect, this causes a refcount leak
whenever a target has more than 0 LUNs.

The patch changes things so that the reference is acquired when the target
is initialized, not when the sdev is initialized.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent 7ee40b43
......@@ -271,8 +271,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
goto out_cleanup_slave;
}
if (get_device(&sdev->host->shost_gendev) == NULL ||
scsi_sysfs_device_initialize(sdev) != 0)
if (scsi_sysfs_device_initialize(sdev) != 0)
goto out_cleanup_slave;
......
......@@ -775,7 +775,7 @@ int scsi_sysfs_target_initialize(struct scsi_device *sdev)
memset(starget, 0, size);
dev = &starget->dev;
device_initialize(dev);
dev->parent = &shost->shost_gendev;
dev->parent = get_device(&shost->shost_gendev);
dev->release = scsi_target_dev_release;
sprintf(dev->bus_id, "target%d:%d:%d",
shost->host_no, sdev->channel, sdev->id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment