From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Richard Henderson <richard.henderson@linaro.org>,
qemu-devel@nongnu.org,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Subject: Re: [PATCH 2/2] pci: Sanity check mask argument to pci_set_*_by_mask()
Date: Wed, 17 Aug 2022 06:48:34 -0400 [thread overview]
Message-ID: <20220817064800-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <CAFEAcA8GF8MLrp+9yqmPYJCfkVdUtc+-A7J+zn-gfvb06v-+Yw@mail.gmail.com>
On Wed, Jul 27, 2022 at 11:26:15AM +0100, Peter Maydell wrote:
> On Tue, 26 Jul 2022 at 23:30, Richard Henderson
> <richard.henderson@linaro.org> wrote:
> >
> > On 7/26/22 09:32, Peter Maydell wrote:
> > > Coverity complains that in functions like pci_set_word_by_mask()
> > > we might end up shifting by more than 31 bits. This is true,
> > > but only if the caller passes in a zero mask. Help Coverity out
> > > by asserting that the mask argument is valid.
> > >
> > > Fixes: CID 1487168
> > >
> > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> > > ---
> > > Note that only 1 of these 4 functions is used, and that only
> > > in 2 places in the codebase. In both cases the mask argument
> > > is a compile-time constant.
> > > ---
> > > include/hw/pci/pci.h | 20 ++++++++++++++++----
> > > 1 file changed, 16 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> > > index c79144bc5ef..0392b947b8b 100644
> > > --- a/include/hw/pci/pci.h
> > > +++ b/include/hw/pci/pci.h
> > > @@ -688,7 +688,10 @@ static inline void
> > > pci_set_byte_by_mask(uint8_t *config, uint8_t mask, uint8_t reg)
> > > {
> > > uint8_t val = pci_get_byte(config);
> > > - uint8_t rval = reg << ctz32(mask);
> > > + uint8_t rval;
> > > +
> > > + assert(mask & 0xff);
> >
> > Why the and, especially considering the uint8_t type?
>
> Oops, yes. I think I was mixing up prototypes and thought the
> mask was passed as a 32-bit value in both these functions.
>
> -- PMM
Did you intend to send v2 of this without the &?
--
MST
next prev parent reply other threads:[~2022-08-17 10:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-26 16:32 [PATCH 0/2] pci *_by_mask() coverity fix Peter Maydell
2022-07-26 16:32 ` [PATCH 1/2] pci: Remove unused pci_get_*_by_mask() functions Peter Maydell
2022-07-26 22:27 ` Richard Henderson
2022-07-26 16:32 ` [PATCH 2/2] pci: Sanity check mask argument to pci_set_*_by_mask() Peter Maydell
2022-07-26 21:29 ` Philippe Mathieu-Daudé via
2022-07-26 22:30 ` Richard Henderson
2022-07-27 10:26 ` Peter Maydell
2022-08-17 10:48 ` Michael S. Tsirkin [this message]
2022-08-17 12:31 ` Peter Maydell
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=20220817064800-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).