scsi: Fix scsi_bus_legacy_add_drive() scsi-generic with serial
PATCH 1/1 scsi: Fix scsi_bus_legacy_add_drive() scsi-generic with serial
From: Markus Armbruster <[email protected]>
scsi_bus_legacy_add_drive() creates either a scsi-disk or a scsi-generic device. It sets property "serial" to argument serial unless null. Crashes with scsi-generic, because it doesn't have such the property.
Only usb_msd_initfn_storage() passes non-null serial. Reproducer:
$ qemu-system-x86_64 -nodefaults -display none -S -usb \
-drive if=none,file=/dev/sg1,id=usb-drv0 \
-device usb-storage,id=usb-msd0,drive=usb-drv0,serial=123
qemu-system-x86_64: -device usb-storage,id=usb-msd0,drive=usb-drv0,serial=123: Property '.serial' not found
Aborted (core dumped)Fix by handling exactly like "removable": set the property only when it exists.
--- hw/scsi/scsi-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/scsi-bus.c +1 -1
@@ -224,7 +224,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,if (object_property_find (OBJECT (dev),"removable" ,NULL )) {qdev_prop_set_bit (dev,"removable" , removable); } -if (serial) { +if (serial &&object_property_find (OBJECT (dev),"serial" ,NULL )) {qdev_prop_set_string (dev,"serial" , serial); }if (qdev_prop_set_drive (dev,"drive" , bdrv) <0 ) {
Signature · 1 line
1.8.1.4
Am 23.08.2013 18:01, schrieb [email protected]:
Quoted 15 lines
From: Markus Armbruster <[email protected]>
scsi_bus_legacy_add_drive()creates either a scsi-disk or a scsi-generic device. It sets property "serial" to argument serial unless null. Crashes with scsi-generic, because it doesn't have such the property.Only
usb_msd_initfn_storage()passes non-null serial. Reproducer:$ qemu-system-x86_64 -nodefaults -display none -S -usb \ -drive if=none,file=/dev/sg1,id=usb-drv0 \ -device usb-storage,id=usb-msd0,drive=usb-drv0,serial=123 qemu-system-x86_64: -device usb-storage,id=usb-msd0,drive=usb-drv0,serial=123: Property '.serial' not found Aborted (core dumped)
Quoted 8 lines
Fix by handling exactly like "removable": set the property only when it exists.
Signed-off-by Markus Armbruster <[email protected]>--- hw/scsi/scsi-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Paolo Bonzini
AppliedIl 23/08/2013 18:01, [email protected] ha scritto:
Quoted 30 lines
From: Markus Armbruster <[email protected]>
scsi_bus_legacy_add_drive()creates either a scsi-disk or a scsi-generic device. It sets property "serial" to argument serial unless null. Crashes with scsi-generic, because it doesn't have such the property.Only
usb_msd_initfn_storage()passes non-null serial. Reproducer:$ qemu-system-x86_64 -nodefaults -display none -S -usb \ -drive if=none,file=/dev/sg1,id=usb-drv0 \ -device usb-storage,id=usb-msd0,drive=usb-drv0,serial=123 qemu-system-x86_64: -device usb-storage,id=usb-msd0,drive=usb-drv0,serial=123: Property '.serial' not found Aborted (core dumped)Fix by handling exactly like "removable": set the property only when it exists.
Signed-off-by Markus Armbruster <[email protected]>--- hw/scsi/scsi-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/scsi-bus.c +0
-0
hw/scsi/scsi-bus.c SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, · line 230
Quoted 8 lines
hw/scsi/scsi-bus.c +1
-1@@ -224,7 +224,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,if (object_property_find (OBJECT (dev),"removable" ,NULL )) {qdev_prop_set_bit (dev,"removable" , removable); } -if (serial) { +if (serial &&object_property_find (OBJECT (dev),"serial" ,NULL )) {qdev_prop_set_string (dev,"serial" , serial); }if (qdev_prop_set_drive (dev,"drive" , bdrv) <0 ) {
Applied to scsi-next branch, thanks.
Paolo