Skip to contentSkip to conversation

xen/ACPI: Remove the acpi_string type

PATCH In review Andrew Cooper 3 participants 4 messages Jul 14, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/ACPI: Remove the acpi_string type

Typedef-ing a naked pointer like this an anti-pattern which is best avoided. Furthermore, it's bad to pass a string literate in a mutable type. Delete the type entirely, and replace it with a plain 'const char *'.

This highlights two futher bugs. acpi_get_table() already had a mismatch in types between it's declaration and definition, and we have declarations for acpi_get_handle() and acpi_get_table_header() but no definition at all (nor any callers).

This fixes 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".

and of Rule 8.3:

All declarations of an object or function shall use the same names and type qualifiers.

and of Rule 8.6:

An identifier with external linkage shall have exactly one external definition.

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]>

Roberto/Nicola: Please double check my choice of rules here, and point out any others that I may have missed.

---
 xen/drivers/acpi/tables/tbxface.c |  4 ++--
 xen/include/acpi/acpixf.h         | 13 ++-----------
 xen/include/acpi/actypes.h        |  1 -
 3 files changed, 4 insertions(+), 14 deletions(-)
xen/drivers/acpi/tables/tbxface.c +2 -2
index 21b2e5eae1c7..204d66caea48 100644
@@ -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;
@@ -220,7 +220,7 @@ acpi_get_table(char *signature,
  *
  *****************************************************************************/
 acpi_status __init
-acpi_get_table_phys(acpi_string signature, acpi_native_uint instance,
+acpi_get_table_phys(const char *signature, acpi_native_uint instance,
 		     acpi_physical_address *addr, acpi_native_uint *len)
 {
 	acpi_native_uint i, j;
xen/include/acpi/acpixf.h +2 -11
index ba74908f0478..8b70154b8f96 100644
@@ -69,25 +69,16 @@ acpi_status acpi_load_tables(void);
 acpi_status acpi_load_table(struct acpi_table_header *table_ptr);
 
 acpi_status
-acpi_get_table_header(acpi_string signature,
-		      acpi_native_uint instance,
-		      struct acpi_table_header *out_table_header);
-
-acpi_status
-acpi_get_table(acpi_string signature,
+acpi_get_table(const char *signature,
 	       acpi_native_uint instance, struct acpi_table_header **out_table);
 
 acpi_status
-acpi_get_table_phys(acpi_string signature, acpi_native_uint instance,
+acpi_get_table_phys(const char *signature, acpi_native_uint instance,
 		     acpi_physical_address *addr, acpi_native_uint *len);
 /*
  * Namespace and name interfaces
  */
 acpi_status
-acpi_get_handle(acpi_handle parent,
-		acpi_string pathname, acpi_handle * ret_handle);
-
-acpi_status
 acpi_debug_trace(char *name, u32 debug_level, u32 debug_layer, u32 flags);
 
 acpi_status
xen/include/acpi/actypes.h +0 -1
index f3e95abc3ab3..7023863d0349 100644
@@ -281,7 +281,6 @@ 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 void *acpi_handle;	/* Actually a ptr to a NS Node */
 
 struct uint64_struct {
Signature · 1 line
2.30.2
#1 lore raw
Quoted 1 line · Andrew Cooper

Typedef-ing a naked pointer like this an anti-pattern which is best avoided.

s/this an/this is an/

Quoted 1 line

Furthermore, it's bad to pass a string literate in a mutable type. Delete the

s/literate/literal/

Quoted 14 lines

type entirely, and replace it with a plain 'const char *'.

This highlights two futher bugs. acpi_get_table() already had a mismatch in types between it's declaration and definition, and we have declarations for acpi_get_handle() and acpi_get_table_header() but no definition at all (nor any callers).

This fixes 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".

and of Rule 8.3:

Quoted 7 lines

All declarations of an object or function shall use the same names and type qualifiers.

and of Rule 8.6:

An identifier with external linkage shall have exactly one external definition.

The choice of rules looks good to me, but perhaps Roberto has some additional insight on this.

Quoted 87 lines

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]>

Roberto/Nicola: Please double check my choice of rules here, and point out any others that I may have missed.

---
  xen/drivers/acpi/tables/tbxface.c |  4 ++--
  xen/include/acpi/acpixf.h         | 13 ++-----------
  xen/include/acpi/actypes.h        |  1 -
  3 files changed, 4 insertions(+), 14 deletions(-)
xen/drivers/acpi/tables/tbxface.c +2 -2
index 21b2e5eae1c7..204d66caea48 100644
@@ -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;
@@ -220,7 +220,7 @@ acpi_get_table(char *signature,
   *
   *****************************************************************************/
  acpi_status __init
-acpi_get_table_phys(acpi_string signature, acpi_native_uint instance,
+acpi_get_table_phys(const char *signature, acpi_native_uint instance,
  		     acpi_physical_address *addr, acpi_native_uint *len)
  {
  	acpi_native_uint i, j;
xen/include/acpi/acpixf.h +2 -11
index ba74908f0478..8b70154b8f96 100644
@@ -69,25 +69,16 @@ acpi_status acpi_load_tables(void);
  acpi_status acpi_load_table(struct acpi_table_header *table_ptr);
 
  acpi_status
-acpi_get_table_header(acpi_string signature,
-		      acpi_native_uint instance,
-		      struct acpi_table_header *out_table_header);
-
-acpi_status
-acpi_get_table(acpi_string signature,
+acpi_get_table(const char *signature,
  	       acpi_native_uint instance, struct acpi_table_header **out_table);
 
  acpi_status
-acpi_get_table_phys(acpi_string signature, acpi_native_uint instance,
+acpi_get_table_phys(const char *signature, acpi_native_uint instance,
  		     acpi_physical_address *addr, acpi_native_uint *len);
  /*
   * Namespace and name interfaces
   */
  acpi_status
-acpi_get_handle(acpi_handle parent,
-		acpi_string pathname, acpi_handle * ret_handle);
-
-acpi_status
  acpi_debug_trace(char *name, u32 debug_level, u32 debug_layer, u32 flags);
 
  acpi_status
xen/include/acpi/actypes.h +0 -1
index f3e95abc3ab3..7023863d0349 100644
@@ -281,7 +281,6 @@ 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 void *acpi_handle;	/* Actually a ptr to a NS Node */
 
  struct uint64_struct {
Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
#2 lore raw
Quoted 11 lines · Nicola Vetrini
Quoted 2 lines · Andrew Cooper

Typedef-ing a naked pointer like this an anti-pattern which is best avoided.

s/this an/this is an/

Quoted 2 lines

Furthermore, it's bad to pass a string literate in a mutable type. Delete the

s/literate/literal/

Fixed, thanks.  And the 3rd typo below.

Quoted 23 lines
Quoted 23 lines

type entirely, and replace it with a plain 'const char *'.

This highlights two futher bugs.  acpi_get_table() already had a mismatch in
types between it's declaration and definition, and we have declarations for
acpi_get_handle() and acpi_get_table_header() but no definition at all (nor
any callers).

This fixes 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".

and of Rule 8.3:

   All declarations of an object or function shall use the same names and type
   qualifiers.

Quoted 7 lines
Quoted 4 lines

and of Rule 8.6:

   An identifier with external linkage shall have exactly one external definition.

The choice of rules looks good to me, but perhaps Roberto has some additional insight on this.

Thanks.

~Andrew

Acked-by on v1 1/1
#3 lore raw
In reply to Andrew Cooper
Quoted 19 lines · Andrew Cooper

Typedef-ing a naked pointer like this an anti-pattern which is best avoided. Furthermore, it's bad to pass a string literate in a mutable type. Delete the type entirely, and replace it with a plain 'const char *'.

This highlights two futher bugs. acpi_get_table() already had a mismatch in types between it's declaration and definition, and we have declarations for acpi_get_handle() and acpi_get_table_header() but no definition at all (nor any callers).

This fixes 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".

and of Rule 8.3:

All declarations of an object or function shall use the same names and type qualifiers.

Quoted 8 lines

and of Rule 8.6:

An identifier with external linkage shall have exactly one external definition.

No functional change.