[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/5] hw/pci-bridge: Do not declare local variable only used f
From: |
Greg Kurz |
Subject: |
Re: [PATCH 2/5] hw/pci-bridge: Do not declare local variable only used for assertion |
Date: |
Wed, 2 Sep 2020 10:59:22 +0200 |
On Wed, 2 Sep 2020 10:07:58 +0200
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> This variable is used once in an assertion. Remove single
> declaration and access directly in the assert().
>
> See in "qemu/osdep.h":
>
> * [...] disable assertion is not
> * supported upstream so the risk is all yours. Meanwhile, please
> * submit patches to remove any side-effects inside an assertion, or
> * fixing error handling that should use Error instead of assert.
>
Not sure how this relates to what the patch is doing, ie. get rid
of a local variable with a single user...
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> hw/pci-bridge/pci_bridge_dev.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
> index 4a080b7c7bf..10c521085d7 100644
> --- a/hw/pci-bridge/pci_bridge_dev.c
> +++ b/hw/pci-bridge/pci_bridge_dev.c
> @@ -224,9 +224,7 @@ void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev,
> DeviceState *dev,
> void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> Error **errp)
> {
> - PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
> -
> - g_assert(shpc_present(pci_hotplug_dev));
> + g_assert(shpc_present(PCI_DEVICE(hotplug_dev)));
I don't think this is correct because PCI_DEVICE() has a side-effect: it
causes QEMU to abort() if dev doesn't point to a PCI device. I guess that
if a non-PCI device reaches this code, something is clearly wrong and we
should abort(), even if QEMU was built without assertions.
> shpc_device_unplug_cb(hotplug_dev, dev, errp);
> }
>
- [PATCH 0/5] misc: Reduce assert side-effects, Philippe Mathieu-Daudé, 2020/09/02
- [PATCH 1/5] tests/qtest/ipmi-kcs: Fix assert side-effect, Philippe Mathieu-Daudé, 2020/09/02
- [PATCH 2/5] hw/pci-bridge: Do not declare local variable only used for assertion, Philippe Mathieu-Daudé, 2020/09/02
- Re: [PATCH 2/5] hw/pci-bridge: Do not declare local variable only used for assertion,
Greg Kurz <=
- [PATCH 4/5] tcg/tcg: Do not declare local variable only used for assertion, Philippe Mathieu-Daudé, 2020/09/02
- [PATCH 5/5] util/qsp: Do not declare local variable only used for assertion, Philippe Mathieu-Daudé, 2020/09/02
- [PATCH 3/5] hw/ppc/spapr: Do not declare local variable only used for assertion, Philippe Mathieu-Daudé, 2020/09/02