Message ID | 8bbf294d832b973648e84e5d837b1878a84f7645.1709219010.git.nicola.vetrini@bugseng.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | address some violations of MISRA C Rule 20.7 | expand |
On Thu, 29 Feb 2024, 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> > --- > xen/drivers/passthrough/arm/smmu.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c > index 625ed0e41961..83196057a937 100644 > --- a/xen/drivers/passthrough/arm/smmu.c > +++ b/xen/drivers/passthrough/arm/smmu.c > @@ -242,7 +242,7 @@ struct arm_smmu_xen_device { > struct iommu_group *group; > }; > > -#define dev_archdata(dev) ((struct arm_smmu_xen_device *)dev->iommu) > +#define dev_archdata(dev) ((struct arm_smmu_xen_device *)(dev)->iommu) > #define dev_iommu_domain(dev) (dev_archdata(dev)->domain) > #define dev_iommu_group(dev) (dev_archdata(dev)->group) this is OK > @@ -627,7 +627,7 @@ struct arm_smmu_master_cfg { > }; > #define INVALID_SMENDX -1 > #define for_each_cfg_sme(cfg, i, idx, num) \ > - for (i = 0; idx = cfg->smendx[i], i < num; ++i) > + for (i = 0; idx = (cfg)->smendx[i], (i) < (num); ++(i)) The first i = 0 is missing parentheses? Also idx misses parentheses?
On 2024-02-29 23:53, Stefano Stabellini wrote: > On Thu, 29 Feb 2024, 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> >> --- >> xen/drivers/passthrough/arm/smmu.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/xen/drivers/passthrough/arm/smmu.c >> b/xen/drivers/passthrough/arm/smmu.c >> index 625ed0e41961..83196057a937 100644 >> --- a/xen/drivers/passthrough/arm/smmu.c >> +++ b/xen/drivers/passthrough/arm/smmu.c >> @@ -242,7 +242,7 @@ struct arm_smmu_xen_device { >> struct iommu_group *group; >> }; >> >> -#define dev_archdata(dev) ((struct arm_smmu_xen_device *)dev->iommu) >> +#define dev_archdata(dev) ((struct arm_smmu_xen_device >> *)(dev)->iommu) >> #define dev_iommu_domain(dev) (dev_archdata(dev)->domain) >> #define dev_iommu_group(dev) (dev_archdata(dev)->group) > > this is OK > > >> @@ -627,7 +627,7 @@ struct arm_smmu_master_cfg { >> }; >> #define INVALID_SMENDX -1 >> #define for_each_cfg_sme(cfg, i, idx, num) \ >> - for (i = 0; idx = cfg->smendx[i], i < num; ++i) >> + for (i = 0; idx = (cfg)->smendx[i], (i) < (num); ++(i)) > > The first i = 0 is missing parentheses? > Also idx misses parentheses? This is another case where the parentheses around the lhs are deviated currently. It's up to the maintainers to decide whether to add them regardless of that for consistency, or to keep it as is.
On Thu, 29 Feb 2024, 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> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > xen/drivers/passthrough/arm/smmu.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c > index 625ed0e41961..83196057a937 100644 > --- a/xen/drivers/passthrough/arm/smmu.c > +++ b/xen/drivers/passthrough/arm/smmu.c > @@ -242,7 +242,7 @@ struct arm_smmu_xen_device { > struct iommu_group *group; > }; > > -#define dev_archdata(dev) ((struct arm_smmu_xen_device *)dev->iommu) > +#define dev_archdata(dev) ((struct arm_smmu_xen_device *)(dev)->iommu) > #define dev_iommu_domain(dev) (dev_archdata(dev)->domain) > #define dev_iommu_group(dev) (dev_archdata(dev)->group) > > @@ -627,7 +627,7 @@ struct arm_smmu_master_cfg { > }; > #define INVALID_SMENDX -1 > #define for_each_cfg_sme(cfg, i, idx, num) \ > - for (i = 0; idx = cfg->smendx[i], i < num; ++i) > + for (i = 0; idx = (cfg)->smendx[i], (i) < (num); ++(i)) > > struct arm_smmu_master { > struct device_node *of_node; > -- > 2.34.1 >
diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index 625ed0e41961..83196057a937 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -242,7 +242,7 @@ struct arm_smmu_xen_device { struct iommu_group *group; }; -#define dev_archdata(dev) ((struct arm_smmu_xen_device *)dev->iommu) +#define dev_archdata(dev) ((struct arm_smmu_xen_device *)(dev)->iommu) #define dev_iommu_domain(dev) (dev_archdata(dev)->domain) #define dev_iommu_group(dev) (dev_archdata(dev)->group) @@ -627,7 +627,7 @@ struct arm_smmu_master_cfg { }; #define INVALID_SMENDX -1 #define for_each_cfg_sme(cfg, i, idx, num) \ - for (i = 0; idx = cfg->smendx[i], i < num; ++i) + for (i = 0; idx = (cfg)->smendx[i], (i) < (num); ++(i)) struct arm_smmu_master { struct device_node *of_node;
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> --- xen/drivers/passthrough/arm/smmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)