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 <k.kozlowski@samsung.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
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 @@
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;
}