[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v11 4/9] xen/arm: use DECLARE_BOUNDS as required
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@xxxxxxxxxx> CC: JBeulich@xxxxxxxx CC: andrew.cooper3@xxxxxxxxxx --- 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 | 14 +++++++++----- xen/arch/arm/mm.c | 8 +++++--- xen/arch/arm/percpu.c | 11 ++++++----- xen/arch/arm/platform.c | 9 ++++++--- xen/include/asm-arm/percpu.h | 4 +++- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 70cd6c1..2de71f6 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -22,8 +22,10 @@ #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; diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 01ae2cc..df52b26 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -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) diff --git a/xen/arch/arm/percpu.c b/xen/arch/arm/percpu.c index 25442c4..874d52c 100644 --- a/xen/arch/arm/percpu.c +++ b/xen/arch/arm/percpu.c @@ -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; } diff --git a/xen/arch/arm/platform.c b/xen/arch/arm/platform.c index 8eb0b6e..007527e 100644 --- a/xen/arch/arm/platform.c +++ b/xen/arch/arm/platform.c @@ -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"); diff --git a/xen/include/asm-arm/percpu.h b/xen/include/asm-arm/percpu.h index 6263e77..3699dd3 100644 --- a/xen/include/asm-arm/percpu.h +++ b/xen/include/asm-arm/percpu.h @@ -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); -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |