* [PATCH 18/22] gpio: acpi: fix string overflow for large pin numbers
[not found] <20170714120720.906842-1-arnd@arndb.de>
@ 2017-07-14 12:07 ` Arnd Bergmann
2017-07-14 12:52 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2017-07-14 12:07 UTC (permalink / raw)
To: linux-kernel, Mika Westerberg, Andy Shevchenko, Linus Walleij
Cc: Greg Kroah-Hartman, Linus Torvalds, Guenter Roeck, akpm, netdev,
David S . Miller, James E . J . Bottomley, Martin K . Petersen,
linux-scsi, x86, Arnd Bergmann, Hans de Goede, Rafael J. Wysocki,
Wei Yongjun, linux-gpio, linux-acpi
gcc-7 notices that the pin_table is an array of 16-bit numbers,
but we assume it can be printed as a two-character hexadecimal
string:
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);
~~~~
This can't be right, so this changes it to truncate the number to
an 8-bit pin number.
Fixes: 0d1c28a449c6 ("gpiolib-acpi: Add ACPI5 event model support to gpio.")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/gpio/gpiolib-acpi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index c9b42dd12dfa..c3faea724af8 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -205,7 +205,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
char ev_name[5];
sprintf(ev_name, "_%c%02X",
agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L',
- pin);
+ (u8)pin);
if (ACPI_SUCCESS(acpi_get_handle(handle, ev_name, &evt_handle)))
handler = acpi_gpio_irq_handler;
}
--
2.9.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 18/22] gpio: acpi: fix string overflow for large pin numbers
2017-07-14 12:07 ` [PATCH 18/22] gpio: acpi: fix string overflow for large pin numbers Arnd Bergmann
@ 2017-07-14 12:52 ` Andy Shevchenko
2017-07-14 19:59 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2017-07-14 12:52 UTC (permalink / raw)
To: Arnd Bergmann, linux-kernel, Mika Westerberg, Linus Walleij
Cc: Greg Kroah-Hartman, Linus Torvalds, Guenter Roeck, akpm, netdev,
David S . Miller, James E . J . Bottomley, Martin K . Petersen,
linux-scsi, x86, Hans de Goede, Rafael J. Wysocki, Wei Yongjun,
linux-gpio, linux-acpi
On Fri, 2017-07-14 at 14:07 +0200, Arnd Bergmann wrote:
> gcc-7 notices that the pin_table is an array of 16-bit numbers,
> but we assume it can be printed as a two-character hexadecimal
> string:
>
> 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);
> ~~~~
This is obviously a false positive warning.
Here we have
int pin = u16 pin_table[0] <= 255 (implying >= 0).
I see few options how to make it more clear
1) your proposal;
2) use "%02hhX" instead;
3) use if (ret >= 0 && ret <= 255) condition.
I would choose one of the 2-3.
In case gcc will complain about 3), file a bug to gcc crazy warning.
>
> This can't be right, so this changes it to truncate the number to
> an 8-bit pin number.
>
> Fixes: 0d1c28a449c6 ("gpiolib-acpi: Add ACPI5 event model support to
> gpio.")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/gpio/gpiolib-acpi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index c9b42dd12dfa..c3faea724af8 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -205,7 +205,7 @@ static acpi_status
> acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
> char ev_name[5];
> sprintf(ev_name, "_%c%02X",
> agpio->triggering == ACPI_EDGE_SENSITIVE ?
> 'E' : 'L',
> - pin);
> + (u8)pin);
> if (ACPI_SUCCESS(acpi_get_handle(handle, ev_name,
> &evt_handle)))
> handler = acpi_gpio_irq_handler;
> }
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 18/22] gpio: acpi: fix string overflow for large pin numbers
2017-07-14 12:52 ` Andy Shevchenko
@ 2017-07-14 19:59 ` Arnd Bergmann
0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2017-07-14 19:59 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linux Kernel Mailing List, Mika Westerberg, Linus Walleij,
Greg Kroah-Hartman, Linus Torvalds, Guenter Roeck, Andrew Morton,
Networking, David S . Miller, James E . J . Bottomley,
Martin K . Petersen, linux-scsi, the arch/x86 maintainers,
Hans de Goede, Rafael J. Wysocki, Wei Yongjun, linux-gpio, ACPI
On Fri, Jul 14, 2017 at 2:52 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Fri, 2017-07-14 at 14:07 +0200, Arnd Bergmann wrote:
>> gcc-7 notices that the pin_table is an array of 16-bit numbers,
>> but we assume it can be printed as a two-character hexadecimal
>> string:
>>
>> 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);
>> ~~~~
>
>
> This is obviously a false positive warning.
>
> Here we have
> int pin = u16 pin_table[0] <= 255 (implying >= 0).
>
> I see few options how to make it more clear
> 1) your proposal;
> 2) use "%02hhX" instead;
> 3) use if (ret >= 0 && ret <= 255) condition.
>
> I would choose one of the 2-3.
>
> In case gcc will complain about 3), file a bug to gcc crazy warning.
Makes sense. I didn't remember the syntax for 2) and couldn't find
it in the man page when I first looked. This seems like a good solution
here.
I'm pretty sure I tried 3) a few times when the warning first showed
up last year, but couldn't get that to work. Filing a gcc bug also seems
like a good idea, but I should first see if it's already fixed. The version
I use for testing at the moment is from late April, and others may
have complained about that already.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-14 19:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20170714120720.906842-1-arnd@arndb.de>
2017-07-14 12:07 ` [PATCH 18/22] gpio: acpi: fix string overflow for large pin numbers Arnd Bergmann
2017-07-14 12:52 ` Andy Shevchenko
2017-07-14 19:59 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).