From ee023587dd85f85c253bb2048a1edb58faedbb6d Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Mon, 30 Apr 2012 19:23:33 +0000 Subject: [PATCH] vcdrom: Don't oops if attaching a CD-ROM fails If no medium is inserted in /dev/sr0, starting SCST with the config below triggers a kernel oops: HANDLER vcdrom { DEVICE vcdrom { filename /dev/sr0 } } Signed-off-by: Bart Van Assche with some improvements git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/2.2.x@4249 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 0ae95f239..817e7c68a 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -550,6 +550,8 @@ static struct file *vdev_open_fd(const struct scst_vdisk_dev *virt_dev) TRACE_ENTRY(); + BUG_ON(!virt_dev->filename); + if (virt_dev->dev->rd_only) open_flags |= O_RDONLY; else @@ -3964,6 +3966,7 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, { loff_t err; char *old_fn, *p, *pp; + bool old_empty; const char *filename = NULL; int length = strlen(buffer); int res = 0; @@ -3990,13 +3993,15 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, /* To sync with detach*() functions */ mutex_lock(&scst_mutex); + old_empty = virt_dev->cdrom_empty; + if (*filename == '\0') { virt_dev->cdrom_empty = 1; TRACE_DBG("%s", "No media"); } else if (*filename != '/') { PRINT_ERROR("File path \"%s\" is not absolute", filename); res = -EINVAL; - goto out_unlock; + goto out_e_unlock; } else virt_dev->cdrom_empty = 0; @@ -4007,7 +4012,7 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, if (fn == NULL) { PRINT_ERROR("%s", "Allocation of filename failed"); res = -ENOMEM; - goto out_unlock; + goto out_e_unlock; } virt_dev->filename = fn; @@ -4065,7 +4070,9 @@ out_free_fn: kfree(virt_dev->filename); virt_dev->filename = old_fn; -out_unlock: +out_e_unlock: + virt_dev->cdrom_empty = old_empty; + mutex_unlock(&scst_mutex); goto out_resume; }