aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/88pm860x_charger.c
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>2015-03-20 05:26:02 -0400
committerSebastian Reichel <sre@kernel.org>2015-03-20 07:46:04 -0400
commitc94a3d403299f64d2f91346ff64c4b95747c123c (patch)
tree427bc1796eced6e09db5914518dd13df5f996184 /drivers/power/88pm860x_charger.c
parentd3a6097b25e09751cba787b33eba26ab4df86215 (diff)
power_supply: 88pm860x_charger: Fix possible NULL pointer dereference and use of initialized variable
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> Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers/power/88pm860x_charger.c')
-rw-r--r--drivers/power/88pm860x_charger.c7
1 files 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)
495 ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_VOLTAGE_NOW, 495 ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_VOLTAGE_NOW,
496 &val); 496 &val);
497 if (ret) 497 if (ret)
498 goto out; 498 goto out_psy_put;
499 vbatt = val.intval / 1000; 499 vbatt = val.intval / 1000;
500 /* 500 /*
501 * CHG_DONE interrupt is faster than CHG_DET interrupt when 501 * CHG_DONE interrupt is faster than CHG_DET interrupt when
@@ -506,14 +506,15 @@ static irqreturn_t pm860x_done_handler(int irq, void *data)
506 */ 506 */
507 ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2); 507 ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2);
508 if (ret < 0) 508 if (ret < 0)
509 goto out; 509 goto out_psy_put;
510 if (vbatt > CHARGE_THRESHOLD && ret & STATUS2_CHG) 510 if (vbatt > CHARGE_THRESHOLD && ret & STATUS2_CHG)
511 power_supply_set_property(psy, POWER_SUPPLY_PROP_CHARGE_FULL, 511 power_supply_set_property(psy, POWER_SUPPLY_PROP_CHARGE_FULL,
512 &val); 512 &val);
513 513
514out_psy_put:
515 power_supply_put(psy);
514out: 516out:
515 mutex_unlock(&info->lock); 517 mutex_unlock(&info->lock);
516 power_supply_put(psy);
517 dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed); 518 dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed);
518 set_charging_fsm(info); 519 set_charging_fsm(info);
519 520