]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
xen/arm: use DECLARE_BOUNDS as required
authorStefano Stabellini <sstabellini@kernel.org>
Fri, 1 Mar 2019 23:27:14 +0000 (15:27 -0800)
committerStefano Stabellini <sstabellini@kernel.org>
Fri, 1 Mar 2019 23:27:14 +0000 (15:27 -0800)
Use DECLARE_BOUNDS and the two static inline functions that come with it
for comparisons and subtractions of:

__init_begin, __init_end, __per_cpu_start, __per_cpu_data_end,
_splatform, _eplatform, _sdevice, _edevice, _asdevice, _aedevice.

M3CM: Rule-18.2: Subtraction between pointers shall only be applied to
pointers that address elements of the same array

https://wiki.sei.cmu.edu/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array

QAVerify: 2761
Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
CC: JBeulich@suse.com
CC: andrew.cooper3@citrix.com
---
Changes in v11:
- change p type to struct abstract_per_cpu *
- move changes to alternative.c to a new patch
- use DECLARE_BOUNDS

Changes in v10:
- use DEFINE_SYMBOL
- move changes for _start, _end, _stext, _etext, _srodata, _erodata,
  _sinittext, _einittext to a different patch

Changes in v9:
- use SYMBOLS_SUBTRACT and SYMBOLS_COMPARE

xen/arch/arm/device.c
xen/arch/arm/mm.c
xen/arch/arm/percpu.c
xen/arch/arm/platform.c
xen/include/asm-arm/percpu.h

index 70cd6c1a19ca26efccb3d20c46788be19c03ae44..2de71f68f99e0b33fd419e92565ed158a3e2800c 100644 (file)
 #include <xen/init.h>
 #include <xen/lib.h>
 
-extern const struct device_desc _sdevice[], _edevice[];
-extern const struct acpi_device_desc _asdevice[], _aedevice[];
+typedef struct device_desc device_desc_t;
+DECLARE_BOUNDS(device_desc, _sdevice, _edevice);
+typedef struct acpi_device_desc acpi_device_desc_t;
+DECLARE_BOUNDS(acpi_device_desc, _asdevice, _aedevice);
 
 int __init device_init(struct dt_device_node *dev, enum device_class class,
                        const void *data)
