Skip to contentSkip to conversation

pci_add storage: fix error handling for 'if' parameter

PATCH Applied Eduardo Habkost 2 participants 3 messages Apr 3, 2009 – Apr 5, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci_add storage: fix error handling for 'if' parameter

This fixes:

- The error message to show the actual if= argument value. It was showing the filename instead, because 'buf' is reaused on the filename parsing.
- A bug that makes a block device to be created even when an unsupported if= arg is passed to pci_add.

---
 hw/pci-hotplug.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
hw/pci-hotplug.c +7 -5
index a01efe0..d968a14 100644
@@ -97,19 +97,22 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus,
             type = IF_SCSI;
         else if (!strcmp(buf, "virtio")) {
             type = IF_VIRTIO;
+        } else {
+            monitor_printf(mon, "type %s not a hotpluggable PCI device.\n", buf);
+            goto out;
         }
     } else {
         monitor_printf(mon, "no if= specified\n");
-        return NULL;
+        goto out;
     }
 
     if (get_param_value(buf, sizeof(buf), "file", opts)) {
         drive_idx = add_init_drive(opts);
         if (drive_idx < 0)
-            return NULL;
+            goto out;
     } else if (type == IF_VIRTIO) {
         monitor_printf(mon, "virtio requires a backing file/device.\n");
-        return NULL;
+        goto out;
     }
 
     switch (type) {
@@ -122,10 +125,9 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus,
     case IF_VIRTIO:
         opaque = virtio_blk_init (pci_bus, drives_table[drive_idx].bdrv);
         break;
-    default:
-        monitor_printf(mon, "type %s not a hotpluggable PCI device.\n", buf);
     }
 
+out:
     return opaque;
 }
 
Signature · 1 line
1.6.1
#1 lore raw
Quoted 9 lines · Eduardo Habkost

This fixes:

- The error message to show the actual if= argument value. It was showing the filename instead, because 'buf' is reaused on the filename parsing.
- A bug that makes a block device to be created even when an unsupported if= arg is passed to pci_add.

Applied. Thanks.

Regards,

Anthony Liguori

#2 lore raw
In reply to Eduardo Habkost
Quoted 9 lines · Eduardo Habkost

This fixes:

- The error message to show the actual if= argument value. It was showing the filename instead, because 'buf' is reaused on the filename parsing.
- A bug that makes a block device to be created even when an unsupported if= arg is passed to pci_add.

Applied to stable. Thanks.

Regards,

Anthony Liguori