From: Peter Maydell <peter.maydell@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Akihiko Odaki <akihiko.odaki@daynix.com>,
Igor Mammedov <imammedo@redhat.com>
Subject: Re: [PULL v2 11/55] hw/qdev: Check machine_hotplug_handler in hotplug_unplug_allowed_common
Date: Tue, 4 Feb 2025 13:58:38 +0000 [thread overview]
Message-ID: <CAFEAcA9aFTCcZTWUJhBisuaKWS5dEDkv1QnU_hgK4+1zPWcH0g@mail.gmail.com> (raw)
In-Reply-To: <20250113173604.46931-7-philmd@linaro.org>
On Mon, 13 Jan 2025 at 17:38, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> From: Akihiko Odaki <akihiko.odaki@daynix.com>
>
> Commit 03fcbd9dc508 ("qdev: Check for the availability of a hotplug
> controller before adding a device") says:
>
> > The qdev_unplug() function contains a g_assert(hotplug_ctrl)
> > statement, so QEMU crashes when the user tries to device_add +
> > device_del a device that does not have a corresponding hotplug
> > controller.
>
> > The code in qdev_device_add() already checks whether the bus has a
> > proper hotplug controller, but for devices that do not have a
> > corresponding bus, here is no appropriate check available yet. In that
> > case we should check whether the machine itself provides a suitable
> > hotplug controller and refuse to plug the device if none is available.
>
> However, it forgot to add the corresponding check to qdev_unplug().
>
> Check the machine hotplug handler once in the common
> qdev_hotplug_unplug_allowed_common() helper so both hotplug
> and hot-unplug path are covered.
> diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
> index e27d25c5859..861c25c855f 100644
> --- a/system/qdev-monitor.c
> +++ b/system/qdev-monitor.c
> @@ -684,17 +684,9 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
> dev = qdev_new(driver);
>
> /* Check whether the hotplug is allowed by the machine */
> - if (phase_check(PHASE_MACHINE_READY)) {
> - if (!qdev_hotplug_allowed(dev, bus, errp)) {
> - goto err_del_dev;
> - }
> -
> - if (!bus && !qdev_get_machine_hotplug_handler(dev)) {
> - /* No bus, no machine hotplug handler --> device is not hotpluggable */
> - error_setg(errp, "Device '%s' can not be hotplugged on this machine",
> - driver);
> - goto err_del_dev;
> - }
> + if (phase_check(PHASE_MACHINE_READY) &&
> + !qdev_hotplug_allowed(dev, bus, errp)) {
> + goto err_del_dev;
> }
>
Hi; Coverity notices a NULL-check related issue as a
result of this change. Here we add a call to
qdev_hotplug_allowed() that assumes that dev is not NULL.
But in the code at err_del_dev we do check whether
dev is NULL. So either this code is wrong (and could be
dereferencing NULL) or the code at err_del_dev is
doing a pointless NULL check.
Since qdev_new() can't fail, it's the err_del_dev
code that's wrong, I think.
thanks
-- PMM
next prev parent reply other threads:[~2025-02-04 13:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 17:35 [PULL v2 00/55] Misc HW patches for 2025-01-12 Philippe Mathieu-Daudé
2025-01-13 17:35 ` [PULL v2 06/55] hw/qdev: Pass bus argument to qdev_hotplug_allowed() Philippe Mathieu-Daudé
2025-01-13 17:35 ` [PULL v2 07/55] hw/qdev: Factor qdev_hotunplug_allowed() out Philippe Mathieu-Daudé
2025-01-13 17:36 ` [PULL v2 08/55] hw/qdev: Introduce qdev_hotplug_unplug_allowed_common() Philippe Mathieu-Daudé
2025-01-13 17:36 ` [PULL v2 09/55] hw/qdev: Check DevClass::hotpluggable in hotplug_unplug_allowed_common Philippe Mathieu-Daudé
2025-01-13 17:36 ` [PULL v2 10/55] hw/qdev: Check qbus_is_hotpluggable " Philippe Mathieu-Daudé
2025-01-13 17:36 ` [PULL v2 11/55] hw/qdev: Check machine_hotplug_handler " Philippe Mathieu-Daudé
2025-02-04 13:58 ` Peter Maydell [this message]
2025-01-13 17:36 ` [PULL v2 55/55] Add a b4 configuration file Philippe Mathieu-Daudé
2025-01-14 20:53 ` [PULL v2 00/55] Misc HW patches for 2025-01-12 Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFEAcA9aFTCcZTWUJhBisuaKWS5dEDkv1QnU_hgK4+1zPWcH0g@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=akihiko.odaki@daynix.com \
--cc=imammedo@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).