]> git.ipfire.org Git - thirdparty/qemu.git/commit
system/qdev: Remove pointless NULL check in qdev_device_add_from_qdict
authorPhilippe Mathieu-Daudé <philmd@linaro.org>
Mon, 10 Feb 2025 12:10:45 +0000 (13:10 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 10 Jul 2025 15:18:43 +0000 (16:18 +0100)
commit677bb509bfbe5f94bb15a62d8490cbad89aa9b94
tree97c89db82e6f95774ecc18d238ec2d26f1e2b9b8
parent851dcb8355cb3c37fbbf8cc99ae5fac4871d1a44
system/qdev: Remove pointless NULL check in qdev_device_add_from_qdict

Coverity reported a unnecessary NULL check:

  qemu/system/qdev-monitor.c: 720 in qdev_device_add_from_qdict()
  683     /* create device */
  684     dev = qdev_new(driver);
  ...
  719     err_del_dev:
  >>>     CID 1590192:  Null pointer dereferences  (REVERSE_INULL)
  >>>     Null-checking "dev" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
  720         if (dev) {
  721             object_unparent(OBJECT(dev));
  722             object_unref(OBJECT(dev));
  723         }
  724         return NULL;
  725     }

Indeed, unlike qdev_try_new() which can return NULL,
qdev_new() always returns a heap pointer (or aborts).

Remove the unnecessary assignment and check.

Fixes: f3a85056569 ("qdev/qbus: add hidden device support")
Resolves: Coverity CID 1590192 (Null pointer dereferences)
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
system/qdev-monitor.c