diff options
author | Markus Armbruster <armbru@redhat.com> | 2010-06-25 18:53:21 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2010-07-02 13:18:01 +0200 |
commit | fa66b909f382619da15f8c7e323145adfa94fdac (patch) | |
tree | ad7e6948ea9eafbd78633a6d14d25cb5c90a88f1 /hw/scsi-bus.c | |
parent | 39508e7adb0de3ef69caa1b494d823d8ac11d3f3 (diff) |
scsi: scsi_bus_legacy_handle_cmdline() can fail, fix callers
None of its callers checks for failure. scsi_hot_add() can crash
because of that:
(qemu) drive_add 4 if=scsi,format=host_device,file=/dev/sg1
scsi-generic: scsi generic interface too old
Segmentation fault (core dumped)
Fix all callers, not just scsi_hot_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hw/scsi-bus.c')
-rw-r--r-- | hw/scsi-bus.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 24bd0602ef..d5b66c14dd 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -83,7 +83,6 @@ void scsi_qdev_register(SCSIDeviceInfo *info) } /* handle legacy '-drive if=scsi,...' cmd line args */ -/* FIXME callers should check for failure, but don't */ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit) { const char *driver; @@ -98,18 +97,22 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit) return DO_UPCAST(SCSIDevice, qdev, dev); } -void scsi_bus_legacy_handle_cmdline(SCSIBus *bus) +int scsi_bus_legacy_handle_cmdline(SCSIBus *bus) { DriveInfo *dinfo; - int unit; + int res = 0, unit; for (unit = 0; unit < MAX_SCSI_DEVS; unit++) { dinfo = drive_get(IF_SCSI, bus->busnr, unit); if (dinfo == NULL) { continue; } - scsi_bus_legacy_add_drive(bus, dinfo, unit); + if (!scsi_bus_legacy_add_drive(bus, dinfo, unit)) { + res = -1; + break; + } } + return res; } void scsi_dev_clear_sense(SCSIDevice *dev) |