qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: P J P <ppandit@redhat.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>, "Li Qiang" <liq3ea@gmail.com>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	Ruhr-University <bugs-syssec@rub.de>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PATCH] pci: check bus pointer before dereference
Date: Wed, 16 Sep 2020 13:19:00 +0100	[thread overview]
Message-ID: <CAFEAcA8Y+sJkapmrjNOdWP4xXa9kWTmSyXpthkvdb6QgUyDh5Q@mail.gmail.com> (raw)
In-Reply-To: <nycvar.YSQ.7.78.906.2009161152040.10832@xnncv>

On Wed, 16 Sep 2020 at 07:28, P J P <ppandit@redhat.com> wrote:
> ===
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index de0fae10ab..0ccb991410 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -253,6 +253,7 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int
> irq_num, int change)
>      PCIBus *bus;
>      for (;;) {
>          bus = pci_get_bus(pci_dev);
> +        assert(bus);
>          irq_num = bus->map_irq(pci_dev, irq_num);
>          if (bus->set_irq)
>              break;
> ===
>
> This should be okay for now?

Generally we don't bother to assert() that pointers that shouldn't be NULL
really are NULL immediately before dereferencing them, because the
dereference provides an equally easy-to-debug crash to the assert,
and so the assert doesn't provide anything extra.
assert()ing that a pointer is non-NULL is more useful if it is done in a
place that identifies the problem at an earlier and easier-to-debug point
in execution rather than at a later point which is distantly removed from
the place where the bogus pointer was introduced.

thanks
-- PMM


  reply	other threads:[~2020-09-16 12:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 11:49 [PATCH] pci: check bus pointer before dereference P J P
2020-09-15 12:46 ` P J P
2020-09-15 13:51 ` Li Qiang
2020-09-15 16:26   ` Philippe Mathieu-Daudé
2020-09-16  6:27     ` P J P
2020-09-16 12:19       ` Peter Maydell [this message]
2020-09-28 11:03         ` P J P
2020-09-30  5:02           ` P J P
2020-09-30  6:45             ` Igor Mammedov
2020-09-30 10:14               ` P J P
2020-10-30  9:01             ` Michael S. Tsirkin
2020-10-30 10:50               ` Fam Zheng

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=CAFEAcA8Y+sJkapmrjNOdWP4xXa9kWTmSyXpthkvdb6QgUyDh5Q@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=alxndr@bu.edu \
    --cc=bugs-syssec@rub.de \
    --cc=imammedo@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=liq3ea@gmail.com \
    --cc=mst@redhat.com \
    --cc=philmd@redhat.com \
    --cc=ppandit@redhat.com \
    --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).