xen: Enable -Wwrite-strings
RFC PATCH 1/1 xen: Enable -Wwrite-strings
Following on from the MISRA discussions.
On x86, most are trivial. The two slightly suspect cases are __hvm_copy() where constness is dependent on flags, and kextra in __start_xen() which only compiles because of laundering the pointer through strstr().
The one case which I can't figure out how to fix is EFI:
In file included from arch/x86/efi/boot.c:700:
arch/x86/efi/efi-boot.h: In function ‘efi_arch_handle_cmdline’:
arch/x86/efi/efi-boot.h:327:16: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
327 | name.s = "xen";
| ^cc1: all warnings being treated as errors
Why do we have something that looks like this ?
union string {
CHAR16 *w;
char *s;
const char *cs;
};---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
--- xen/Makefile | 2 ++ 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/dom0_build.c | 2 +- xen/arch/x86/e820.c | 2 +- xen/arch/x86/hvm/dom0_build.c | 4 ++-- xen/arch/x86/hvm/hvm.c | 8 ++++---- xen/arch/x86/hvm/vmx/vmcs.c | 4 ++-- xen/arch/x86/include/asm/dom0_build.h | 4 ++-- xen/arch/x86/include/asm/hvm/hvm.h | 2 +- xen/arch/x86/include/asm/hvm/support.h | 4 ++-- xen/arch/x86/include/asm/setup.h | 2 +- xen/arch/x86/oprofile/nmi_int.c | 8 ++++---- xen/arch/x86/pv/dom0_build.c | 2 +- xen/arch/x86/setup.c | 9 +++++---- xen/arch/x86/time.c | 4 ++-- xen/common/gunzip.c | 2 +- xen/common/ioreq.c | 3 ++- xen/common/libelf/libelf-dominfo.c | 2 +- xen/drivers/acpi/tables.c | 6 +++--- xen/drivers/acpi/tables/tbfadt.c | 2 +- xen/drivers/acpi/tables/tbutils.c | 2 +- xen/drivers/acpi/tables/tbxface.c | 2 +- xen/drivers/acpi/utilities/utmisc.c | 6 +++--- xen/include/acpi/actables.h | 2 +- xen/include/acpi/actypes.h | 2 +- xen/include/acpi/acutils.h | 12 ++++++------ xen/include/xen/acpi.h | 6 +++--- xen/include/xen/dmi.h | 4 ++-- 30 files changed, 59 insertions(+), 55 deletions(-)
xen/Makefile +2 -0
@@ -384,6 +384,8 @@ else CFLAGS += -fomit-frame-pointer endif +CFLAGS += -Wwrite-strings + CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) += -ffunction-sections -fdata-sections CFLAGS += -nostdinc -fno-builtin -fno-common
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
@@ -58,7 +58,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/dom0_build.c +1 -1
@@ -576,7 +576,7 @@ int __init dom0_setup_permissions(struct domain *d)int __init construct_dom0 (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -char *cmdline) +const char *cmdline) {int rc;
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/dom0_build.c +2 -2
@@ -532,7 +532,7 @@ static paddr_t __init find_memory(static int __init pvh_load_kernel (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd,void *image_base, -char *cmdline,paddr_t *entry, +const char *cmdline,paddr_t *entry,paddr_t *start_info_addr) {void *image_start = image_base + image_headroom;
@@ -1177,7 +1177,7 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain *d)int __init dom0_construct_pvh (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -char *cmdline) +const char *cmdline) {paddr_t entry, start_info;int rc;
xen/arch/x86/hvm/hvm.c +4 -4
@@ -3398,9 +3398,9 @@ static enum hvm_translation_result __hvm_copy( }enum hvm_translation_result hvm_copy_to_guest_phys ( -paddr_t paddr,void *buf,unsigned int size,struct vcpu *v) +paddr_t paddr,const void *buf,unsigned int size,struct vcpu *v) { -return __hvm_copy (buf, paddr, size, v, +return __hvm_copy ((void *)buf/* to_guest doesn't modify */ , paddr, size, v, HVMCOPY_to_guest | HVMCOPY_phys,0 ,NULL ); }
@@ -3412,10 +3412,10 @@ enum hvm_translation_result hvm_copy_from_guest_phys( }enum hvm_translation_result hvm_copy_to_guest_linear ( -unsigned long addr,void *buf,unsigned int size,uint32_t pfec, +unsigned long addr,const void *buf,unsigned int size,uint32_t pfec,pagefault_info_t *pfinfo) { -return __hvm_copy (buf, addr, size, current, +return __hvm_copy ((void *)buf, addr, size, current, HVMCOPY_to_guest | HVMCOPY_linear, PFEC_page_present | PFEC_write_access | pfec, pfinfo); }
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/dom0_build.h +2 -2
@@ -16,12 +16,12 @@ int dom0_setup_permissions(struct domain *d);int dom0_construct_pv (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -char *cmdline); +const char *cmdline);int dom0_construct_pvh (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -char *cmdline); +const char *cmdline);unsigned long dom0_paging_pages (const struct domain *d,unsigned long nr_pages);
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/include/asm/hvm/support.h +2 -2
@@ -59,7 +59,7 @@ enum hvm_translation_result {* address range does not map entirely onto ordinary machine memory. */ enum hvm_translation_result hvm_copy_to_guest_phys ( -paddr_t paddr,void *buf,unsigned int size,struct vcpu *v); +paddr_t paddr,const void *buf,unsigned int size,struct vcpu *v);enum hvm_translation_result hvm_copy_from_guest_phys (void *buf,paddr_t paddr,unsigned int size);
@@ -85,7 +85,7 @@ typedef struct pagefault_info } pagefault_info_t;enum hvm_translation_result hvm_copy_to_guest_linear ( -unsigned long addr,void *buf,unsigned int size,uint32_t pfec, +unsigned long addr,const void *buf,unsigned int size,uint32_t pfec,pagefault_info_t *pfinfo); enum hvm_translation_result hvm_copy_from_guest_linear( void *buf, unsigned long addr, unsigned int size, uint32_t pfec,
xen/arch/x86/include/asm/setup.h +1 -1
@@ -35,7 +35,7 @@ int construct_dom0(struct domain *d, const module_t *kernel, unsigned long kernel_headroom, module_t *initrd, - char *cmdline); + const char *cmdline);void setup_io_bitmap (struct domain *d);unsigned long initial_images_nrpages (nodeid_t node);
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/pv/dom0_build.c +1 -1
@@ -358,7 +358,7 @@ int __init dom0_construct_pv(struct domain *d,const module_t *image, unsigned long image_headroom, module_t *initrd, - char *cmdline) + const char *cmdline) { int i, rc, order, machine;bool compatible, compat;
xen/arch/x86/setup.c +5 -4
@@ -835,7 +835,7 @@ static bool __init loader_is_grub2(const char *loader_name)return (p !=NULL ) && (p[5 ] !='0' ); } -static char *__init cmdline_cook (char *p,const char *loader_name) +static const char *__init cmdline_cook (const char *p,const char *loader_name) { p = p ? :"" ;
@@ -883,7 +883,7 @@ static struct domain *__init create_dom0(const module_t *image, }, };struct domain *d; -char *cmdline; +const char *cmdline;domid_t domid;if ( opt_dom0_pvh )
@@ -968,8 +968,9 @@ static struct domain *__init create_dom0(const module_t *image,void __init noreturn__start_xen (unsigned long mbi_p) { -char *memmap_type =NULL ; -char *cmdline, *kextra, *loader; +const char *memmap_type =NULL ; +const char *cmdline, *loader; +char *kextra;void *bsp_stack;struct cpu_info *info =get_cpu_info (), *bsp_info;unsigned int initrdidx, num_parked =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/common/gunzip.c +1 -1
@@ -52,7 +52,7 @@ typedef unsigned long ulg;static long __initdata bytes_out;static void flush_window (void ); -static __init void error (char *x) +static __init void error (const char *x) {panic ("%s\n" , x); }
xen/common/ioreq.c +2 -1
@@ -501,7 +501,8 @@ static int ioreq_server_alloc_rangesets(struct ioreq_server *s,for ( i =0 ; i <NR_IO_RANGE_TYPES ; i++ ) { -char *name, *type; +const char *type; +char *name;switch ( i ) {
xen/common/libelf/libelf-dominfo.c +1 -1
@@ -100,7 +100,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, {/* *INDENT-OFF* */ static const struct { -char *name; +const char *name;bool str; } note_desc[] = { [XEN_ELFNOTE_ENTRY ] = {"ENTRY" ,0 },
xen/drivers/acpi/tables.c +3 -3
@@ -300,7 +300,7 @@ acpi_table_get_entry_madt(enum acpi_madt_type entry_id, }int __init -acpi_parse_entries (char *id,unsigned long table_size, +acpi_parse_entries (const char *id,unsigned long table_size,acpi_table_entry_handler handler,struct acpi_table_header *table_header,int entry_id,unsigned int max_entries)
@@ -359,7 +359,7 @@ acpi_parse_entries(char *id, unsigned long table_size, } int __init -acpi_table_parse_entries(char *id, +acpi_table_parse_entries(const char *id, unsigned long table_size, int entry_id, acpi_table_entry_handler handler,
@@ -405,7 +405,7 @@ acpi_table_parse_madt(enum acpi_madt_type id,* Scan the ACPI System Descriptor Table (STD) for a table matching @id, * run @handler on it. */ -int __init acpi_table_parse (char *id,acpi_table_handler handler) +int __init acpi_table_parse (const char *id,acpi_table_handler handler) {struct acpi_table_header *table =NULL ;
xen/drivers/acpi/tables/tbfadt.c +1 -1
@@ -60,7 +60,7 @@ static void acpi_tb_validate_fadt(void);/* Table for conversion of FADT to common internal format and FADT validation */ typedef struct acpi_fadt_info { - char *name; + const char *name; u16 target; u16 source; u16 length;
xen/drivers/acpi/tables/tbutils.c +1 -1
@@ -243,7 +243,7 @@ u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)void __init acpi_tb_install_table (acpi_physical_address address, -u8 flags,char *signature,acpi_native_uint table_index) +u8 flags,const char *signature,acpi_native_uint table_index) {struct acpi_table_header *table;
xen/drivers/acpi/tables/tbxface.c +1 -1
@@ -164,7 +164,7 @@ acpi_initialize_tables(struct acpi_table_desc * initial_table_array,* *****************************************************************************/ acpi_status __init -acpi_get_table (char *signature, +acpi_get_table (const char *signature,acpi_native_uint instance,struct acpi_table_header **out_table) {acpi_native_uint i;
xen/drivers/acpi/utilities/utmisc.c +3 -3
@@ -134,7 +134,7 @@ const char *__init acpi_ut_validate_exception(acpi_status status)******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE __init -acpi_ut_error (const char *module_name,u32 line_number,char *format, ...) +acpi_ut_error (const char *module_name,u32 line_number,const char *format, ...) {va_list args;
@@ -147,7 +147,7 @@ acpi_ut_error(const char *module_name, u32 line_number, char *format, ...) } void ACPI_INTERNAL_VAR_XFACE __init -acpi_ut_warning (const char *module_name,u32 line_number,char *format, ...) +acpi_ut_warning (const char *module_name,u32 line_number,const char *format, ...) {va_list args;
@@ -161,7 +161,7 @@ acpi_ut_warning(const char *module_name, u32 line_number, char *format, ...) } void ACPI_INTERNAL_VAR_XFACE __init -acpi_ut_info (const char *module_name,u32 line_number,char *format, ...) +acpi_ut_info (const char *module_name,u32 line_number,const char *format, ...) {va_list args;
xen/include/acpi/actables.h +1 -1
@@ -99,7 +99,7 @@ acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length);void acpi_tb_install_table (acpi_physical_address address, -u8 flags,char *signature,acpi_native_uint table_index); +u8 flags,const char *signature,acpi_native_uint table_index);acpi_status acpi_tb_parse_root_table (acpi_physical_address rsdp_address,u8 flags);
xen/include/acpi/actypes.h +1 -1
@@ -281,7 +281,7 @@ typedef acpi_native_uint acpi_size;*/ typedef u32 acpi_status ;/* All ACPI Exceptions */ typedef u32 acpi_name ;/* 4-byte ACPI name */ -typedef char *acpi_string ;/* Null terminated ASCII string */ +typedef const char *acpi_string ;/* Null terminated ASCII string */ typedef void *acpi_handle ;/* Actually a ptr to a NS Node */ struct uint64_struct {
xen/include/acpi/acutils.h +6 -6
@@ -164,7 +164,7 @@ acpi_ut_debug_print(u32 requested_debug_level,u32 line_number, const char *function_name, const char *module_name, - u32 component_id, char *format, ...) ACPI_PRINTF_LIKE(6); + u32 component_id, const char *format, ...) ACPI_PRINTF_LIKE(6); void ACPI_INTERNAL_VAR_XFACE acpi_ut_debug_print_raw(u32 requested_debug_level,
@@ -172,24 +172,24 @@ acpi_ut_debug_print_raw(u32 requested_debug_level,const char *function_name, const char *module_name, u32 component_id, - char *format, ...) ACPI_PRINTF_LIKE(6); + const char *format, ...) ACPI_PRINTF_LIKE(6); void ACPI_INTERNAL_VAR_XFACE acpi_ut_error(const char *module_name, - u32 line_number, char *format, ...) ACPI_PRINTF_LIKE(3); + u32 line_number, const char *format, ...) ACPI_PRINTF_LIKE(3); void ACPI_INTERNAL_VAR_XFACE acpi_ut_exception(const char *module_name, u32 line_number, - acpi_status status, char *format, ...) ACPI_PRINTF_LIKE(4); + acpi_status status, const char *format, ...) ACPI_PRINTF_LIKE(4); void ACPI_INTERNAL_VAR_XFACE acpi_ut_warning(const char *module_name, - u32 line_number, char *format, ...) ACPI_PRINTF_LIKE(3); + u32 line_number, const char *format, ...) ACPI_PRINTF_LIKE(3); void ACPI_INTERNAL_VAR_XFACE acpi_ut_info(const char *module_name, - u32 line_number, char *format, ...) ACPI_PRINTF_LIKE(3); + u32 line_number, const char *format, ...) ACPI_PRINTF_LIKE(3);/* * utmisc
xen/include/xen/acpi.h +3 -3
@@ -81,12 +81,12 @@ int erst_init(void);void acpi_hest_init (void );int acpi_table_init (void ); -int acpi_table_parse (char *id,acpi_table_handler handler); -int acpi_parse_entries (char *id,unsigned long table_size, +int acpi_table_parse (const char *id,acpi_table_handler handler); +int acpi_parse_entries (const char *id,unsigned long table_size,acpi_table_entry_handler handler,struct acpi_table_header *table_header,int entry_id,unsigned int max_entries); -int acpi_table_parse_entries (char *id,unsigned long table_size, +int acpi_table_parse_entries (const char *id,unsigned long table_size,int entry_id,acpi_table_entry_handler handler,unsigned int max_entries);struct acpi_subtable_header *acpi_table_get_entry_madt (enum acpi_madt_type id,unsigned int entry_index);
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
Quoted 4 lines · Andrew Cooper
Following on from the MISRA discussions.
On x86, most are trivial. The two slightly suspect cases are
__hvm_copy()where constness is dependent on flags,
But do we ever pass string literals into there? I certainly would like to avoid the explicit casts to get rid of the const there.
Quoted 2 lines
and kextra in
__start_xen()which only
compiles because of laundering the pointer throughstrstr().
The sole string literal there looks to be the empty string in cmdline_cook(), which could be easily replaced, I think:
static char * __init cmdline_cook(char *p, const char *loader_name)
{
static char __initdata empty[] = "";
p = p ? : empty;Yet of course only if we were unhappy with the strstr() side effect.
Quoted 9 lines
The one case which I can't figure out how to fix is EFI:
In file included from
arch/x86/efi/boot.c:700:
arch/x86/efi/efi-boot.h: In function ‘efi_arch_handle_cmdline’:
arch/x86/efi/efi-boot.h:327:16: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]327 | name.s = "xen"; | ^cc1: all warnings being treated as errors
Quoted 7 lines
Why do we have something that looks like this ?
union string { CHAR16 *w; char *s; const char *cs; };
Because that was the least clutter (at respective use sites) that I could think of at the time. Looks like you could simply assign to name.cs, now that we have that field (iirc it wasn't there originally). Of course that's then only papering over the issue.
xen/include/acpi/actypes.h typedef acpi_native_uint acpi_size; · line 285
Quoted 9 lines
xen/include/acpi/actypes.h +1
-1@@ -281,7 +281,7 @@ typedef acpi_native_uint acpi_size;*/ typedef u32 acpi_status ;/* All ACPI Exceptions */ typedef u32 acpi_name ;/* 4-byte ACPI name */ -typedef char *acpi_string ;/* Null terminated ASCII string */ +typedef const char *acpi_string ;/* Null terminated ASCII string */ typedef void *acpi_handle ;/* Actually a ptr to a NS Node */
For all present uses that we have this change looks okay, but changing this header leaves me a little uneasy. At the same time I have no better suggestion.
Jan
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Andrew Cooper
Following on from the MISRA discussions.
On x86, most are trivial. The two slightly suspect cases are
__hvm_copy()where constness is dependent on flags,But do we ever pass string literals into there? I certainly would like to avoid the explicit casts to get rid of the const there.
The thing which trips it up is the constness of the cmdline param in the construct_dom0() calltree. It may have been tied up in the constness from cmdline_cook() - I wasn't paying that much attention.
Irrespective, from a conceptual point of view, we ought to be able to use the copy_to_* helpers from a const source.
Quoted 5 lines
Quoted 2 lines
and kextra in
__start_xen()which only
compiles because of laundering the pointer throughstrstr().The sole string literal there looks to be the empty string in
cmdline_cook(), which could be easily replaced, I think:
Quoted 7 lines
static char *
__initcmdline_cook(char *p, const char *loader_name){ static char __initdata empty[] = ""; p = p ? : empty;Yet of course only if we were unhappy with the
strstr()side effect.
It's quite possible we can do something better here. This logic looks unnecessarily complicated and fragile.
Quoted 17 lines
Quoted 10 lines
The one case which I can't figure out how to fix is EFI:
In file included from
arch/x86/efi/boot.c:700:
arch/x86/efi/efi-boot.h: In function ‘efi_arch_handle_cmdline’:
arch/x86/efi/efi-boot.h:327:16: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]327 | name.s = "xen"; | ^cc1: all warnings being treated as errors
Quoted 7 lines
Why do we have something that looks like this ?
union string { CHAR16 *w; char *s; const char *cs; };
Quoted 4 lines
Because that was the least clutter (at respective use sites) that I could think of at the time. Looks like you could simply assign to name.cs, now that we have that field (iirc it wasn't there originally). Of course that's then only papering over the issue.
Well yes. If it's only this one, we could use the same initconst trick and delete the cs field, but I suspect the fields existence means it would cause problems elsewhere.
Quoted 13 lines
xen/include/acpi/actypes.h typedef acpi_native_uint acpi_size; · line 285
Quoted 10 lines
xen/include/acpi/actypes.h +1
-1@@ -281,7 +281,7 @@ typedef acpi_native_uint acpi_size;*/ typedef u32 acpi_status ;/* All ACPI Exceptions */ typedef u32 acpi_name ;/* 4-byte ACPI name */ -typedef char *acpi_string ;/* Null terminated ASCII string */ +typedef const char *acpi_string ;/* Null terminated ASCII string */ typedef void *acpi_handle ;/* Actually a ptr to a NS Node */ For all present uses that we have this change looks okay, but changing this header leaves me a little uneasy. At the same time I have no better suggestion.
I was honestly tempted to purge this typedef with prejudice. Hiding indirection like this is nothing but an obfuscation technique.
~Andrew
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Andrew Cooper
Following on from the MISRA discussions.
On x86, most are trivial. The two slightly suspect cases are
__hvm_copy()where constness is dependent on flags,But do we ever pass string literals into there? I certainly would like to avoid the explicit casts to get rid of the const there.
Quoted 6 lines
The thing which trips it up is the constness of the cmdline param in the
construct_dom0()calltree. It may have been tied up in the constness fromcmdline_cook()- I wasn't paying that much attention.Irrespective, from a conceptual point of view, we ought to be able to use the copy_to_* helpers from a const source.
True. Yet then as a minimal additional change may I ask that you drop the cast that copy_to_user_hvm() has in exchange for the one(s) you add?
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
The one case which I can't figure out how to fix is EFI:
In file included from
arch/x86/efi/boot.c:700:
arch/x86/efi/efi-boot.h: In function ‘efi_arch_handle_cmdline’:
arch/x86/efi/efi-boot.h:327:16: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]327 | name.s = "xen"; | ^cc1: all warnings being treated as errors
Why do we have something that looks like this ?
union string { CHAR16 *w; char *s; const char *cs; };
Quoted 8 lines
Quoted 4 lines
Because that was the least clutter (at respective use sites) that I could think of at the time. Looks like you could simply assign to name.cs, now that we have that field (iirc it wasn't there originally). Of course that's then only papering over the issue.
Well yes. If it's only this one, we could use the same initconst trick and delete the cs field, but I suspect the fields existence means it would cause problems elsewhere.
I'm pretty sure it would (hence why I didn't suggest so); as said I think this field was added much later, maybe in the context of the unified EFI image work.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/include/acpi/actypes.h +0
-0@@ -281,7 +281,7 @@ typedef acpi_native_uint acpi_size;*/ Quoted 8 lines
xen/include/acpi/actypes.h typedef acpi_native_uint acpi_size; · line 285
Quoted 5 lines
xen/include/acpi/actypes.h +1
-1typedef u32 acpi_status ;/* All ACPI Exceptions */ typedef u32 acpi_name ;/* 4-byte ACPI name */ -typedef char *acpi_string ;/* Null terminated ASCII string */ +typedef const char *acpi_string ;/* Null terminated ASCII string */ typedef void *acpi_handle ;/* Actually a ptr to a NS Node */ For all present uses that we have this change looks okay, but changing this header leaves me a little uneasy. At the same time I have no better suggestion.
Quoted 2 lines
I was honestly tempted to purge this typedef with prejudice. Hiding indirection like this is nothing but an obfuscation technique.
To be honest - I think I'd be fine with purging (but then better in a separate patch).
Jan