xen/ACPI: Use const char * for string literals
PATCH 1/1 xen/ACPI: 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: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
--- xen/drivers/acpi/tables.c | 6 +++--- xen/drivers/acpi/tables/tbfadt.c | 2 +- xen/drivers/acpi/tables/tbutils.c | 2 +- xen/drivers/acpi/utilities/utmisc.c | 6 +++--- xen/include/acpi/actables.h | 2 +- xen/include/acpi/acutils.h | 12 ++++++------ xen/include/xen/acpi.h | 6 +++--- 7 files changed, 18 insertions(+), 18 deletions(-)
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/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/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);
Signature · 1 line
2.30.2
Hi 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]>
I had a similar patch in my queue. But never sent as I didn't know whether it would be accepted. This was one of the major blocker for switching the hypervisor to use const string.
Cheers,
Signature · 1 line
Julien Grall
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]>