hw/qdev: Don't crash if qdev_create(NULL, ...) fails
PATCH 1/1 hw/qdev: Don't crash if qdev_create(NULL, ...) fails
If an attempt to create a qdev device on the default sysbus (by passing NULL as the bus to qdev_create) fails, print a useful error message rather than crashing trying to dereference a NULL pointer.
--- hw/qdev.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
hw/qdev.c +6 -1
@@ -110,7 +110,12 @@ DeviceState *qdev_create(BusState *bus, const char *name) dev =qdev_try_create (bus, name);if (!dev) { -hw_error ("Unknown device '%s' for bus '%s'\n" , name, bus->info->name); +if (bus) { +hw_error ("Unknown device '%s' for bus '%s'\n" , name, + bus->info->name); + }else { +hw_error ("Unknown device '%s' for default sysbus\n" , name); + } }return dev;
Signature · 1 line
1.7.4.1
Quoted 3 lines · Peter Maydell
If an attempt to create a qdev device on the default sysbus (by passing NULL as the bus to
qdev_create) fails, print a useful error message rather than crashing trying to dereference a NULL pointer.
The special case bus == NULL is ugly, and should be removed. But rejecting simple bug fixes because we want some cleanup would be blackmail, and only hurts users.
Stefan Hajnoczi
AppliedQuoted 8 lines · Peter Maydell
If an attempt to create a qdev device on the default sysbus (by passing NULL as the bus to
qdev_create) fails, print a useful error message rather than crashing trying to dereference a NULL pointer.Signed-off-by Peter Maydell <[email protected]>--- hw/qdev.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches-next
Stefan