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; }