xen/drivers/vpci/header.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
MISRA C Rule 10.1 states: "Operands shall not be of an
inappropriate essential type".
Boolean values cannot be directly used in arithmetic operations.
Convert boolean to integer in vPCI header bar index calculation
using the ternary operator to satisfy strict type checking rule.
No functional changes.
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2545399814
---
xen/drivers/vpci/header.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index a760d8c32f..2b7f78728d 100644
--- 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;
--
2.43.0
(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? Jan
© 2016 - 2026 Red Hat, Inc.