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 <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

---

The patch was prepared on top of next-20150323. It depends on changes in
power supply core (battery-2.6.git) so probably it should be applied to
the battery tree.
---
 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 a70fa4d7f8f9..008e89bf6f3c 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;
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to