All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power_supply: 88pm860x_charger: Fix possible NULL pointer dereference and use of initialized variable
@ 2015-03-20  9:26 Krzysztof Kozlowski
  2015-03-20 11:58 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Kozlowski @ 2015-03-20  9:26 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, linux-kernel
  Cc: Krzysztof Kozlowski

Do not put reference to power supply in early exit paths of
pm860x_done_handler() because:
1. it is not yet initialized,
2. it is NULL.

This fixes possible NULL pointer dereference and following build
warning:
drivers/power/88pm860x_charger.c: In function ‘pm860x_done_handler’:
drivers/power/88pm860x_charger.c:516:18: warning: ‘psy’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Additionally this puts the power supply reference before unlocking
mutex. This actually is not needed (there is no race here) but has
logical sense and makes the exit paths cleaner.

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/power/88pm860x_charger.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/power/88pm860x_charger.c b/drivers/power/88pm860x_charger.c
index bf822aa00c14..0e448c68c02b 100644
--- a/drivers/power/88pm860x_charger.c
+++ b/drivers/power/88pm860x_charger.c
@@ -495,7 +495,7 @@ static irqreturn_t pm860x_done_handler(int irq, void *data)
 	ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_VOLTAGE_NOW,
 			&val);
 	if (ret)
-		goto out;
+		goto out_psy_put;
 	vbatt = val.intval / 1000;
 	/*
 	 * CHG_DONE interrupt is faster than CHG_DET interrupt when
@@ -506,14 +506,15 @@ static irqreturn_t pm860x_done_handler(int irq, void *data)
 	 */
 	ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2);
 	if (ret < 0)
-		goto out;
+		goto out_psy_put;
 	if (vbatt > CHARGE_THRESHOLD && ret & STATUS2_CHG)
 		power_supply_set_property(psy, POWER_SUPPLY_PROP_CHARGE_FULL,
 				&val);
 
+out_psy_put:
+	power_supply_put(psy);
 out:
 	mutex_unlock(&info->lock);
-	power_supply_put(psy);
 	dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed);
 	set_charging_fsm(info);
 
-- 
1.9.1


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

* Re: [PATCH] power_supply: 88pm860x_charger: Fix possible NULL pointer dereference and use of initialized variable
  2015-03-20  9:26 [PATCH] power_supply: 88pm860x_charger: Fix possible NULL pointer dereference and use of initialized variable Krzysztof Kozlowski
@ 2015-03-20 11:58 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2015-03-20 11:58 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-pm, linux-kernel

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

Hi Krzysztof,

On Fri, Mar 20, 2015 at 10:26:02AM +0100, Krzysztof Kozlowski wrote:
> Do not put reference to power supply in early exit paths of
> pm860x_done_handler() because:
> 1. it is not yet initialized,
> 2. it is NULL.
> 
> This fixes possible NULL pointer dereference and following build
> warning:
> drivers/power/88pm860x_charger.c: In function ‘pm860x_done_handler’:
> drivers/power/88pm860x_charger.c:516:18: warning: ‘psy’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> Additionally this puts the power supply reference before unlocking
> mutex. This actually is not needed (there is no race here) but has
> logical sense and makes the exit paths cleaner.
> 
> Reported-by: kbuild test robot <fengguang.wu@intel.com>
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Thanks, pulled.

-- Sebastian

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

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

end of thread, other threads:[~2015-03-20 11:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-20  9:26 [PATCH] power_supply: 88pm860x_charger: Fix possible NULL pointer dereference and use of initialized variable Krzysztof Kozlowski
2015-03-20 11:58 ` Sebastian Reichel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.