* [PATCH] gpio / ACPI: Prevent potential wrap of GPIO value on OpRegion read
@ 2014-04-01 10:03 Mika Westerberg
2014-04-10 16:24 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Mika Westerberg @ 2014-04-01 10:03 UTC (permalink / raw)
To: Linus Walleij
Cc: Alexandre Courbot, Dan Carpenter, linux-gpio, linux-kernel,
Mika Westerberg
Dan Carpenter's static code checker reports:
The patch 473ed7be0da0: "gpio / ACPI: Add support for ACPI GPIO
operation regions" from Mar 14, 2014, leads to the following static
checker warning:
drivers/gpio/gpiolib-acpi.c:454 acpi_gpio_adr_space_handler()
warn: should 'gpiod_get_raw_value(desc) << i' be a 64 bit type?
This is due the fact that *value is of type u64 and gpiod_get_raw_value()
returns int. Since i can be larger than 31, it is possible that the value
returned gets wrapped.
Fix this by casting the return of gpiod_get_raw_value() to u64 first before
shift.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
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 d5be56fe689e..401add28933f 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -451,7 +451,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
if (function == ACPI_WRITE)
gpiod_set_raw_value(desc, !!((1 << i) & *value));
else
- *value |= gpiod_get_raw_value(desc) << i;
+ *value |= (u64)gpiod_get_raw_value(desc) << i;
}
out:
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] gpio / ACPI: Prevent potential wrap of GPIO value on OpRegion read
2014-04-01 10:03 [PATCH] gpio / ACPI: Prevent potential wrap of GPIO value on OpRegion read Mika Westerberg
@ 2014-04-10 16:24 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2014-04-10 16:24 UTC (permalink / raw)
To: Mika Westerberg
Cc: Alexandre Courbot, Dan Carpenter, linux-gpio@vger.kernel.org,
linux-kernel@vger.kernel.org
On Tue, Apr 1, 2014 at 12:03 PM, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
> Dan Carpenter's static code checker reports:
>
> The patch 473ed7be0da0: "gpio / ACPI: Add support for ACPI GPIO
> operation regions" from Mar 14, 2014, leads to the following static
> checker warning:
>
> drivers/gpio/gpiolib-acpi.c:454 acpi_gpio_adr_space_handler()
> warn: should 'gpiod_get_raw_value(desc) << i' be a 64 bit type?
>
> This is due the fact that *value is of type u64 and gpiod_get_raw_value()
> returns int. Since i can be larger than 31, it is possible that the value
> returned gets wrapped.
>
> Fix this by casting the return of gpiod_get_raw_value() to u64 first before
> shift.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Patch applied for fixes.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-04-10 16:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01 10:03 [PATCH] gpio / ACPI: Prevent potential wrap of GPIO value on OpRegion read Mika Westerberg
2014-04-10 16:24 ` Linus Walleij
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).