Message ID | a2ec33d23fbc956d6b84e3736ff7f09549ab85b6.1690893696.git.nicola.vetrini@bugseng.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | xen: address MISRA C:2012 Rule 5.3 | expand |
On 01.08.2023 14:47, Nicola Vetrini wrote: > --- a/xen/common/compat/memory.c > +++ b/xen/common/compat/memory.c > @@ -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); 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) Acked-by: Jan Beulich <jbeulich@suse.com> Jan
On 01/08/2023 15:33, Jan Beulich wrote: > On 01.08.2023 14:47, Nicola Vetrini wrote: >> --- a/xen/common/compat/memory.c >> +++ b/xen/common/compat/memory.c >> @@ -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); > > 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.
diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c index 8ca63ceda6..d000a5d93d 100644 --- a/xen/common/compat/memory.c +++ b/xen/common/compat/memory.c @@ -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; } diff --git a/xen/common/numa.c b/xen/common/numa.c index fc1f7f665b..f454c4d894 100644 --- a/xen/common/numa.c +++ b/xen/common/numa.c @@ -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++ )
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. Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com> --- 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(-)