Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1682769 > unrolled thread
| Started by | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| First post | 2017-07-07 00:30 +0200 |
| Last post | 2017-07-10 21:40 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] platform/x86: fujitsu-laptop: add NULL check on devm_kzalloc() return value "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-07 00:30 +0200
Re: [PATCH] platform/x86: fujitsu-laptop: add NULL check on devm_kzalloc() return value Jonathan Woithe <jwoithe@just42.net> - 2017-07-07 02:30 +0200
Re: [PATCH] platform/x86: fujitsu-laptop: add NULL check on devm_kzalloc() return value Darren Hart <dvhart@infradead.org> - 2017-07-07 19:10 +0200
Re: [PATCH] platform/x86: fujitsu-laptop: add NULL check on devm_kzalloc() return value "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-10 21:40 +0200
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Date | 2017-07-07 00:30 +0200 |
| Subject | [PATCH] platform/x86: fujitsu-laptop: add NULL check on devm_kzalloc() return value |
| Message-ID | <u0nrA-3is-35@gated-at.bofh.it> |
Check return value from call to devm_kzalloc()
in order to prevent a NULL pointer dereference.
This issue was detected using Coccinelle and the following semantic patch:
@@
expression x;
identifier fld;
@@
* x = devm_kzalloc(...);
... when != x == NULL
x->fld
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
drivers/platform/x86/fujitsu-laptop.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index c1a8528..593a350 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -695,6 +695,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
if (call_fext_func(device,
FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ if (!led)
+ return -ENOMEM;
+
led->name = "fujitsu::logolamp";
led->brightness_set_blocking = logolamp_set;
led->brightness_get = logolamp_get;
@@ -707,6 +710,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
(call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ if (!led)
+ return -ENOMEM;
+
led->name = "fujitsu::kblamps";
led->brightness_set_blocking = kblamps_set;
led->brightness_get = kblamps_get;
@@ -723,6 +729,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
*/
if (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ if (!led)
+ return -ENOMEM;
+
led->name = "fujitsu::radio_led";
led->brightness_set_blocking = radio_led_set;
led->brightness_get = radio_led_get;
@@ -741,6 +750,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
(call_fext_func(device,
FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ if (!led)
+ return -ENOMEM;
+
led->name = "fujitsu::eco_led";
led->brightness_set_blocking = eco_led_set;
led->brightness_get = eco_led_get;
--
2.5.0
[toc] | [next] | [standalone]
| From | Jonathan Woithe <jwoithe@just42.net> |
|---|---|
| Date | 2017-07-07 02:30 +0200 |
| Message-ID | <u0pjH-4tw-3@gated-at.bofh.it> |
| In reply to | #1682769 |
On Thu, Jul 06, 2017 at 05:19:02PM -0500, Gustavo A. R. Silva wrote:
> Check return value from call to devm_kzalloc()
> in order to prevent a NULL pointer dereference.
>
> This issue was detected using Coccinelle and the following semantic patch:
>
> @@
> expression x;
> identifier fld;
> @@
>
> * x = devm_kzalloc(...);
> ... when != x == NULL
> x->fld
>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
These checks should be added in the interest of code correctness.
devm_kzalloc() can fail (even if it's extremely unlikely in practice) so we
should check for this.
Reviewed-by: Jonathan Woithe <jwoithe@just42.net>
> ---
> drivers/platform/x86/fujitsu-laptop.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index c1a8528..593a350 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -695,6 +695,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
> if (call_fext_func(device,
> FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
> led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
> + if (!led)
> + return -ENOMEM;
> +
> led->name = "fujitsu::logolamp";
> led->brightness_set_blocking = logolamp_set;
> led->brightness_get = logolamp_get;
> @@ -707,6 +710,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
> FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
> (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
> led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
> + if (!led)
> + return -ENOMEM;
> +
> led->name = "fujitsu::kblamps";
> led->brightness_set_blocking = kblamps_set;
> led->brightness_get = kblamps_get;
> @@ -723,6 +729,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
> */
> if (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
> led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
> + if (!led)
> + return -ENOMEM;
> +
> led->name = "fujitsu::radio_led";
> led->brightness_set_blocking = radio_led_set;
> led->brightness_get = radio_led_get;
> @@ -741,6 +750,9 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
> (call_fext_func(device,
> FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
> led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
> + if (!led)
> + return -ENOMEM;
> +
> led->name = "fujitsu::eco_led";
> led->brightness_set_blocking = eco_led_set;
> led->brightness_get = eco_led_get;
> --
> 2.5.0
[toc] | [prev] | [next] | [standalone]
| From | Darren Hart <dvhart@infradead.org> |
|---|---|
| Date | 2017-07-07 19:10 +0200 |
| Message-ID | <u0EVs-71k-25@gated-at.bofh.it> |
| In reply to | #1682827 |
On Fri, Jul 07, 2017 at 09:49:00AM +0930, Jonathan Woithe wrote: > On Thu, Jul 06, 2017 at 05:19:02PM -0500, Gustavo A. R. Silva wrote: > > Check return value from call to devm_kzalloc() > > in order to prevent a NULL pointer dereference. > > > > This issue was detected using Coccinelle and the following semantic patch: > > > > @@ > > expression x; > > identifier fld; > > @@ > > > > * x = devm_kzalloc(...); > > ... when != x == NULL > > x->fld > > > > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> > > These checks should be added in the interest of code correctness. > devm_kzalloc() can fail (even if it's extremely unlikely in practice) so we > should check for this. > > Reviewed-by: Jonathan Woithe <jwoithe@just42.net> Thanks Gustavo and Jonathan, Queued to testing. -- Darren Hart VMware Open Source Technology Center
[toc] | [prev] | [next] | [standalone]
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Date | 2017-07-10 21:40 +0200 |
| Message-ID | <u1MHg-HI-27@gated-at.bofh.it> |
| In reply to | #1683321 |
Hi Darren, Jonathan, Quoting Darren Hart <dvhart@infradead.org>: > On Fri, Jul 07, 2017 at 09:49:00AM +0930, Jonathan Woithe wrote: >> On Thu, Jul 06, 2017 at 05:19:02PM -0500, Gustavo A. R. Silva wrote: >> > Check return value from call to devm_kzalloc() >> > in order to prevent a NULL pointer dereference. >> > >> > This issue was detected using Coccinelle and the following semantic patch: >> > >> > @@ >> > expression x; >> > identifier fld; >> > @@ >> > >> > * x = devm_kzalloc(...); >> > ... when != x == NULL >> > x->fld >> > >> > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> >> >> These checks should be added in the interest of code correctness. >> devm_kzalloc() can fail (even if it's extremely unlikely in practice) so we >> should check for this. >> >> Reviewed-by: Jonathan Woithe <jwoithe@just42.net> > > Thanks Gustavo and Jonathan, > > Queued to testing. > Glad to help. :) Thanks -- Gustavo A. R. Silva
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web