platform/x86: fujitsu-laptop: add NULL check on devm_kzalloc() return value
Subsystems (2)
PATCH 1/1 platform/x86: fujitsu-laptop: add NULL check on devm_kzalloc() return value
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
--- drivers/platform/x86/fujitsu-laptop.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/platform/x86/fujitsu-laptop.c +12 -0
@@ -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;
Signature · 1 line
2.5.0
Quoted 10 lines · Gustavo A. R. Silva
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;
@@
Quoted 5 lines
* x =
devm_kzalloc(...);
... when != x == NULL
x->fldSigned-off-by Gustavo A. R. Silva <[email protected]>
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.
Quoted 50 lines
--- drivers/platform/x86/fujitsu-laptop.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/platform/x86/fujitsu-laptop.c +12
-0@@ -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;Signature · 1 line
2.5.0
Quoted 15 lines · Jonathan Woithe
Quoted 14 lines · Gustavo A. R. Silva
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
Quoted 7 lines
Quoted 1 line
Signed-off-by Gustavo A. R. Silva <[email protected]>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 <[email protected]>
Thanks Gustavo and Jonathan,
Queued to testing.
Signature · 2 lines
Darren Hart VMware Open Source Technology Center
Hi Darren, Jonathan,
Quoting Darren Hart <[email protected]>:
Quoted 22 lines · Jonathan Woithe
Quoted 21 lines · Gustavo A. R. Silva
Quoted 10 lines
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;
@@Quoted 5 lines
* x =
devm_kzalloc(...);
... when != x == NULL
x->fldSigned-off-by Gustavo A. R. Silva <[email protected]>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.
Quoted 6 lines
Quoted 1 line
Reviewed-by Jonathan Woithe <[email protected]>Thanks Gustavo and Jonathan,
Queued to testing.
Glad to help. :)
Thanks
--
Gustavo A. R. Silva