Skip to contentSkip to conversation

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

PATCH Applied Gustavo A. R. Silva 3 participants 4 messages Jul 7, 2017 – Jul 20, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

Check return value from call to devm_kmemdup()
in order to prevent a NULL pointer dereference.

---
 drivers/hid/hid-logitech-hidpp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hid/hid-logitech-hidpp.c +3 -0
index 41b3946..501e16a 100644
@@ -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)
Signature · 1 line
2.5.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Gustavo A. R. Silva

Check return value from call to devm_kmemdup()
in order to prevent a NULL pointer dereference.

---

Quoted 20 lines
 drivers/hid/hid-logitech-hidpp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hid/hid-logitech-hidpp.c +3 -0
index 41b3946..501e16a 100644
@@ -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)
Signature · 1 line
2.5.0
#2 lore raw
Quoted 9 lines · Benjamin Tissoires
Quoted 5 lines · Gustavo A. R. Silva

Check return value from call to devm_kmemdup()
in order to prevent a NULL pointer dereference.

---

Thank you, Benjamin.

Quoted 20 lines
Quoted 20 lines
 drivers/hid/hid-logitech-hidpp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hid/hid-logitech-hidpp.c +3 -1
index 41b3946..501e16a 100644
@@ -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

Signature · 1 line
Gustavo A. R. Silva
maintainer Applied
#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 13 lines · Gustavo A. R. Silva

Check return value from call to devm_kmemdup()
in order to prevent a NULL pointer dereference.

---
 drivers/hid/hid-logitech-hidpp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hid/hid-logitech-hidpp.c +0 -0
index 41b3946..501e16a 100644

drivers/hid/hid-logitech-hidpp.c static int hidpp_initialize_battery(struct hidpp_device *hidpp) · line 2737

Quoted 6 lines
drivers/hid/hid-logitech-hidpp.c +3 -0
@@ -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.

Signature · 2 lines
Jiri Kosina
SUSE Labs