From: Krzysztof Kozlowski Date: Mon, 23 Mar 2015 15:34:51 +0000 (+0100) Subject: HID: input: Fix NULL pointer dereference when power_supply_register fails X-Git-Tag: v4.9.8~4492^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbea947c7d122f4704001fac2a96b617f767037a;p=platform%2Fkernel%2Flinux-rpi3.git 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 --- diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 5d5a8c4..32c2da4 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; }