gpio: acpi: work around false-positive -Wstring-overflow warning
PATCH 1/1 gpio: acpi: work around false-positive -Wstring-overflow warning
gcc-7 notices that the pin_table is an array of 16-bit numbers, but fails to take the following range check into account:
drivers/gpio/gpiolib-acpi.c: In function 'acpi_gpiochip_request_interrupt':drivers/gpio/gpiolib-acpi.c:206:24: warning: '%02X' directive writing between 2 and 4 bytes into a region of size 3 [-Wformat-overflow=]
sprintf(ev_name, "_%c%02X",
^~~~
drivers/gpio/gpiolib-acpi.c:206:20: note: directive argument in the range [0, 65535]
sprintf(ev_name, "_%c%02X",
^~~~~~~~~
drivers/gpio/gpiolib-acpi.c:206:3: note: 'sprintf' output between 5 and 7 bytes into a destination of size 5
sprintf(ev_name, "_%c%02X",
^~~~~~~~~~~~~~~~~~~~~~~~~~~
agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pin);
~~~~As suggested by Andy, this changes the format string to have a fixed length. Since modifying the range check did not help, I also opened a bug against gcc, see link below.
--- drivers/gpio/gpiolib-acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-acpi.c +1 -1
@@ -203,7 +203,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,if (pin <=255 ) {char ev_name[5 ]; -sprintf (ev_name,"_%c%02X" , +sprintf (ev_name,"_%c%02hhX" , agpio->triggering ==ACPI_EDGE_SENSITIVE ?'E' :'L' , pin);if (ACPI_SUCCESS (acpi_get_handle (handle, ev_name, &evt_handle)))
Signature · 1 line
2.9.0
Quoted 18 lines · Arnd Bergmann
gcc-7 notices that the
pin_tableis an array of 16-bit numbers, but fails to take the following range check into account:
drivers/gpio/gpiolib-acpi.c: In function 'acpi_gpiochip_request_interrupt':drivers/gpio/gpiolib-acpi.c:206:24: warning: '%02X' directive writing between 2 and 4 bytes into a region of size 3 [-Wformat-overflow=]
sprintf(ev_name, "_%c%02X",^~~~ drivers/gpio/gpiolib-acpi.c:206:20: note: directive argument in the range [0, 65535] sprintf(ev_name, "_%c%02X", ^~~~~~~~~ drivers/gpio/gpiolib-acpi.c:206:3: note: 'sprintf' output between 5 and 7 bytes into a destination of size 5 sprintf(ev_name, "_%c%02X", ^~~~~~~~~~~~~~~~~~~~~~~~~~~ agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pin); ~~~~
Quoted 3 lines
As suggested by Andy, this changes the format string to have a fixed length. Since modifying the range check did not help, I also opened a bug against gcc, see link below.
The code has
int pin
does changing pin to unsigned int matter?
drivers/gpio/gpiolib-acpi.c
Quoted 1 line
drivers/gpio/gpiolib-acpi.c +0
-0
[]
Quoted 9 lines
drivers/gpio/gpiolib-acpi.c +1
-1@@ -203,7 +203,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,if (pin <=255 ) {char ev_name[5 ]; -sprintf (ev_name,"_%c%02X" , +sprintf (ev_name,"_%c%02hhX" , agpio->triggering ==ACPI_EDGE_SENSITIVE ?'E' :'L' , pin);if (ACPI_SUCCESS (acpi_get_handle (handle, ev_name, &evt_handle)))
Quoted 11 lines · Joe Perches
Quoted 3 lines · Arnd Bergmann
As suggested by Andy, this changes the format string to have a fixed length. Since modifying the range check did not help, I also opened a bug against gcc, see link below.
The code has
int pin
does changing pin to unsigned int matter?
No difference, see also the gcc bugzilla report.
Arnd
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Joe Perches
Quoted 3 lines · Arnd Bergmann
As suggested by Andy, this changes the format string to have a fixed length. Since modifying the range check did not help, I also opened a bug against gcc, see link below.
Quoted 7 lines
Quoted 5 lines
The code has
int pin
does changing pin to unsigned int matter?
No difference, see also the gcc bugzilla report.
Perhaps the bug report does not apply here as the function is casting a unsigned int to an int through a pointer when the int could now be negative, the int is tested for < 256 and is then printed.
Quoted 22 lines · Arnd Bergmann
gcc-7 notices that the
pin_tableis an array of 16-bit numbers, but fails to take the following range check into account:
drivers/gpio/gpiolib-acpi.c: In function 'acpi_gpiochip_request_interrupt':drivers/gpio/gpiolib-acpi.c:206:24: warning: '%02X' directive writing between 2 and 4 bytes into a region of size 3 [-Wformat-overflow=]
sprintf(ev_name, "_%c%02X",^~~~ drivers/gpio/gpiolib-acpi.c:206:20: note: directive argument in the range [0, 65535] sprintf(ev_name, "_%c%02X", ^~~~~~~~~ drivers/gpio/gpiolib-acpi.c:206:3: note: 'sprintf' output between 5 and 7 bytes into a destination of size 5 sprintf(ev_name, "_%c%02X", ^~~~~~~~~~~~~~~~~~~~~~~~~~~ agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pin); ~~~~As suggested by Andy, this changes the format string to have a fixed length. Since modifying the range check did not help, I also opened a bug against gcc, see link below.
Quoted 5 lines
Fixes 0d1c28a449c6 ("gpiolib-acpi: Add ACPI5 event model support to gpio.")Cc Andy Shevchenko <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>
Quoted 22 lines · Arnd Bergmann
gcc-7 notices that the
pin_tableis an array of 16-bit numbers, but fails to take the following range check into account:
drivers/gpio/gpiolib-acpi.c: In function 'acpi_gpiochip_request_interrupt':drivers/gpio/gpiolib-acpi.c:206:24: warning: '%02X' directive writing between 2 and 4 bytes into a region of size 3 [-Wformat-overflow=]
sprintf(ev_name, "_%c%02X",^~~~ drivers/gpio/gpiolib-acpi.c:206:20: note: directive argument in the range [0, 65535] sprintf(ev_name, "_%c%02X", ^~~~~~~~~ drivers/gpio/gpiolib-acpi.c:206:3: note: 'sprintf' output between 5 and 7 bytes into a destination of size 5 sprintf(ev_name, "_%c%02X", ^~~~~~~~~~~~~~~~~~~~~~~~~~~ agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pin); ~~~~As suggested by Andy, this changes the format string to have a fixed length. Since modifying the range check did not help, I also opened a bug against gcc, see link below.
Quoted 5 lines
Fixes 0d1c28a449c6 ("gpiolib-acpi: Add ACPI5 event model support to gpio.")Cc Andy Shevchenko <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>
Patch applied with Mika's ACK.
Yours,
Linus Walleij