Skip to contentSkip to conversation

xen: address MISRA C:2012 Rule 5.3

PATCH In review Nicola Vetrini 3 participants 8 messages Aug 1, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover xen: address MISRA C:2012 Rule 5.3

Rule 5.3 has the following headline:
"An identifier declared in an inner scope shall not hide an identifier declared in an outer scope".

The following two strategies are adopted to deal with some violations of this rule:
- renaming of local variables, functions or parameters;
- removal of unnecessary declarations.

No functional changes.

Changes in v2:
- Patches 1/4 and 2/4 from the previous version of this patch
(https://lore.kernel.org/xen-devel/[email protected]/)
are already committed to staging, therefore are excluded from this series.

Nicola Vetrini (3):
xen/common: address MISRA C:2012 Rule 5.3
drivers/char: address MISRA C:2012 Rule 5.3
arm/efi: address MISRA C:2012 Rule 5.3

 xen/arch/arm/efi/efi-boot.h  | 84 ++++++++++++++++++------------------
 xen/common/compat/memory.c   |  7 ++-
 xen/common/numa.c            | 20 ++++-----
 xen/drivers/char/ehci-dbgp.c |  4 +-
 xen/drivers/char/ns16550.c   |  6 +--
 5 files changed, 59 insertions(+), 62 deletions(-)

--
2.34.1

#1 lore raw

PATCH v2 1/3 xen/common: address MISRA C:2012 Rule 5.3

The following strategies are adopted to deal with violations of MISRA C:2012 Rule 5.3:
"An identifier declared in an inner scope shall not hide an identifier declared in an outer scope".

- s/nodes/numa_nodes/ for the file-scope variable in 'common/numa.c';
- move the variable 'struct compat_remove_from_physmap cmp' inside the outer union variable 'cmp' to avoid shadowing it.

---
Changes in v2:
- Split the patch in common/ and drivers/.
- Moved the local cmp into the union as a member.
- Renamed the file-scope variable instead of parameters/local variables.

---
 xen/common/compat/memory.c |  7 +++----
 xen/common/numa.c          | 20 ++++++++++----------
 2 files changed, 13 insertions(+), 14 deletions(-)
xen/common/compat/memory.c +3 -4
index 8ca63ceda6..d000a5d93d 100644
@@ -81,6 +81,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             struct compat_memory_exchange xchg;
             struct compat_add_to_physmap atp;
             struct compat_add_to_physmap_batch atpb;
+            struct compat_remove_from_physmap rmfp;
             struct compat_vnuma_topology_info vnuma;
             struct compat_mem_access_op mao;
             struct compat_mem_acquire_resource mar;
@@ -321,12 +322,10 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
 
         case XENMEM_remove_from_physmap:
         {
-            struct compat_remove_from_physmap cmp;
-
-            if ( copy_from_guest(&cmp, compat, 1) )
+            if ( copy_from_guest(&cmp.rmfp, compat, 1) )
                 return -EFAULT;
 
-            XLAT_remove_from_physmap(nat.xrfp, &cmp);
+            XLAT_remove_from_physmap(nat.xrfp, &cmp.rmfp);
 
             break;
         }
xen/common/numa.c +10 -10
index fc1f7f665b..f454c4d894 100644
@@ -15,7 +15,7 @@
 
 static nodemask_t __initdata processor_nodes_parsed;
 static nodemask_t __initdata memory_nodes_parsed;
-static struct node __initdata nodes[MAX_NUMNODES];
+static struct node __initdata numa_nodes[MAX_NUMNODES];
 
 static unsigned int __ro_after_init num_node_memblks;
 static struct node __ro_after_init node_memblk_range[NR_NODE_MEMBLKS];
@@ -117,7 +117,7 @@ static enum conflicts __init conflicting_memblks(
 
 static void __init cutoff_node(nodeid_t i, paddr_t start, paddr_t end)
 {
-    struct node *nd = &nodes[i];
+    struct node *nd = &numa_nodes[i];
 
     if ( nd->start < start )
     {
@@ -157,7 +157,7 @@ bool __init numa_update_node_memblks(nodeid_t node, unsigned int arch_nid,
     paddr_t end = start + size;
     paddr_t nd_start = start;
     paddr_t nd_end = end;
-    struct node *nd = &nodes[node];
+    struct node *nd = &numa_nodes[node];
 
     /*
      * For the node that already has some memory blocks, we will
@@ -292,17 +292,17 @@ static bool __init nodes_cover_memory(void)
         do {
             found = false;
             for_each_node_mask ( j, memory_nodes_parsed )
-                if ( start < nodes[j].end && end > nodes[j].start )
+                if ( start < numa_nodes[j].end && end > numa_nodes[j].start )
                 {
-                    if ( start >= nodes[j].start )
+                    if ( start >= numa_nodes[j].start )
                     {
-                        start = nodes[j].end;
+                        start = numa_nodes[j].end;
                         found = true;
                     }
 
-                    if ( end <= nodes[j].end )
+                    if ( end <= numa_nodes[j].end )
                     {
-                        end = nodes[j].start;
+                        end = numa_nodes[j].start;
                         found = true;
                     }
                 }
@@ -356,10 +356,10 @@ static bool __init numa_process_nodes(paddr_t start, paddr_t end)
     /* Finally register nodes */
     for_each_node_mask ( i, all_nodes_parsed )
     {
-        if ( nodes[i].end == nodes[i].start )
+        if ( numa_nodes[i].end == numa_nodes[i].start )
             printk(KERN_INFO "NUMA: node %u has no memory\n", i);
 
-        setup_node_bootmem(i, nodes[i].start, nodes[i].end);
+        setup_node_bootmem(i, numa_nodes[i].start, numa_nodes[i].end);
     }
 
     for ( i = 0; i < nr_cpu_ids; i++ )
Signature · 1 line
2.34.1
Acked-by on v2 1/3
#2 lore raw

Re: [XEN PATCH v2 1/3] xen/common: address MISRA C:2012 Rule 5.3

Quoted 12 lines · Nicola Vetrini
xen/common/compat/memory.c +1 -0
@@ -81,6 +81,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             struct compat_memory_exchange xchg;
             struct compat_add_to_physmap atp;
             struct compat_add_to_physmap_batch atpb;
+            struct compat_remove_from_physmap rmfp;
             struct compat_vnuma_topology_info vnuma;
             struct compat_mem_access_op mao;
             struct compat_mem_acquire_resource mar;
@@ -321,12 +322,10 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
 

xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 328

Quoted 10 lines
xen/common/compat/memory.c +2 -4
         case XENMEM_remove_from_physmap:
         {
-            struct compat_remove_from_physmap cmp;
-
-            if ( copy_from_guest(&cmp, compat, 1) )
+            if ( copy_from_guest(&cmp.rmfp, compat, 1) )
                 return -EFAULT;
 
-            XLAT_remove_from_physmap(nat.xrfp, &cmp);
+            XLAT_remove_from_physmap(nat.xrfp, &cmp.rmfp);

Is there a reason not to use the same name in the compat union as is used in the native one, like all other members do?

Preferably with consistent naming (which I'd be okay switching to while committing)

Jan

#3 lore raw

Re: [XEN PATCH v2 1/3] xen/common: address MISRA C:2012 Rule 5.3

Quoted 23 lines · Jan Beulich
Quoted 22 lines · Nicola Vetrini
xen/common/compat/memory.c +1 -0
@@ -81,6 +81,7 @@ int compat_memory_op(unsigned int cmd, 
 XEN_GUEST_HANDLE_PARAM(void) compat)
             struct compat_memory_exchange xchg;
             struct compat_add_to_physmap atp;
             struct compat_add_to_physmap_batch atpb;
+            struct compat_remove_from_physmap rmfp;
             struct compat_vnuma_topology_info vnuma;
             struct compat_mem_access_op mao;
             struct compat_mem_acquire_resource mar;
xen/common/compat/memory.c +1 -3
@@ -321,12 +322,10 @@ int compat_memory_op(unsigned int cmd, 
 XEN_GUEST_HANDLE_PARAM(void) compat)
 
         case XENMEM_remove_from_physmap:
         {
-            struct compat_remove_from_physmap cmp;
-
-            if ( copy_from_guest(&cmp, compat, 1) )
+            if ( copy_from_guest(&cmp.rmfp, compat, 1) )
                 return -EFAULT;
 
Quoted 6 lines

xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 328

Quoted 2 lines
xen/common/compat/memory.c +1 -1
-            XLAT_remove_from_physmap(nat.xrfp, &cmp);
+            XLAT_remove_from_physmap(nat.xrfp, &cmp.rmfp);

Is there a reason not to use the same name in the compat union as is used in the native one, like all other members do?

No, I just didn't notice there was a native remove_from_physmap field when choosing the name.

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
#4 lore raw

PATCH v2 2/3 drivers/char: address MISRA C:2012 Rule 5.3

In reply to Nicola Vetrini

The following strategies are adopted to deal with violations of MISRA C:2012 Rule 5.3:
"An identifier declared in an inner scope shall not hide an identifier declared in an outer scope".

Local variable 'ctrl' shadows a variable defined in an outer scope. Since the innermost variable is used only once after being set, it is safe to remove it entirely.

The enum constant 'baud' is shadowed by local a local variable at line 1476, and renaming the enum constant avoid such conflicts.

---
Changes in v2:
- Renamed the enum constant instead of the local variable 'baud'.
- Removed the inner variable entirely, as it serves no purpose.

---
 xen/drivers/char/ehci-dbgp.c | 4 +---
 xen/drivers/char/ns16550.c   | 6 +++---
 2 files changed, 4 insertions(+), 6 deletions(-)
xen/drivers/char/ehci-dbgp.c +1 -3
index 4d8d765122..72be4d9cc9 100644
@@ -424,9 +424,7 @@ static void dbgp_issue_command(struct ehci_dbgp *dbgp, u32 ctrl,
          * checks to see if ACPI or some other initialization also
          * reset the EHCI debug port.
          */
-        u32 ctrl = readl(&dbgp->ehci_debug->control);
-
-        if ( ctrl & DBGP_ENABLED )
+        if ( readl(&dbgp->ehci_debug->control) & DBGP_ENABLED )
         {
             cmd |= CMD_RUN;
             writel(cmd, &dbgp->ehci_regs->command);
xen/drivers/char/ns16550.c +3 -3
index 212a9c49ae..b75e7f8fa0 100644
@@ -1388,7 +1388,7 @@ string_param("com1", opt_com1);
 string_param("com2", opt_com2);
 
 enum serial_param_type {
-    baud,
+    baud_rate,
     clock_hz,
     data_bits,
     io_base,
@@ -1416,7 +1416,7 @@ struct serial_param_var {
  * com_console_options for serial port com1 and com2.
  */
 static const struct serial_param_var __initconst sp_vars[] = {
-    {"baud", baud},
+    {"baud", baud_rate},
     {"clock-hz", clock_hz},
     {"data-bits", data_bits},
     {"io-base", io_base},
@@ -1596,7 +1596,7 @@ static bool __init parse_namevalue_pairs(char *str, struct ns16550 *uart)
 
         switch ( get_token(token, &param_value) )
         {
-        case baud:
+        case baud_rate:
             uart->baud = simple_strtoul(param_value, NULL, 0);
             break;
 
Signature · 1 line
2.34.1
Reviewed-by on v2 2/3
#5 lore raw

Re: [XEN PATCH v2 2/3] drivers/char: address MISRA C:2012 Rule 5.3

Quoted 5 lines · Nicola Vetrini

The following strategies are adopted to deal with violations of MISRA C:2012 Rule 5.3:
"An identifier declared in an inner scope shall not hide an identifier declared in an outer scope".

Quoted 8 lines

Local variable 'ctrl' shadows a variable defined in an outer scope. Since the innermost variable is used only once after being set, it is safe to remove it entirely.

The enum constant 'baud' is shadowed by local a local variable at line 1476, and renaming the enum constant avoid such conflicts.

#6 lore raw

PATCH v2 3/3 arm/efi: address MISRA C:2012 Rule 5.3

In reply to Nicola Vetrini

Rule 5.3 has the following headline:
"An identifier declared in an inner scope shall not hide an identifier declared in an outer scope"

The file-scope variable 'fdt' is shadowed by function parameters, and thus violates the rule, hence it's renamed to 'fdt_efi'

No functional changes.

---
Changes in v2:
- Renamed the file-scope variable instead of removing function parameters.

---
 xen/arch/arm/efi/efi-boot.h | 84 ++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 42 deletions(-)
xen/arch/arm/efi/efi-boot.h +42 -42
index 6126a71400..f24df2abb9 100644
@@ -49,7 +49,7 @@ static void PrintMessage(const CHAR16 *s);
 {0xb1b621d5U, 0xf19c, 0x41a5, {0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0}}
 
 static struct file __initdata dtbfile;
-static void __initdata *fdt;
+static void __initdata *fdt_efi;
 static void __initdata *memmap;
 
 static int __init setup_chosen_node(void *fdt, int *addr_cells, int *size_cells)
@@ -383,7 +383,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
     if ( EFI_ERROR(status) )
         blexit(L"EFI memory map processing failed");
 
-    status = fdt_add_uefi_nodes(SystemTable, fdt, map, map_size, desc_size,
+    status = fdt_add_uefi_nodes(SystemTable, fdt_efi, map, map_size, desc_size,
                                 desc_ver);
     if ( EFI_ERROR(status) )
         PrintErrMesg(L"Updating FDT failed", status);
@@ -395,7 +395,7 @@ static void __init efi_arch_pre_exit_boot(void)
 
 static void __init noreturn efi_arch_post_exit_boot(void)
 {
-    efi_xen_start(fdt, fdt_totalsize(fdt));
+    efi_xen_start(fdt_efi, fdt_totalsize(fdt_efi));
 }
 
 static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image,
@@ -420,8 +420,8 @@ static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image,
             efi_bs->FreePool(name.w);
         }
     }
-    fdt = fdt_increase_size(&dtbfile, cfg.size + EFI_PAGE_SIZE);
-    if ( !fdt )
+    fdt_efi = fdt_increase_size(&dtbfile, cfg.size + EFI_PAGE_SIZE);
+    if ( !fdt_efi )
         blexit(L"Unable to create new FDT");
 }
 
@@ -465,7 +465,7 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
     int chosen;
 
     /* locate chosen node, which is where we add Xen module info. */
-    chosen = fdt_subnode_offset(fdt, 0, "chosen");
+    chosen = fdt_subnode_offset(fdt_efi, 0, "chosen");
     if ( chosen < 0 )
         blexit(L"Unable to find chosen node");
 
@@ -498,7 +498,7 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
     else
     {
         /* Get xen,xen-bootargs in /chosen if it is specified */
-        const char *dt_bootargs_prop = fdt_getprop(fdt, chosen,
+        const char *dt_bootargs_prop = fdt_getprop(fdt_efi, chosen,
                                                    "xen,xen-bootargs", NULL);
         if ( dt_bootargs_prop )
         {
@@ -526,7 +526,7 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
             blexit(L"FDT string overflow");
     }
 
-    if ( fdt_setprop_string(fdt, chosen, "xen,xen-bootargs", buf) < 0 )
+    if ( fdt_setprop_string(fdt_efi, chosen, "xen,xen-bootargs", buf) < 0 )
         blexit(L"Unable to set xen,xen-bootargs property.");
 
     efi_bs->FreePool(buf);
@@ -542,7 +542,7 @@ static void __init efi_arch_handle_module(const struct file *file,
 
     if ( file == &dtbfile )
         return;
-    chosen = setup_chosen_node(fdt, &addr_len, &size_len);
+    chosen = setup_chosen_node(fdt_efi, &addr_len, &size_len);
     if ( chosen < 0 )
         blexit(L"Unable to setup chosen node");
 
@@ -551,13 +551,13 @@ static void __init efi_arch_handle_module(const struct file *file,
         static const char __initconst ramdisk_compat[] = "multiboot,ramdisk\0"
                                                          "multiboot,module";
 
-        node = fdt_add_subnode(fdt, chosen, "ramdisk");
+        node = fdt_add_subnode(fdt_efi, chosen, "ramdisk");
         if ( node < 0 )
             blexit(L"Unable to add ramdisk FDT node.");
-        if ( fdt_setprop(fdt, node, "compatible", ramdisk_compat,
+        if ( fdt_setprop(fdt_efi, node, "compatible", ramdisk_compat,
                          sizeof(ramdisk_compat)) < 0 )
             blexit(L"Unable to set compatible property.");
-        if ( fdt_set_reg(fdt, node, addr_len, size_len, ramdisk.addr,
+        if ( fdt_set_reg(fdt_efi, node, addr_len, size_len, ramdisk.addr,
                     ramdisk.size) < 0 )
             blexit(L"Unable to set reg property.");
     }
@@ -566,13 +566,13 @@ static void __init efi_arch_handle_module(const struct file *file,
         static const char __initconst xsm_compat[] = "xen,xsm-policy\0"
                                                      "multiboot,module";
 
-        node = fdt_add_subnode(fdt, chosen, "xsm");
+        node = fdt_add_subnode(fdt_efi, chosen, "xsm");
         if ( node < 0 )
             blexit(L"Unable to add xsm FDT node.");
-        if ( fdt_setprop(fdt, node, "compatible", xsm_compat,
+        if ( fdt_setprop(fdt_efi, node, "compatible", xsm_compat,
                          sizeof(xsm_compat)) < 0 )
             blexit(L"Unable to set compatible property.");
-        if ( fdt_set_reg(fdt, node, addr_len, size_len, xsm.addr,
+        if ( fdt_set_reg(fdt_efi, node, addr_len, size_len, xsm.addr,
                     xsm.size) < 0 )
             blexit(L"Unable to set reg property.");
     }
@@ -581,15 +581,15 @@ static void __init efi_arch_handle_module(const struct file *file,
         static const char __initconst kernel_compat[] = "multiboot,kernel\0"
                                                         "multiboot,module";
 
-        node = fdt_add_subnode(fdt, chosen, "kernel");
+        node = fdt_add_subnode(fdt_efi, chosen, "kernel");
         if ( node < 0 )
             blexit(L"Unable to add dom0 FDT node.");
-        if ( fdt_setprop(fdt, node, "compatible", kernel_compat,
+        if ( fdt_setprop(fdt_efi, node, "compatible", kernel_compat,
                          sizeof(kernel_compat)) < 0 )
             blexit(L"Unable to set compatible property.");
-        if ( options && fdt_setprop_string(fdt, node, "bootargs", options) < 0 )
+        if ( options && fdt_setprop_string(fdt_efi, node, "bootargs", options) < 0 )
             blexit(L"Unable to set bootargs property.");
-        if ( fdt_set_reg(fdt, node, addr_len, size_len, kernel.addr,
+        if ( fdt_set_reg(fdt_efi, node, addr_len, size_len, kernel.addr,
                          kernel.size) < 0 )
             blexit(L"Unable to set reg property.");
     }
@@ -719,7 +719,7 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
     module_info *file;
 
     /* Check if the node is a multiboot,module otherwise return */
-    module_compat = fdt_node_check_compatible(fdt, module_node_offset,
+    module_compat = fdt_node_check_compatible(fdt_efi, module_node_offset,
                                               "multiboot,module");
     if ( module_compat < 0 )
         /* Error while checking the compatible string */
@@ -730,7 +730,7 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
         return 0;
 
     /* Read xen,uefi-binary property to get the file name. */
-    uefi_name_prop = fdt_getprop(fdt, module_node_offset, "xen,uefi-binary",
+    uefi_name_prop = fdt_getprop(fdt_efi, module_node_offset, "xen,uefi-binary",
                                  &uefi_name_len);
 
     if ( !uefi_name_prop )
@@ -751,13 +751,13 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
     snprintf(mod_string, sizeof(mod_string), "module@%"PRIx64, file->addr);
 
     /* Rename the module to be module@{address} */
-    if ( fdt_set_name(fdt, module_node_offset, mod_string) < 0 )
+    if ( fdt_set_name(fdt_efi, module_node_offset, mod_string) < 0 )
     {
         PrintMessage(L"Unable to modify module node name.");
         return ERROR_RENAME_MODULE_NAME;
     }
 
-    if ( fdt_set_reg(fdt, module_node_offset, reg_addr_cells, reg_size_cells,
+    if ( fdt_set_reg(fdt_efi, module_node_offset, reg_addr_cells, reg_size_cells,
                      file->addr, file->size) < 0 )
     {
         PrintMessage(L"Unable to set module reg property.");
@@ -766,7 +766,7 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
 
     if ( !is_domu_module )
     {
-        if ( (fdt_node_check_compatible(fdt, module_node_offset,
+        if ( (fdt_node_check_compatible(fdt_efi, module_node_offset,
                                     "multiboot,kernel") == 0) )
         {
             /*
@@ -784,14 +784,14 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
             kernel.size = file->size;
         }
         else if ( ramdisk.addr &&
-                  (fdt_node_check_compatible(fdt, module_node_offset,
+                  (fdt_node_check_compatible(fdt_efi, module_node_offset,
                                              "multiboot,ramdisk") == 0) )
         {
             PrintMessage(L"Dom0 ramdisk already found in cfg file.");
             return ERROR_DOM0_RAMDISK_FOUND;
         }
         else if ( xsm.addr &&
-                  (fdt_node_check_compatible(fdt, module_node_offset,
+                  (fdt_node_check_compatible(fdt_efi, module_node_offset,
                                              "xen,xsm-policy") == 0) )
         {
             PrintMessage(L"XSM policy already found in cfg file.");
@@ -816,7 +816,7 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima
     unsigned int mb_modules_found = 0;
 
     /* Get #address-cells and #size-cells from domain node */
-    prop = fdt_get_property(fdt, domain_node, "#address-cells", &len);
+    prop = fdt_get_property(fdt_efi, domain_node, "#address-cells", &len);
     if ( !prop )
     {
         PrintMessage(L"#address-cells not found in domain node.");
@@ -825,7 +825,7 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima
 
     addr_cells = fdt32_to_cpu(*((uint32_t *)prop->data));
 
-    prop = fdt_get_property(fdt, domain_node, "#size-cells", &len);
+    prop = fdt_get_property(fdt_efi, domain_node, "#size-cells", &len);
     if ( !prop )
     {
         PrintMessage(L"#size-cells not found in domain node.");
@@ -835,9 +835,9 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima
     size_cells = fdt32_to_cpu(*((uint32_t *)prop->data));
 
     /* Check for nodes compatible with multiboot,module inside this node */
-    for ( module_node = fdt_first_subnode(fdt, domain_node);
+    for ( module_node = fdt_first_subnode(fdt_efi, domain_node);
           module_node > 0;
-          module_node = fdt_next_subnode(fdt, module_node) )
+          module_node = fdt_next_subnode(fdt_efi, module_node) )
     {
         int ret = handle_module_node(loaded_image, dir_handle, module_node,
                                      addr_cells, size_cells, true);
@@ -862,7 +862,7 @@ static int __init efi_check_dt_boot(const EFI_LOADED_IMAGE *loaded_image)
     EFI_FILE_HANDLE dir_handle = NULL;
 
     /* Check for the chosen node in the current DTB */
-    chosen = setup_chosen_node(fdt, &addr_len, &size_len);
+    chosen = setup_chosen_node(fdt_efi, &addr_len, &size_len);
     if ( chosen < 0 )
     {
         PrintMessage(L"Unable to setup chosen node");
@@ -870,13 +870,13 @@ static int __init efi_check_dt_boot(const EFI_LOADED_IMAGE *loaded_image)
     }
 
     /* Check for nodes compatible with xen,domain under the chosen node */
-    for ( node = fdt_first_subnode(fdt, chosen);
+    for ( node = fdt_first_subnode(fdt_efi, chosen);
           node > 0;
-          node = fdt_next_subnode(fdt, node) )
+          node = fdt_next_subnode(fdt_efi, node) )
     {
         int ret;
 
-        if ( !fdt_node_check_compatible(fdt, node, "xen,domain") )
+        if ( !fdt_node_check_compatible(fdt_efi, node, "xen,domain") )
         {
             /* Found a node with compatible xen,domain; handle this node. */
             ret = handle_dom0less_domain_node(loaded_image, &dir_handle, node);
@@ -951,29 +951,29 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
      * node to decide whether to skip the UEFI Xen configuration file or not.
      */
 
-    fdt = lookup_fdt_config_table(SystemTable);
-    dtbfile.ptr = fdt;
+    fdt_efi = lookup_fdt_config_table(SystemTable);
+    dtbfile.ptr = fdt_efi;
     dtbfile.need_to_free = false; /* Config table memory can't be freed. */
 
-    if ( fdt &&
-         (fdt_node_offset_by_compatible(fdt, 0, "multiboot,module") > 0) )
+    if ( fdt_efi &&
+         (fdt_node_offset_by_compatible(fdt_efi, 0, "multiboot,module") > 0) )
     {
         /* Locate chosen node */
-        int node = fdt_subnode_offset(fdt, 0, "chosen");
+        int node = fdt_subnode_offset(fdt_efi, 0, "chosen");
         const void *cfg_load_prop;
         int cfg_load_len;
 
         if ( node > 0 )
         {
             /* Check if xen,uefi-cfg-load property exists */
-            cfg_load_prop = fdt_getprop(fdt, node, "xen,uefi-cfg-load",
+            cfg_load_prop = fdt_getprop(fdt_efi, node, "xen,uefi-cfg-load",
                                         &cfg_load_len);
             if ( !cfg_load_prop )
                 load_cfg_file = false;
         }
     }
 
-    if ( !fdt || load_cfg_file )
+    if ( !fdt_efi || load_cfg_file )
     {
         /*
          * We either have no FDT, or one without modules, so we must have a
@@ -983,7 +983,7 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
     }
     PrintStr(L"Using modules provided by bootloader in FDT\r\n");
     /* We have modules already defined in fdt, just add space. */
-    fdt = fdt_increase_size(&dtbfile, EFI_PAGE_SIZE);
+    fdt_efi = fdt_increase_size(&dtbfile, EFI_PAGE_SIZE);
 
     return false;
 }
Signature · 1 line
2.34.1
Reviewed-by on v2 3/3
#7 lore raw

Re: [XEN PATCH v2 3/3] arm/efi: address MISRA C:2012 Rule 5.3

Quoted 10 lines · Nicola Vetrini

Rule 5.3 has the following headline:
"An identifier declared in an inner scope shall not hide an identifier declared in an outer scope"

The file-scope variable 'fdt' is shadowed by function parameters, and thus violates the rule, hence it's renamed to 'fdt_efi'

No functional changes.

Quoted 304 lines

---
Changes in v2:
- Renamed the file-scope variable instead of removing function parameters.

---
 xen/arch/arm/efi/efi-boot.h | 84 ++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 42 deletions(-)
xen/arch/arm/efi/efi-boot.h +42 -42
index 6126a71400..f24df2abb9 100644
@@ -49,7 +49,7 @@ static void PrintMessage(const CHAR16 *s);
 {0xb1b621d5U, 0xf19c, 0x41a5, {0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0}}
 
 static struct file __initdata dtbfile;
-static void __initdata *fdt;
+static void __initdata *fdt_efi;
 static void __initdata *memmap;
 
 static int __init setup_chosen_node(void *fdt, int *addr_cells, int *size_cells)
@@ -383,7 +383,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
     if ( EFI_ERROR(status) )
         blexit(L"EFI memory map processing failed");
 
-    status = fdt_add_uefi_nodes(SystemTable, fdt, map, map_size, desc_size,
+    status = fdt_add_uefi_nodes(SystemTable, fdt_efi, map, map_size, desc_size,
                                 desc_ver);
     if ( EFI_ERROR(status) )
         PrintErrMesg(L"Updating FDT failed", status);
@@ -395,7 +395,7 @@ static void __init efi_arch_pre_exit_boot(void)
 
 static void __init noreturn efi_arch_post_exit_boot(void)
 {
-    efi_xen_start(fdt, fdt_totalsize(fdt));
+    efi_xen_start(fdt_efi, fdt_totalsize(fdt_efi));
 }
 
 static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image,
@@ -420,8 +420,8 @@ static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image,
             efi_bs->FreePool(name.w);
         }
     }
-    fdt = fdt_increase_size(&dtbfile, cfg.size + EFI_PAGE_SIZE);
-    if ( !fdt )
+    fdt_efi = fdt_increase_size(&dtbfile, cfg.size + EFI_PAGE_SIZE);
+    if ( !fdt_efi )
         blexit(L"Unable to create new FDT");
 }
 
@@ -465,7 +465,7 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
     int chosen;
 
     /* locate chosen node, which is where we add Xen module info. */
-    chosen = fdt_subnode_offset(fdt, 0, "chosen");
+    chosen = fdt_subnode_offset(fdt_efi, 0, "chosen");
     if ( chosen < 0 )
         blexit(L"Unable to find chosen node");
 
@@ -498,7 +498,7 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
     else
     {
         /* Get xen,xen-bootargs in /chosen if it is specified */
-        const char *dt_bootargs_prop = fdt_getprop(fdt, chosen,
+        const char *dt_bootargs_prop = fdt_getprop(fdt_efi, chosen,
                                                    "xen,xen-bootargs", NULL);
         if ( dt_bootargs_prop )
         {
@@ -526,7 +526,7 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
             blexit(L"FDT string overflow");
     }
 
-    if ( fdt_setprop_string(fdt, chosen, "xen,xen-bootargs", buf) < 0 )
+    if ( fdt_setprop_string(fdt_efi, chosen, "xen,xen-bootargs", buf) < 0 )
         blexit(L"Unable to set xen,xen-bootargs property.");
 
     efi_bs->FreePool(buf);
@@ -542,7 +542,7 @@ static void __init efi_arch_handle_module(const struct file *file,
 
     if ( file == &dtbfile )
         return;
-    chosen = setup_chosen_node(fdt, &addr_len, &size_len);
+    chosen = setup_chosen_node(fdt_efi, &addr_len, &size_len);
     if ( chosen < 0 )
         blexit(L"Unable to setup chosen node");
 
@@ -551,13 +551,13 @@ static void __init efi_arch_handle_module(const struct file *file,
         static const char __initconst ramdisk_compat[] = "multiboot,ramdisk\0"
                                                          "multiboot,module";
 
-        node = fdt_add_subnode(fdt, chosen, "ramdisk");
+        node = fdt_add_subnode(fdt_efi, chosen, "ramdisk");
         if ( node < 0 )
             blexit(L"Unable to add ramdisk FDT node.");
-        if ( fdt_setprop(fdt, node, "compatible", ramdisk_compat,
+        if ( fdt_setprop(fdt_efi, node, "compatible", ramdisk_compat,
                          sizeof(ramdisk_compat)) < 0 )
             blexit(L"Unable to set compatible property.");
-        if ( fdt_set_reg(fdt, node, addr_len, size_len, ramdisk.addr,
+        if ( fdt_set_reg(fdt_efi, node, addr_len, size_len, ramdisk.addr,
                     ramdisk.size) < 0 )
             blexit(L"Unable to set reg property.");
     }
@@ -566,13 +566,13 @@ static void __init efi_arch_handle_module(const struct file *file,
         static const char __initconst xsm_compat[] = "xen,xsm-policy\0"
                                                      "multiboot,module";
 
-        node = fdt_add_subnode(fdt, chosen, "xsm");
+        node = fdt_add_subnode(fdt_efi, chosen, "xsm");
         if ( node < 0 )
             blexit(L"Unable to add xsm FDT node.");
-        if ( fdt_setprop(fdt, node, "compatible", xsm_compat,
+        if ( fdt_setprop(fdt_efi, node, "compatible", xsm_compat,
                          sizeof(xsm_compat)) < 0 )
             blexit(L"Unable to set compatible property.");
-        if ( fdt_set_reg(fdt, node, addr_len, size_len, xsm.addr,
+        if ( fdt_set_reg(fdt_efi, node, addr_len, size_len, xsm.addr,
                     xsm.size) < 0 )
             blexit(L"Unable to set reg property.");
     }
@@ -581,15 +581,15 @@ static void __init efi_arch_handle_module(const struct file *file,
         static const char __initconst kernel_compat[] = "multiboot,kernel\0"
                                                         "multiboot,module";
 
-        node = fdt_add_subnode(fdt, chosen, "kernel");
+        node = fdt_add_subnode(fdt_efi, chosen, "kernel");
         if ( node < 0 )
             blexit(L"Unable to add dom0 FDT node.");
-        if ( fdt_setprop(fdt, node, "compatible", kernel_compat,
+        if ( fdt_setprop(fdt_efi, node, "compatible", kernel_compat,
                          sizeof(kernel_compat)) < 0 )
             blexit(L"Unable to set compatible property.");
-        if ( options && fdt_setprop_string(fdt, node, "bootargs", options) < 0 )
+        if ( options && fdt_setprop_string(fdt_efi, node, "bootargs", options) < 0 )
             blexit(L"Unable to set bootargs property.");
-        if ( fdt_set_reg(fdt, node, addr_len, size_len, kernel.addr,
+        if ( fdt_set_reg(fdt_efi, node, addr_len, size_len, kernel.addr,
                          kernel.size) < 0 )
             blexit(L"Unable to set reg property.");
     }
@@ -719,7 +719,7 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
     module_info *file;
 
     /* Check if the node is a multiboot,module otherwise return */
-    module_compat = fdt_node_check_compatible(fdt, module_node_offset,
+    module_compat = fdt_node_check_compatible(fdt_efi, module_node_offset,
                                               "multiboot,module");
     if ( module_compat < 0 )
         /* Error while checking the compatible string */
@@ -730,7 +730,7 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
         return 0;
 
     /* Read xen,uefi-binary property to get the file name. */
-    uefi_name_prop = fdt_getprop(fdt, module_node_offset, "xen,uefi-binary",
+    uefi_name_prop = fdt_getprop(fdt_efi, module_node_offset, "xen,uefi-binary",
                                  &uefi_name_len);
 
     if ( !uefi_name_prop )
@@ -751,13 +751,13 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
     snprintf(mod_string, sizeof(mod_string), "module@%"PRIx64, file->addr);
 
     /* Rename the module to be module@{address} */
-    if ( fdt_set_name(fdt, module_node_offset, mod_string) < 0 )
+    if ( fdt_set_name(fdt_efi, module_node_offset, mod_string) < 0 )
     {
         PrintMessage(L"Unable to modify module node name.");
         return ERROR_RENAME_MODULE_NAME;
     }
 
-    if ( fdt_set_reg(fdt, module_node_offset, reg_addr_cells, reg_size_cells,
+    if ( fdt_set_reg(fdt_efi, module_node_offset, reg_addr_cells, reg_size_cells,
                      file->addr, file->size) < 0 )
     {
         PrintMessage(L"Unable to set module reg property.");
@@ -766,7 +766,7 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
 
     if ( !is_domu_module )
     {
-        if ( (fdt_node_check_compatible(fdt, module_node_offset,
+        if ( (fdt_node_check_compatible(fdt_efi, module_node_offset,
                                     "multiboot,kernel") == 0) )
         {
             /*
@@ -784,14 +784,14 @@ static int __init handle_module_node(const EFI_LOADED_IMAGE *loaded_image,
             kernel.size = file->size;
         }
         else if ( ramdisk.addr &&
-                  (fdt_node_check_compatible(fdt, module_node_offset,
+                  (fdt_node_check_compatible(fdt_efi, module_node_offset,
                                              "multiboot,ramdisk") == 0) )
         {
             PrintMessage(L"Dom0 ramdisk already found in cfg file.");
             return ERROR_DOM0_RAMDISK_FOUND;
         }
         else if ( xsm.addr &&
-                  (fdt_node_check_compatible(fdt, module_node_offset,
+                  (fdt_node_check_compatible(fdt_efi, module_node_offset,
                                              "xen,xsm-policy") == 0) )
         {
             PrintMessage(L"XSM policy already found in cfg file.");
@@ -816,7 +816,7 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima
     unsigned int mb_modules_found = 0;
 
     /* Get #address-cells and #size-cells from domain node */
-    prop = fdt_get_property(fdt, domain_node, "#address-cells", &len);
+    prop = fdt_get_property(fdt_efi, domain_node, "#address-cells", &len);
     if ( !prop )
     {
         PrintMessage(L"#address-cells not found in domain node.");
@@ -825,7 +825,7 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima
 
     addr_cells = fdt32_to_cpu(*((uint32_t *)prop->data));
 
-    prop = fdt_get_property(fdt, domain_node, "#size-cells", &len);
+    prop = fdt_get_property(fdt_efi, domain_node, "#size-cells", &len);
     if ( !prop )
     {
         PrintMessage(L"#size-cells not found in domain node.");
@@ -835,9 +835,9 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima
     size_cells = fdt32_to_cpu(*((uint32_t *)prop->data));
 
     /* Check for nodes compatible with multiboot,module inside this node */
-    for ( module_node = fdt_first_subnode(fdt, domain_node);
+    for ( module_node = fdt_first_subnode(fdt_efi, domain_node);
           module_node > 0;
-          module_node = fdt_next_subnode(fdt, module_node) )
+          module_node = fdt_next_subnode(fdt_efi, module_node) )
     {
         int ret = handle_module_node(loaded_image, dir_handle, module_node,
                                      addr_cells, size_cells, true);
@@ -862,7 +862,7 @@ static int __init efi_check_dt_boot(const EFI_LOADED_IMAGE *loaded_image)
     EFI_FILE_HANDLE dir_handle = NULL;
 
     /* Check for the chosen node in the current DTB */
-    chosen = setup_chosen_node(fdt, &addr_len, &size_len);
+    chosen = setup_chosen_node(fdt_efi, &addr_len, &size_len);
     if ( chosen < 0 )
     {
         PrintMessage(L"Unable to setup chosen node");
@@ -870,13 +870,13 @@ static int __init efi_check_dt_boot(const EFI_LOADED_IMAGE *loaded_image)
     }
 
     /* Check for nodes compatible with xen,domain under the chosen node */
-    for ( node = fdt_first_subnode(fdt, chosen);
+    for ( node = fdt_first_subnode(fdt_efi, chosen);
           node > 0;
-          node = fdt_next_subnode(fdt, node) )
+          node = fdt_next_subnode(fdt_efi, node) )
     {
         int ret;
 
-        if ( !fdt_node_check_compatible(fdt, node, "xen,domain") )
+        if ( !fdt_node_check_compatible(fdt_efi, node, "xen,domain") )
         {
             /* Found a node with compatible xen,domain; handle this node. */
             ret = handle_dom0less_domain_node(loaded_image, &dir_handle, node);
@@ -951,29 +951,29 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
      * node to decide whether to skip the UEFI Xen configuration file or not.
      */
 
-    fdt = lookup_fdt_config_table(SystemTable);
-    dtbfile.ptr = fdt;
+    fdt_efi = lookup_fdt_config_table(SystemTable);
+    dtbfile.ptr = fdt_efi;
     dtbfile.need_to_free = false; /* Config table memory can't be freed. */
 
-    if ( fdt &&
-         (fdt_node_offset_by_compatible(fdt, 0, "multiboot,module") > 0) )
+    if ( fdt_efi &&
+         (fdt_node_offset_by_compatible(fdt_efi, 0, "multiboot,module") > 0) )
     {
         /* Locate chosen node */
-        int node = fdt_subnode_offset(fdt, 0, "chosen");
+        int node = fdt_subnode_offset(fdt_efi, 0, "chosen");
         const void *cfg_load_prop;
         int cfg_load_len;
 
         if ( node > 0 )
         {
             /* Check if xen,uefi-cfg-load property exists */
-            cfg_load_prop = fdt_getprop(fdt, node, "xen,uefi-cfg-load",
+            cfg_load_prop = fdt_getprop(fdt_efi, node, "xen,uefi-cfg-load",
                                         &cfg_load_len);
             if ( !cfg_load_prop )
                 load_cfg_file = false;
         }
     }
 
-    if ( !fdt || load_cfg_file )
+    if ( !fdt_efi || load_cfg_file )
     {
         /*
          * We either have no FDT, or one without modules, so we must have a
@@ -983,7 +983,7 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
     }
     PrintStr(L"Using modules provided by bootloader in FDT\r\n");
     /* We have modules already defined in fdt, just add space. */
-    fdt = fdt_increase_size(&dtbfile, EFI_PAGE_SIZE);
+    fdt_efi = fdt_increase_size(&dtbfile, EFI_PAGE_SIZE);
 
     return false;
 }
Signature · 1 line
2.34.1