diff mbox

HID: hid-logitech-hidpp: add NULL check on devm_kmemdup() return value

Message ID 20170707051213.GA6074@embeddedgus (mailing list archive)
State Accepted
Headers show

Commit Message

Gustavo A. R. Silva July 7, 2017, 5:12 a.m. UTC
Check return value from call to devm_kmemdup()
in order to prevent a NULL pointer dereference.

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/hid/hid-logitech-hidpp.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Benjamin Tissoires July 12, 2017, 7:40 a.m. UTC | #1
On Jul 07 2017 or thereabouts, Gustavo A. R. Silva wrote:
> Check return value from call to devm_kmemdup()
> in order to prevent a NULL pointer dereference.
> 
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---

Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

>  drivers/hid/hid-logitech-hidpp.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
> index 41b3946..501e16a 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -2732,6 +2732,9 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
>  				     hidpp_battery_props,
>  				     sizeof(hidpp_battery_props),
>  				     GFP_KERNEL);
> +	if (!battery_props)
> +		return -ENOMEM;
> +
>  	num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2;
>  
>  	if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
> -- 
> 2.5.0
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Gustavo A. R. Silva July 17, 2017, 5 a.m. UTC | #2
On 07/12/2017 02:40 AM, Benjamin Tissoires wrote:
> On Jul 07 2017 or thereabouts, Gustavo A. R. Silva wrote:
>> Check return value from call to devm_kmemdup()
>> in order to prevent a NULL pointer dereference.
>>
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>
> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
>

Thank you, Benjamin.

>>  drivers/hid/hid-logitech-hidpp.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
>> index 41b3946..501e16a 100644
>> --- a/drivers/hid/hid-logitech-hidpp.c
>> +++ b/drivers/hid/hid-logitech-hidpp.c
>> @@ -2732,6 +2732,9 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
>>  				     hidpp_battery_props,
>>  				     sizeof(hidpp_battery_props),
>>  				     GFP_KERNEL);
>> +	if (!battery_props)
>> +		return -ENOMEM;
>> +
>>  	num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2;
>>
>>  	if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
>> --
>> 2.5.0
>>
Jiri Kosina July 20, 2017, 1:46 p.m. UTC | #3
On Fri, 7 Jul 2017, Gustavo A. R. Silva wrote:

> Check return value from call to devm_kmemdup()
> in order to prevent a NULL pointer dereference.
> 
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/hid/hid-logitech-hidpp.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
> index 41b3946..501e16a 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -2732,6 +2732,9 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
>  				     hidpp_battery_props,
>  				     sizeof(hidpp_battery_props),
>  				     GFP_KERNEL);
> +	if (!battery_props)
> +		return -ENOMEM;
> +

Applied to for-4.13/upstream-fixes, thanks.
diff mbox

Patch

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 41b3946..501e16a 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2732,6 +2732,9 @@  static int hidpp_initialize_battery(struct hidpp_device *hidpp)
 				     hidpp_battery_props,
 				     sizeof(hidpp_battery_props),
 				     GFP_KERNEL);
+	if (!battery_props)
+		return -ENOMEM;
+
 	num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2;
 
 	if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)