@@ -35,7 +37,7 @@ int __init device_init(struct dt_device_node *dev, enum device_class class,
     if ( !dt_device_is_available(dev) || dt_device_for_passthrough(dev) )
         return  -ENODEV;
 
-    for ( desc = _sdevice; desc != _edevice; desc++ )
+    for ( desc = _sdevice; device_desc_diff(desc, _edevice) != 0; desc++ )
     {
         if ( desc->class != class )
             continue;
@@ -56,7 +58,9 @@ int __init acpi_device_init(enum device_class class, const void *data, int class
 {
     const struct acpi_device_desc *desc;
 
-    for ( desc = _asdevice; desc != _aedevice; desc++ )
+    for ( desc = _asdevice;
+          acpi_device_desc_diff(desc, _aedevice) != 0;
+          desc++ )
     {
         if ( ( desc->class != class ) || ( desc->class_type != class_type ) )
             continue;
@@ -75,7 +79,7 @@ enum device_class device_get_class(const struct dt_device_node *dev)
 
     ASSERT(dev != NULL);
 
-    for ( desc = _sdevice; desc != _edevice; desc++ )
+    for ( desc = _sdevice; device_desc_diff(desc, _edevice) != 0; desc++ )
     {
         if ( dt_match_node(desc->dt_match, dev) )
             return desc->class;
index 01ae2cccc0682af642fbbe69c9b8167397ede291..df52b26ab26333116d641398785b4e0772f1a5c5 100644 (file)
@@ -157,7 +157,8 @@ unsigned long frametable_virt_end __read_mostly;
 unsigned long max_page;
 unsigned long total_pages;
 
-extern char __init_begin[], __init_end[];
+typedef char init_t;
+DECLARE_BOUNDS(init, __init_begin, __init_end);
 
 /* Checking VA memory layout alignment. */
 static inline void check_memory_layout_alignment_constraints(void) {
@@ -1122,7 +1123,7 @@ static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg)
 void free_init_memory(void)
 {
     paddr_t pa = virt_to_maddr(__init_begin);
-    unsigned long len = __init_end - __init_begin;
+    unsigned long len = init_diff(__init_begin, __init_end);
     uint32_t insn;
     unsigned int i, nr = len / sizeof(insn);
     uint32_t *p;
@@ -1140,7 +1141,8 @@ void free_init_memory(void)
 
     set_pte_flags_on_range(__init_begin, len, mg_clear);
     init_domheap_pages(pa, pa + len);
-    printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
+    printk("Freed %ldkB init memory.\n",
+           init_diff(__init_begin, __init_end) >> 10);
 }
 
 void arch_dump_shared_mem_info(void)
index 25442c48fe90dc93446e4671cd8439de51e68446..874d52cfe62ae6c095966f43a659fd0e4f113339 100644 (file)
@@ -6,7 +6,8 @@
 
 unsigned long __per_cpu_offset[NR_CPUS];
 #define INVALID_PERCPU_AREA (-(long)__per_cpu_start)
-#define PERCPU_ORDER (get_order_from_bytes(__per_cpu_data_end-__per_cpu_start))
+#define PERCPU_ORDER (get_order_from_bytes(per_cpu_diff(__per_cpu_start,      \
+                                                        __per_cpu_data_end)))
 
 void __init percpu_init_areas(void)
 {
@@ -17,13 +18,13 @@ void __init percpu_init_areas(void)
 
 static int init_percpu_area(unsigned int cpu)
 {
-    char *p;
+    struct abstract_per_cpu *p;
     if ( __per_cpu_offset[cpu] != INVALID_PERCPU_AREA )
         return -EBUSY;
     if ( (p = alloc_xenheap_pages(PERCPU_ORDER, 0)) == NULL )
         return -ENOMEM;
-    memset(p, 0, __per_cpu_data_end - __per_cpu_start);
-    __per_cpu_offset[cpu] = p - __per_cpu_start;
+    memset(p, 0, per_cpu_diff(__per_cpu_start, __per_cpu_data_end));
+    __per_cpu_offset[cpu] = per_cpu_diff(__per_cpu_start, p);
     return 0;
 }
 
@@ -37,7 +38,7 @@ static void _free_percpu_area(struct rcu_head *head)
 {
     struct free_info *info = container_of(head, struct free_info, rcu);
     unsigned int cpu = info->cpu;
-    char *p = __per_cpu_start + __per_cpu_offset[cpu];
+    char *p = (char *)__per_cpu_start + __per_cpu_offset[cpu];
     free_xenheap_pages(p, PERCPU_ORDER);
     __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
 }
index 8eb0b6e57a5a784f9ca6ff8e199e024382594963..007527e96e8be43da3aa55d09f78a69fd20f29e8 100644 (file)
@@ -22,7 +22,8 @@
 #include <xen/init.h>
 #include <asm/psci.h>
 
-extern const struct platform_desc _splatform[], _eplatform[];
+typedef struct platform_desc platform_desc_t;
+DECLARE_BOUNDS(platform_desc, _splatform, _eplatform);
 
 /* Pointer to the current platform description */
 static const struct platform_desc *platform;
@@ -51,14 +52,16 @@ void __init platform_init(void)
     ASSERT(platform == NULL);
 
     /* Looking for the platform description */
-    for ( platform = _splatform; platform != _eplatform; platform++ )
+    for ( platform = _splatform;
+          platform_desc_diff(platform, _eplatform) != 0;
+          platform++ )
     {
         if ( platform_is_compatible(platform) )
             break;
     }
 
     /* We don't have specific operations for this platform */
-    if ( platform == _eplatform )
+    if ( platform_desc_diff(platform, _eplatform) == 0 )
     {
         /* TODO: dump DT machine compatible node */
         printk(XENLOG_INFO "Platform: Generic System\n");
index 6263e772512947067fbcd717ecd0d279811c7eab..3699dd341717974041d276df92a8c246fcb2f521 100644 (file)
@@ -3,10 +3,12 @@
 
 #ifndef __ASSEMBLY__
 
+#include <xen/lib.h>
 #include <xen/types.h>
 #include <asm/sysregs.h>
 
-extern char __per_cpu_start[], __per_cpu_data_end[];
+typedef char per_cpu_t;
+DECLARE_BOUNDS(per_cpu, __per_cpu_start, __per_cpu_data_end);
 extern unsigned long __per_cpu_offset[NR_CPUS];
 void percpu_init_areas(void);