Address violations of MISRA C Rule 20.7
cover Address violations of MISRA C Rule 20.7
This series fixes some MISRA C Rule 20.7.
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2383264392
Dmytro Prokopchuk (2):
arm/pci: address violations of MISRA C Rule 20.7
livepatch: address violations of MISRA C Rule 20.7
xen/arch/arm/pci/pci-access.c | 6 +++--- xen/common/livepatch.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 arm/pci: address violations of MISRA C Rule 20.7
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses".
In macros PCI_ERR_VALUE(), PCI_OP_WRITE() and PCI_OP_READ() add the parentheses around the macro's parameter to prevent against unintended expansions.
No functional changes.
--- xen/arch/arm/pci/pci-access.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/arm/pci/pci-access.c +3 -3
@@ -16,7 +16,7 @@#include <asm/io.h> #define INVALID_VALUE (~0U) -#define PCI_ERR_VALUE (len) GENMASK(0, len * 8) +#define PCI_ERR_VALUE (len) GENMASK(0, (len) * 8)static const struct pci_ops *get_ops (struct pci_host_bridge *bridge,pci_sbdf_t sbdf)
@@ -139,14 +139,14 @@ static void pci_config_write(pci_sbdf_t sbdf, unsigned int reg, void pci_conf_write##size(pci_sbdf_t sbdf, \ unsigned int reg, type data) \ { \ - pci_config_write(sbdf, reg, size / 8, data); \ + pci_config_write(sbdf, reg, (size) / 8, data); \ }#define PCI_OP_READ (size, type) \ type pci_conf_read##size(pci_sbdf_t sbdf, \ unsigned int reg) \ { \ - return pci_config_read(sbdf, reg, size / 8); \ + return pci_config_read(sbdf, reg, (size) / 8); \ }PCI_OP_READ (8 , uint8_t)
Signature · 1 line
2.43.0
Re: [PATCH 1/2] arm/pci: address violations of MISRA C Rule 20.7
Quoted 5 lines · On 13.03.2026 12:44, Dmytro Prokopchuk1 wrote:
xen/arch/arm/pci/pci-access.c +0
-1@@ -139,14 +139,14 @@ static void pci_config_write(pci_sbdf_t sbdf, unsigned int reg, void pci_conf_write##size(pci_sbdf_t sbdf, \ unsigned int reg, type data) \ { \ - pci_config_write(sbdf, reg, size / 8, data); \
xen/arch/arm/pci/pci-access.c static void pci_config_write(pci_sbdf_t sbdf, unsigned int reg, · line 150
Quoted 10 lines
xen/arch/arm/pci/pci-access.c +2
-1+pci_config_write (sbdf, reg, (size) /8 , data); \ }#define PCI_OP_READ (size, type) \ type pci_conf_read##size(pci_sbdf_t sbdf, \ unsigned int reg) \ { \ - return pci_config_read(sbdf, reg, size / 8); \ + return pci_config_read(sbdf, reg, (size) / 8); \ }
I guess the trailing backslashes would better stay aligned? (Can likely be addressed while committing.)
Jan
PATCH 2/2 livepatch: address violations of MISRA C Rule 20.7
In reply to Dmytro Prokopchuk1MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses".
In macros LIVEPATCH_ASSIGN_SINGLE_HOOK() and LIVEPATCH_ASSIGN_MULTI_HOOK() add parentheses around the macro's parameter 'hook' to prevent against unintended expansions.
No functional changes.
--- xen/common/livepatch.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
xen/common/livepatch.c +9 -9
@@ -660,13 +660,13 @@ static inline int livepatch_check_expectations(const struct payload *payload)* Perform section pointer and size validation: single hook sections must contain a * single pointer only. */ -#define LIVEPATCH_ASSIGN_SINGLE_HOOK (elf, hook, section_name) do { \ - const struct livepatch_elf_sec *__sec = livepatch_elf_sec_by_name(elf, section_name); \ - if ( !__sec ) \ - break; \ - if ( !section_ok(elf, __sec, sizeof(*hook)) || __sec->sec->sh_size != sizeof(*hook) ) \ - return -EINVAL; \ - hook = __sec->addr; \ +#define LIVEPATCH_ASSIGN_SINGLE_HOOK (elf, hook, section_name) do { \ + const struct livepatch_elf_sec *__sec = livepatch_elf_sec_by_name(elf, section_name); \ + if ( !__sec ) \ + break; \ + if ( !section_ok(elf, __sec, sizeof(*(hook))) || __sec->sec->sh_size != sizeof(*(hook)) ) \ + return -EINVAL; \ + hook = __sec->addr; \ } while (0)/*
@@ -678,10 +678,10 @@ static inline int livepatch_check_expectations(const struct payload *payload)const struct livepatch_elf_sec *__sec =livepatch_elf_sec_by_name (elf, section_name); \if ( !__sec ) \break ; \ -if ( !section_ok (elf, __sec,sizeof (*hook)) ) \ +if ( !section_ok (elf, __sec,sizeof (*(hook))) ) \return -EINVAL ; \ hook = __sec->addr; \ - nhooks = __sec->sec->sh_size /sizeof (*hook); \ + nhooks = __sec->sec->sh_size /sizeof (*(hook)); \ }while (0 ) static int prepare_payload(struct payload *payload,
Signature · 1 line
2.43.0
Quoted 8 lines · On 13/03/2026 11:44 am, Dmytro Prokopchuk1 wrote:
This series fixes some MISRA C Rule 20.7.
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2383264392Dmytro Prokopchuk (2):
arm/pci: address violations of MISRA C Rule 20.7
livepatch: address violations of MISRA C Rule 20.7
I already have patches pending for these and more.
~Andrew
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · On 13/03/2026 11:44 am, Dmytro Prokopchuk1 wrote:
This series fixes some MISRA C Rule 20.7.
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2383264392
Quoted 7 lines
Quoted 3 lines
Dmytro Prokopchuk (2):
arm/pci: address violations of MISRA C Rule 20.7
livepatch: address violations of MISRA C Rule 20.7I already have patches pending for these and more.
~Andrew
Hello Andrew,
sorry, my bad. Just ignore my patches.
BR, Dmytro.