Re: [PATCH] HID: input: Fix NULL pointer dereference when power_supply_register fails
From: Jiri Kosina
Date: Tue Mar 24 2015 - 07:02:51 EST
On Mon, 23 Mar 2015, Krzysztof Kozlowski wrote:
> 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@xxxxxxxxxxx>
> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
>
> ---
>
> 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.
Acked-by: Jiri Kosina <jkosina@xxxxxxx>
for the merge through battery-2.6.git. Thanks.
> ---
> 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;
> }
--
Jiri Kosina
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/