[XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C Rule 20.7

Nicola Vetrini posted 10 patches 1 year, 10 months ago
There is a newer version of this series
[XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C Rule 20.7
Posted by Nicola Vetrini 1 year, 10 months ago
MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
This local helper may disappear as a follow-up to [1], if the function that
remains there after the cleanup ends up being removed, so this patch has a slight
dependency on what follows up from that thread (in which case it can be dropped).

[1] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2403151724380.853156@ubuntu-linux-20-04-desktop/T/#m9474ad4f35830345a22acd4a665245f7085d4b46
---
 xen/drivers/passthrough/amd/iommu_guest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/amd/iommu_guest.c b/xen/drivers/passthrough/amd/iommu_guest.c
index 4c4252eea116..5bfaa48d9d65 100644
--- a/xen/drivers/passthrough/amd/iommu_guest.c
+++ b/xen/drivers/passthrough/amd/iommu_guest.c
@@ -30,7 +30,7 @@
 #define GUEST_ADDRESS_SIZE_6_LEVEL              0x2
 #define HOST_ADDRESS_SIZE_6_LEVEL               0x2
 
-#define reg_to_u64(reg) (((uint64_t)reg.hi << 32) | reg.lo )
+#define reg_to_u64(reg) (((uint64_t)((reg).hi << 32)) | (reg).lo )
 #define u64_to_reg(reg, val) \
     do \
     { \
-- 
2.34.1
Re: [XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C Rule 20.7
Posted by Jan Beulich 1 year, 10 months ago
On 18.03.2024 12:53, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> This local helper may disappear as a follow-up to [1], if the function that
> remains there after the cleanup ends up being removed, so this patch has a slight
> dependency on what follows up from that thread (in which case it can be dropped).

Indeed let's not add more churn to the file before it disappears.

Jan

> [1] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2403151724380.853156@ubuntu-linux-20-04-desktop/T/#m9474ad4f35830345a22acd4a665245f7085d4b46