All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>,
	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, 3 Jun 2026 14:54:05 +0200	[thread overview]
Message-ID: <aiAj7duOGUAkbB05@macbook.local> (raw)
In-Reply-To: <b443469b-01fe-4196-a79f-811bfb6e17d8@suse.com>

On Wed, Jun 03, 2026 at 08:04:25AM +0200, Jan Beulich wrote:
> On 03.06.2026 03:41, Stefano Stabellini wrote:
> > On Tue, 2 Jun 2026, Jan Beulich wrote:
> >> On 27.05.2026 00:12, 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.
> >>
> >> Well, okay, we have different opinions there. This reply of yours applies
> >> to the first paragraph of my earlier reply though, despite its placement.
> >> What about the aspect mentioned in the second paragraph?
> > 
> > You mean "then we ought to consider alternatives (like changing the
> > variables' types in the case here)" ?
> 
> That's another option, but not what I meant. I simply don't understand why
> some operators are okay to use with booleans while others aren't. Adding
> (for example) booleans can be quite helpful. Take this example from gas
> sources as example:
> 
>       if (overlap.bitfield.imm8
> 	  + overlap.bitfield.imm8s
> 	  + overlap.bitfield.imm16
> 	  + overlap.bitfield.imm32
> 	  + overlap.bitfield.imm32s
> 	  + overlap.bitfield.imm64 != 1)
> 
> And then see how the added verbosity would hamper readability:
> 
>       if ((overlap.bitfield.imm8 ? 1 : 0)
> 	  + (overlap.bitfield.imm8s ? 1 : 0)
> 	  + (overlap.bitfield.imm16 ? 1 : 0)
> 	  + (overlap.bitfield.imm32 ? 1 : 0)
> 	  + (overlap.bitfield.imm32s ? 1 : 0)
> 	  + (overlap.bitfield.imm64 ? 1 : 0) != 1)
> 
> > Other alternatives could be OK, but also this patch as-is is OK to me.
> 
> I'm not going to veto it (not being a maintainer of the code I really
> can't), but as per above the transformation imo is setting a bad example.

What about getting the BAR index based on the register value, and
hence avoiding the pointer arithmetic plus the boolean type addition?
I think that's clear and doesn't violate any MISRA rules, it would
obviously not settle the discussion about boolean type abuse as
integers, but would be fine to solve the specific issue in vPCI IMO.

Thanks, Roger.


  reply	other threads:[~2026-06-03 12:54 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é
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é [this message]
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=aiAj7duOGUAkbB05@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.