From: James Bottomley <James.Bottomley@steeleye.com>
To: Jens Axboe <axboe@suse.de>
Cc: SCSI Mailing List <linux-scsi@vger.kernel.org>
Subject: [PATCH] fix LLD module refcounting in sr.c
Date: 10 May 2004 16:20:38 -0500 [thread overview]
Message-ID: <1084224040.2659.400.camel@mulgrave> (raw)
The patch to close all the open/close/hotplug races in sr left the
module refcounting broken so that the ULD housing the CD device now
can't be removed until the device itself is removed.
This patch (structurally identical to the one for sd.c to perform the
same function) fixes the module refcounting.
James
===== drivers/scsi/sr.c 1.105 vs edited =====
--- 1.105/drivers/scsi/sr.c Mon Apr 12 20:27:08 2004
+++ edited/drivers/scsi/sr.c Mon May 10 16:12:15 2004
@@ -138,7 +138,15 @@
goto out;
cd = scsi_cd(disk);
if (!kref_get(&cd->kref))
- cd = NULL;
+ goto out_null;
+ if (scsi_device_get(cd->device))
+ goto out_put;
+ goto out;
+
+ out_put:
+ kref_put(&cd->kref);
+ out_null:
+ cd = NULL;
out:
up(&sr_ref_sem);
return cd;
@@ -147,6 +155,7 @@
static inline void scsi_cd_put(struct scsi_cd *cd)
{
down(&sr_ref_sem);
+ scsi_device_put(cd->device);
kref_put(&cd->kref);
up(&sr_ref_sem);
}
@@ -558,13 +567,10 @@
if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
goto fail;
- if ((error = scsi_device_get(sdev)) != 0)
- goto fail;
-
error = -ENOMEM;
cd = kmalloc(sizeof(*cd), GFP_KERNEL);
if (!cd)
- goto fail_put_sdev;
+ goto fail;
memset(cd, 0, sizeof(*cd));
kref_init(&cd->kref, sr_kref_release);
@@ -637,8 +643,6 @@
put_disk(disk);
fail_free:
kfree(cd);
-fail_put_sdev:
- scsi_device_put(sdev);
fail:
return error;
}
@@ -926,7 +930,6 @@
static void sr_kref_release(struct kref *kref)
{
struct scsi_cd *cd = container_of(kref, struct scsi_cd, kref);
- struct scsi_device *sdev = cd->device;
struct gendisk *disk = cd->disk;
spin_lock(&sr_index_lock);
@@ -940,8 +943,6 @@
put_disk(disk);
kfree(cd);
-
- scsi_device_put(sdev);
}
static int sr_remove(struct device *dev)
@@ -950,7 +951,9 @@
del_gendisk(cd->disk);
- scsi_cd_put(cd);
+ down(&sr_ref_sem);
+ kref_put(&cd->kref);
+ up(&sr_ref_sem);
return 0;
}
reply other threads:[~2004-05-10 21:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1084224040.2659.400.camel@mulgrave \
--to=james.bottomley@steeleye.com \
--cc=axboe@suse.de \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox