[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v10 3/6] xen/arm: use DEFINE_SYMBOL as required
Use DEFINE_SYMBOL and the two static inline functions that come with it for comparisons and subtractions of: __init_begin, __init_end, __alt_instructions, __alt_instructions_end, __per_cpu_start, __per_cpu_data_end, _splatform, _eplatform, _sdevice, _edevice, _asdevice, _aedevice. Use explicit casts to uintptr_t when it is not possible to use the provided static inline functions. 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 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/alternative.c | 10 +++++++--- xen/arch/arm/device.c | 13 ++++++++----- xen/arch/arm/mm.c | 7 ++++--- xen/arch/arm/percpu.c | 9 +++++---- xen/arch/arm/platform.c | 9 ++++++--- xen/include/asm-arm/percpu.h | 2 +- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index 52ed7ed..cef9cca 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -38,7 +38,8 @@ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) -extern const struct alt_instr __alt_instructions[], __alt_instructions_end[]; +DEFINE_SYMBOL(struct alt_instr, alt_instr, __alt_instructions, + __alt_instructions_end); struct alt_region { const struct alt_instr *begin; @@ -131,7 +132,10 @@ static int __apply_alternatives(const struct alt_region *region, printk(XENLOG_INFO "alternatives: Patching with alt table %p -> %p\n", region->begin, region->end); - for ( alt = region->begin; alt < region->end; alt++ ) + /* region->begin and region->end might point to different objects. */ + for ( alt = region->begin; + (uintptr_t)alt < (uintptr_t)region->end; + alt++ ) { int nr_inst; @@ -204,7 +208,7 @@ static int __apply_alternatives_multi_stop(void *unused) BUG_ON(!xenmap); region.begin = __alt_instructions; - region.end = __alt_instructions_end; + region.end = (struct alt_instr *)__alt_instructions_end; ret = __apply_alternatives(®ion, xenmap - (void *)_start); /* The patching is not expected to fail during boot. */ diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 70cd6c1..1ecb9b7 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -22,8 +22,9 @@ #include <xen/init.h> #include <xen/lib.h> -extern const struct device_desc _sdevice[], _edevice[]; -extern const struct acpi_device_desc _asdevice[], _aedevice[]; +DEFINE_SYMBOL(struct device_desc, device_desc, _sdevice, _edevice); +DEFINE_SYMBOL(struct acpi_device_desc, acpi_device_desc, _asdevice, + _aedevice); int __init device_init(struct dt_device_node *dev, enum device_class class, const void *data) @@ -35,7 +36,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 +57,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 +78,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..9f31e81 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -157,7 +157,7 @@ unsigned long frametable_virt_end __read_mostly; unsigned long max_page; unsigned long total_pages; -extern char __init_begin[], __init_end[]; +DEFINE_SYMBOL(char, init, __init_begin, __init_end); /* Checking VA memory layout alignment. */ static inline void check_memory_layout_alignment_constraints(void) { @@ -1122,7 +1122,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 +1140,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..502739d 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) { @@ -22,8 +23,8 @@ static int init_percpu_area(unsigned int cpu) 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] = (uintptr_t)p - (uintptr_t)__per_cpu_start; 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..1da33e7 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[]; +DEFINE_SYMBOL(struct platform_desc, 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..a589c1c 100644 --- a/xen/include/asm-arm/percpu.h +++ b/xen/include/asm-arm/percpu.h @@ -6,7 +6,7 @@ #include <xen/types.h> #include <asm/sysregs.h> -extern char __per_cpu_start[], __per_cpu_data_end[]; +DEFINE_SYMBOL(char, 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 |