Re: Linux 3.0 oopses when pulling a USB CDROM

James Bottomley
2011-07-01T19:33:19Z

On Fri, 2011-07-01 at 14:20 -0500, James Bottomley wrote:
> I'll see if I can find the refcounting problem.
>
> Likely it's a longstanding bug which we didn't actually notice until
> now.

OK, so it looks like we have correct refcounting on the sr_block ops,
but not on the actual cdrom ops, so the device is already gone by the
time the cdrom release function gets called.

This is my best guess at the fix (just add a get into the cdrom ops),
does it work?

James

---

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 4778e27..ee75983 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -575,7 +575,10 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose)
{
struct scsi_cd *cd = cdi->handle;
struct scsi_device *sdev = cd->device;
- int retval;
+ int retval = scsi_device_get(sdev);
+
+ if (!retval)
+ return retval;

/*
* If the device is in error recovery, wait until it is done.
@@ -588,6 +591,7 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose)
return 0;

error_out:
+ scsi_device_put(sdev);
return retval;
}

@@ -598,6 +602,7 @@ static void sr_release(struct cdrom_device_info *cdi)
if (cd->device->sector_size > 2048)
sr_set_blocklength(cd, 2048);

+ scsi_device_put(cd->device);
}

static int sr_probe(struct device *dev)