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-Url: https://git.stricted.de/?a=commitdiff_plain;h=fbea947c7d122f4704001fac2a96b617f767037a;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.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 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; }