linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: input: Fix NULL pointer dereference when power_supply_register fails
@ 2015-03-23 15:34 Krzysztof Kozlowski
  2015-03-24 11:02 ` Jiri Kosina
  0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Kozlowski @ 2015-03-23 15:34 UTC (permalink / raw)
  To: Jiri Kosina, linux-input, linux-kernel, linux-pm
  Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
	Dan Carpenter, Krzysztof Kozlowski

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>

---

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: input: Fix NULL pointer dereference when power_supply_register fails
  2015-03-23 15:34 [PATCH] HID: input: Fix NULL pointer dereference when power_supply_register fails Krzysztof Kozlowski
@ 2015-03-24 11:02 ` Jiri Kosina
  2015-03-24 15:07   ` Sebastian Reichel
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Kosina @ 2015-03-24 11:02 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: linux-input, linux-kernel, linux-pm, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Dan Carpenter

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@samsung.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> ---
> 
> 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@suse.cz>

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: input: Fix NULL pointer dereference when power_supply_register fails
  2015-03-24 11:02 ` Jiri Kosina
@ 2015-03-24 15:07   ` Sebastian Reichel
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2015-03-24 15:07 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Krzysztof Kozlowski, linux-input, linux-kernel, linux-pm,
	Dmitry Eremin-Solenikov, David Woodhouse, Dan Carpenter

[-- Attachment #1: Type: text/plain, Size: 783 bytes --]

Hi Krzysztof & Jiri,

On Tue, Mar 24, 2015 at 12:02:41PM +0100, Jiri Kosina wrote:
> 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@samsung.com>
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > ---
> > 
> > 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@suse.cz>
> 
> for the merge through battery-2.6.git. Thanks.

Thanks, pulled.

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-24 15:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-23 15:34 [PATCH] HID: input: Fix NULL pointer dereference when power_supply_register fails Krzysztof Kozlowski
2015-03-24 11:02 ` Jiri Kosina
2015-03-24 15:07   ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).