x86/common: Use const char * for string literals
PATCH 1/1 x86/common: Use const char * for string literals
For pre-ANSI-C compatibility reasons, string literals have a mutable type, but it is undefined behaviour to mutate them.
Swap char *'s to const char *'s for variables which hold string literals.
This fixes several violations of MISRA Rule 7.4:
A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char".
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
--- xen/arch/x86/acpi/cpu_idle.c | 2 +- xen/arch/x86/cpu/mcheck/mce.c | 2 +- xen/arch/x86/cpu/mcheck/mce.h | 2 +- xen/arch/x86/e820.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 4 ++-- xen/arch/x86/include/asm/hvm/hvm.h | 2 +- xen/arch/x86/oprofile/nmi_int.c | 8 ++++---- xen/arch/x86/time.c | 4 ++-- xen/include/xen/dmi.h | 4 ++-- 9 files changed, 15 insertions(+), 15 deletions(-)
xen/arch/x86/acpi/cpu_idle.c +1 -1
@@ -302,7 +302,7 @@ static void print_hw_residencies(uint32_t cpu) hw_res.cc6, hw_res.cc7); } -static char * acpi_cstate_method_name[] = +static const char *const acpi_cstate_method_name[] = {"NONE" ,"SYSIO" ,
xen/arch/x86/cpu/mcheck/mce.c +1 -1
@@ -1706,7 +1706,7 @@ static void mc_panic_dump(void)dprintk (XENLOG_ERR ,"End dump mc_info, %x mcinfo dumped\n" , mcinfo_dumpped); } -void mc_panic (char *s) +void mc_panic (const char *s) { is_mc_panic = true;console_force_unlock ();
xen/arch/x86/cpu/mcheck/mce.h +1 -1
@@ -57,7 +57,7 @@ struct mcinfo_extended *intel_get_extended_msrs(bool mce_available (const struct cpuinfo_x86 *c);unsigned int mce_firstbank (struct cpuinfo_x86 *c);/* Helper functions used for collecting error telemetry */ -void noreturnmc_panic (char *s); +void noreturnmc_panic (const char *s);void x86_mc_get_cpu_info (unsigned ,uint32_t *,uint16_t *,uint16_t *,uint32_t *,uint32_t *,uint32_t *,uint32_t *);
xen/arch/x86/e820.c +1 -1
@@ -363,7 +363,7 @@ static unsigned long __init find_max_pfn(void)return max_pfn; } -static void __init clip_to_limit (uint64_t limit,char *warnmsg) +static void __init clip_to_limit (uint64_t limit,const char *warnmsg) {unsigned int i;char _warnmsg[160 ];
xen/arch/x86/hvm/vmx/vmcs.c +2 -2
@@ -1949,7 +1949,7 @@ static inline unsigned long vmr(unsigned long field) (uint32_t )vmr (fld); \ }) -static void vmx_dump_sel (char *name,uint32_t selector) +static void vmx_dump_sel (const char *name,uint32_t selector) {uint32_t sel, attr, limit;uint64_t base;
@@ -1960,7 +1960,7 @@ static void vmx_dump_sel(char *name, uint32_t selector)printk ("%s: %04x %05x %08x %016" PRIx64"\n" , name, sel, attr, limit, base); } -static void vmx_dump_sel2 (char *name,uint32_t lim) +static void vmx_dump_sel2 (const char *name,uint32_t lim) {uint32_t limit;uint64_t base;
xen/arch/x86/include/asm/hvm/hvm.h +1 -1
@@ -92,7 +92,7 @@ struct hvm_vcpu_nonreg_state {* supports Intel's VT-x and AMD's SVM extensions. */ struct hvm_function_table { -char *name; +const char *name;/* Support Hardware-Assisted Paging? */ bool_t hap_supported;
xen/arch/x86/oprofile/nmi_int.c +4 -4
@@ -36,7 +36,7 @@ struct op_x86_model_spec const *__read_mostly model;static struct op_msrs cpu_msrs[NR_CPUS ];static unsigned long saved_lvtpc[NR_CPUS ]; -static char *cpu_type; +static const char *cpu_type; static DEFINE_PER_CPU(struct vcpu *, nmi_cont_vcpu);
@@ -309,7 +309,7 @@ void nmi_stop(void) } -static int __init p4_init (char ** cpu_type) +static int __init p4_init (const char **cpu_type) {unsigned int cpu_model = current_cpu_data.x86_model;
@@ -353,7 +353,7 @@ static int __init cf_check force_cpu_type(const char *str) }custom_param ("cpu_type" , force_cpu_type); -static int __init ppro_init (char ** cpu_type) +static int __init ppro_init (const char **cpu_type) {if (force_arch_perfmon && cpu_has_arch_perfmon)return 0 ;
@@ -375,7 +375,7 @@ static int __init ppro_init(char ** cpu_type)return 1 ; } -static int __init arch_perfmon_init (char **cpu_type) +static int __init arch_perfmon_init (const char **cpu_type) {if (!cpu_has_arch_perfmon)return 0 ;
xen/arch/x86/time.c +2 -2
@@ -64,8 +64,8 @@ struct cpu_time { };struct platform_timesource { -char *id; -char *name; +const char *id; +const char *name;u64 frequency;/* Post-init this hook may only be invoked via the read_counter() wrapper! */ u64 (*read_counter)(void );
xen/include/xen/dmi.h +2 -2
@@ -20,12 +20,12 @@ enum dmi_field {*/ struct dmi_strmatch {u8 slot; -char *substr; +const char *substr; };struct dmi_system_id {int (*callback)(const struct dmi_system_id *); -char *ident; +const char *ident;struct dmi_strmatch matches[4 ];void *driver_data; };
Signature · 1 line
2.30.2
Hmm, I intended this to be xen/x86: as a subject.
Fixed locally, but I won't resend for just this.
~Andrew
Quoted 5 lines · Andrew Cooper
For pre-ANSI-C compatibility reasons, string literals have a mutable type, but it is undefined behaviour to mutate them.
Swap char *'s to const char *'s for variables which hold string literals.
Quoted 8 lines
This fixes several violations of MISRA Rule 7.4:
A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char".
No functional change.
Signed-off-by Andrew Cooper <[email protected]>