From fbea947c7d122f4704001fac2a96b617f767037a Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 23 Mar 2015 16:34:51 +0100 Subject: [PATCH] HID: input: Fix NULL pointer dereference when power_supply_register fails Do not call power_supply_powers() if power_supply_register() failed earlier. This fixes possible NULL pointer dereference by power_supply_powers() in such case. Signed-off-by: Krzysztof Kozlowski Reported-by: Dan Carpenter Acked-by: Jiri Kosina Signed-off-by: Sebastian Reichel --- drivers/hid/hid-input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 5d5a8c42645f..32c2da49bd5b 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -452,10 +452,10 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, kfree(psy_desc->name); kfree(psy_desc); dev->battery = NULL; + } else { + power_supply_powers(dev->battery, &dev->dev); } - power_supply_powers(dev->battery, &dev->dev); - out: return true; } -- 2.39.5