[XEN PATCH v4 2/4] xen/vpci: address violations of MISRA C:2012 Rule 7.2

Simone Ballarin posted 4 patches 2 years, 6 months ago
There is a newer version of this series
[XEN PATCH v4 2/4] xen/vpci: address violations of MISRA C:2012 Rule 7.2
Posted by Simone Ballarin 2 years, 6 months ago
From: Gianluca Luparini <gianluca.luparini@bugseng.com>

The xen sources contains violations of MISRA C:2012 Rule 7.2 whose
headline states:
"A 'u' or 'U' suffix shall be applied to all integer constants
that are represented in an unsigned type".

Add the 'U' suffix to integers literals with unsigned type and also to other
literals used in the same contexts or near violations, when their positive
nature is immediately clear. The latter changes are done for the sake of
uniformity.

Signed-off-by: Gianluca Luparini <gianluca.luparini@bugseng.com>
Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
Changes in v4:
- change commit headline

Changes in v3:
- change 'Signed-off-by' ordering
- add 'uint32_t' casts in 'msi.c' and 'msix.c'

Changes in v2:
- minor change to commit title
- change commit message
---
 xen/drivers/vpci/msi.c  | 2 +-
 xen/drivers/vpci/msix.c | 2 +-
 xen/drivers/vpci/vpci.c | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c
index 8f2b59e61a..bf5fe2f981 100644
--- a/xen/drivers/vpci/msi.c
+++ b/xen/drivers/vpci/msi.c
@@ -124,7 +124,7 @@ static void cf_check address_hi_write(
     struct vpci_msi *msi = data;
 
     /* Clear and update high part. */
-    msi->address &= 0xffffffff;
+    msi->address  = (uint32_t)msi->address;
     msi->address |= (uint64_t)val << 32;
 
     update_msi(pdev, msi);
diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
index 25bde77586..2090168f42 100644
--- a/xen/drivers/vpci/msix.c
+++ b/xen/drivers/vpci/msix.c
@@ -531,7 +531,7 @@ static int cf_check msix_write(
 
     case PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET:
         entry->updated = true;
-        entry->addr &= 0xffffffff;
+        entry->addr  = (uint32_t)entry->addr;
         entry->addr |= (uint64_t)data << 32;
         break;
 
diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index d73fa76302..3bec9a4153 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -319,7 +319,7 @@ static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,
 static uint32_t merge_result(uint32_t data, uint32_t new, unsigned int size,
                              unsigned int offset)
 {
-    uint32_t mask = 0xffffffff >> (32 - 8 * size);
+    uint32_t mask = 0xffffffffU >> (32 - 8 * size);
 
     return (data & ~(mask << (offset * 8))) | ((new & mask) << (offset * 8));
 }
@@ -402,7 +402,7 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size)
         data = merge_result(data, tmp_data, size - data_offset, data_offset);
     }
 
