All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Stefano Stabellini <sstabellini@kernel.org>,
	Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>,
	Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien@xen.org>,
	Anthony PERARD <anthony.perard@vates.tech>,
	Michal Orzel <michal.orzel@amd.com>,
	Stewart Hildebrand <stewart.hildebrand@amd.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] vPCI: resolve MISRA R10.1 boolean arithmetic type violation
Date: Wed, 27 May 2026 16:34:04 +0200	[thread overview]
Message-ID: <ahcA3EbeHu2ErSrs@macbook.local> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2605261508390.182011@ubuntu-linux-20-04-desktop>

On Tue, May 26, 2026 at 03:12:23PM -0700, Stefano Stabellini wrote:
> On Fri, 22 May 2026, Jan Beulich wrote:
> > (extending Cc list)
> > 
> > On 22.05.2026 08:13, Dmytro Prokopchuk1 wrote:
> > > --- a/xen/drivers/vpci/header.c
> > > +++ b/xen/drivers/vpci/header.c
> > > @@ -586,7 +586,7 @@ static void cf_check bar_write(
> > >          if ( val != (uint32_t)(bar->addr >> (hi ? 32 : 0)) )
> > >              gprintk(XENLOG_WARNING,
> > >                      "%pp: ignored BAR %zu write while mapped\n",
> > > -                    &pdev->sbdf, bar - pdev->vpci->header.bars + hi);
> > > +                    &pdev->sbdf, bar - pdev->vpci->header.bars + (hi ? 1 : 0));
> > >          return;
> > >      }
> > >  
> > > @@ -647,7 +647,7 @@ static void cf_check guest_mem_bar_write(const struct pci_dev *pdev,
> > >          if ( guest_addr != bar->guest_addr )
> > >              gprintk(XENLOG_WARNING,
> > >                      "%pp: ignored guest BAR %zu write while mapped\n",
> > > -                    &pdev->sbdf, bar - pdev->vpci->header.bars + hi);
> > > +                    &pdev->sbdf, bar - pdev->vpci->header.bars + (hi ? 1 : 0));
> > >          return;
> > >      }
> > >      bar->guest_addr = guest_addr;
> > 
> > Well. If I'm not mistaken we had discussed situations like this (long ago).
> > Imo the added verbosity gets in the way of readability. If we absolutely
> > cannot or don't want to deviate such constructs (of which I expect we have
> > more), then we ought to consider alternatives (like changing the variables'
> > types in the case here).
> > 
> > As to deviating: rules.rst, according to my reading, says that &, |, ^, or
> > shifts would be okay to use with a bool operand. What's wrong with also
> > permitting this for other operators?
> 
> In my opinion, if we are going to treat bool as its own type, it makes
> sense not to silently mix bools into arithmetic with int types. I also
> do not find this patch less readable -- I actually find it more
> readable, since it makes it more obvious that hi is a bool.

Another possibly less controversial option is doing the arithmetic
based on the register value directly: (reg - PCI_BASE_ADDRESS_0) / 4.

TBH that's likely faster than the dereferences done to get the base
address of the bars array.

Thanks, Roger.


  reply	other threads:[~2026-05-27 14:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-22  6:13 [PATCH] vPCI: resolve MISRA R10.1 boolean arithmetic type violation Dmytro Prokopchuk1
2026-05-22  6:40 ` Jan Beulich
2026-05-26 22:12   ` Stefano Stabellini
2026-05-27 14:34     ` Roger Pau Monné [this message]
2026-06-02  8:39     ` Jan Beulich
2026-06-03  1:41       ` Stefano Stabellini
2026-06-03  6:04         ` Jan Beulich
2026-06-03 12:54           ` Roger Pau Monné
2026-06-03 13:02             ` Jan Beulich
2026-06-03 20:43               ` Stefano Stabellini
2026-06-04  6:15                 ` Nicola Vetrini
2026-06-05  8:20                 ` Jan Beulich

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=ahcA3EbeHu2ErSrs@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=dmytro_prokopchuk1@epam.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=stewart.hildebrand@amd.com \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.