From 0ee20e665840d8a887c145b368ee121cb86a028e Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 6 May 2013 15:58:04 +0200 Subject: ahci: Don't allow creating slave drives An IDE bus provided by AHCI can only take a single IDE drive. If you add a drive as slave, qemu used to accept the command line but the device wouldn't be actually usable. Catch the situation instead and error out. Signed-off-by: Kevin Wolf --- hw/ide/qdev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'hw/ide/qdev.c') diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 8a9a891769..6a272b046d 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -47,10 +47,11 @@ static const TypeInfo ide_bus_info = { .class_init = ide_bus_class_init, }; -void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id) +void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id, int max_units) { qbus_create_inplace(&idebus->qbus, TYPE_IDE_BUS, dev, NULL); idebus->bus_id = bus_id; + idebus->max_units = max_units; } static char *idebus_get_fw_dev_path(DeviceState *dev) @@ -76,6 +77,13 @@ static int ide_qdev_init(DeviceState *qdev) if (dev->unit == -1) { dev->unit = bus->master ? 1 : 0; } + + if (dev->unit >= bus->max_units) { + error_report("Can't create IDE unit %d, bus supports only %d units", + dev->unit, bus->max_units); + goto err; + } + switch (dev->unit) { case 0: if (bus->master) { -- cgit v1.2.3