mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-19 03:31:26 +00:00
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 <bvanassche@acm.org>
with some improvements
git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/2.2.x@4249 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user