From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751543AbbCTJ0v (ORCPT ); Fri, 20 Mar 2015 05:26:51 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:63445 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750913AbbCTJ0s (ORCPT ); Fri, 20 Mar 2015 05:26:48 -0400 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 X-AuditID: cbfec7f5-b7fc86d0000066b7-01-550be72e8e43 Content-transfer-encoding: 8BIT From: Krzysztof Kozlowski To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH] power_supply: 88pm860x_charger: Fix possible NULL pointer dereference and use of initialized variable Date: Fri, 20 Mar 2015 10:26:02 +0100 Message-id: <1426843562-6415-1-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNLMWRmVeSWpSXmKPExsVy+t/xy7p6z7lDDY7kW0x68p7ZYuLKycwW r18YWlzeNYfN4nPvEUaL07tLHNg8ds66y+6xeYWWx6ZVnWwefVtWMXp83iQXwBrFZZOSmpNZ llqkb5fAlXFt8mS2gud8FT/63jE3MG7k6WLk5JAQMJFYevEWG4QtJnHh3nogm4tDSGApo8TZ bWtYQRK8AoISPybfY+li5OBgFpCXOHIpGyTMLKAuMWneImYQW0igj0nibVMuiM0mYCyxefkS sDkiArsZJSZMXc4C0WAo8fPdH3YQW1igQmL9/C9gi1kEVCVmnPvFDrHLTWLr28XsEAfJSZw8 Npl1AiPfLCRnzEI4YxaSMxYwMq9iFE0tTS4oTkrPNdIrTswtLs1L10vOz93ECAnQrzsYlx6z OsQowMGoxMN74jh3qBBrYllxZe4hRgkOZiUR3ofXgUK8KYmVValF+fFFpTmpxYcYmTg4pRoY gzy8H358V/3sROlKrSjNb7E2n7Pqyx5qCHh1NT+K0Zde9Vgpf/Y1Tu8+1Vt/NF80dXY82Hu+ +InZY99dTeK7va49+VZ436Pp3rOtnhkJ/3v5nRgmhohEOViv67pSOeWhYtnZyKMqCxo84jtK Rc7uY9UtZRH89uVy/DVOw2mzWV+/tDtvpPlYiaU4I9FQi7moOBEAidjZoC4CAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Krzysztof Kozlowski --- 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