-    return data & (0xffffffff >> (32 - 8 * size));
+    return data & (0xffffffffU >> (32 - 8 * size));
 }
 
 /*
@@ -427,7 +427,7 @@ static void vpci_write_helper(const struct pci_dev *pdev,
         data = merge_result(val, data, size, offset);
     }
 
-    r->write(pdev, r->offset, data & (0xffffffff >> (32 - 8 * r->size)),
+    r->write(pdev, r->offset, data & (0xffffffffU >> (32 - 8 * r->size)),
              r->private);
 }
 
-- 
2.34.1
Re: [XEN PATCH v4 2/4] xen/vpci: address violations of MISRA C:2012 Rule 7.2
Posted by Roger Pau Monné 2 years, 5 months ago
On Wed, Jul 26, 2023 at 01:03:37PM +0200, Simone Ballarin wrote:
> From: Gianluca Luparini <gianluca.luparini@bugseng.com>
> 
> The xen sources contains violations of MISRA C:2012 Rule 7.2 whose
> headline states:
> "A 'u' or 'U' suffix shall be applied to all integer constants
> that are represented in an unsigned type".
> 
> Add the 'U' suffix to integers literals with unsigned type and also to other
> literals used in the same contexts or near violations, when their positive
> nature is immediately clear. The latter changes are done for the sake of
> uniformity.
> 
> Signed-off-by: Gianluca Luparini <gianluca.luparini@bugseng.com>
> Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.

Re: [XEN PATCH v4 2/4] xen/vpci: address violations of MISRA C:2012 Rule 7.2
Posted by Stefano Stabellini 2 years, 5 months ago
On Thu, 24 Aug 2023, Roger Pau Monné wrote:
> On Wed, Jul 26, 2023 at 01:03:37PM +0200, Simone Ballarin wrote:
> > From: Gianluca Luparini <gianluca.luparini@bugseng.com>
> > 
> > The xen sources contains violations of MISRA C:2012 Rule 7.2 whose
> > headline states:
> > "A 'u' or 'U' suffix shall be applied to all integer constants
> > that are represented in an unsigned type".
> > 
> > Add the 'U' suffix to integers literals with unsigned type and also to other
> > literals used in the same contexts or near violations, when their positive
> > nature is immediately clear. The latter changes are done for the sake of
> > uniformity.
> > 
> > Signed-off-by: Gianluca Luparini <gianluca.luparini@bugseng.com>
> > Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
> > Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> 
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks! I saw too late :-)
Re: [XEN PATCH v4 2/4] xen/vpci: address violations of MISRA C:2012 Rule 7.2
Posted by Nicola Vetrini 2 years, 5 months ago
On 26/07/2023 13:03, Simone Ballarin wrote:
> From: Gianluca Luparini <gianluca.luparini@bugseng.com>
> 
> The xen sources contains violations of MISRA C:2012 Rule 7.2 whose
> headline states:
> "A 'u' or 'U' suffix shall be applied to all integer constants
> that are represented in an unsigned type".
> 
> Add the 'U' suffix to integers literals with unsigned type and also to 
> other
> literals used in the same contexts or near violations, when their 
> positive
> nature is immediately clear. The latter changes are done for the sake 
> of
> uniformity.
> 
> Signed-off-by: Gianluca Luparini <gianluca.luparini@bugseng.com>
> Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> Changes in v4:
> - change commit headline
> 
> Changes in v3:
> - change 'Signed-off-by' ordering
> - add 'uint32_t' casts in 'msi.c' and 'msix.c'
> 
> Changes in v2:
> - minor change to commit title
> - change commit message
> ---
>  xen/drivers/vpci/msi.c  | 2 +-
>  xen/drivers/vpci/msix.c | 2 +-
>  xen/drivers/vpci/vpci.c | 6 +++---
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 

Like other patches in this series, this one could also benefit from an 
ack from
VPCI maintainers to get committed, as it does apply cleanly on staging.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
Need Ack, Re: [XEN PATCH v4 2/4] xen/vpci: address violations of MISRA C:2012 Rule 7.2
Posted by Stefano Stabellini 2 years, 5 months ago
Please ack

On Thu, 24 Aug 2023, Nicola Vetrini wrote:
> On 26/07/2023 13:03, Simone Ballarin wrote:
> > From: Gianluca Luparini <gianluca.luparini@bugseng.com>
> > 
> > The xen sources contains violations of MISRA C:2012 Rule 7.2 whose
> > headline states:
> > "A 'u' or 'U' suffix shall be applied to all integer constants
> > that are represented in an unsigned type".
> > 
> > Add the 'U' suffix to integers literals with unsigned type and also to other
> > literals used in the same contexts or near violations, when their positive
> > nature is immediately clear. The latter changes are done for the sake of
> > uniformity.
> > 
> > Signed-off-by: Gianluca Luparini <gianluca.luparini@bugseng.com>
> > Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
> > Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> > ---
> > Changes in v4:
> > - change commit headline
> > 
> > Changes in v3:
> > - change 'Signed-off-by' ordering
> > - add 'uint32_t' casts in 'msi.c' and 'msix.c'
> > 
> > Changes in v2:
> > - minor change to commit title
> > - change commit message
> > ---
> >  xen/drivers/vpci/msi.c  | 2 +-
> >  xen/drivers/vpci/msix.c | 2 +-
> >  xen/drivers/vpci/vpci.c | 6 +++---
> >  3 files changed, 5 insertions(+), 5 deletions(-)
> > 
> 
> Like other patches in this series, this one could also benefit from an ack
> from
> VPCI maintainers to get committed, as it does apply cleanly on staging.
> 
> -- 
> Nicola Vetrini, BSc
> Software Engineer, BUGSENG srl (https://bugseng.com)
>