From patchwork Wed Oct 15 14:25:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5085651 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DDEF89F65C for ; Wed, 15 Oct 2014 14:25:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E39B4200E1 for ; Wed, 15 Oct 2014 14:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1315720117 for ; Wed, 15 Oct 2014 14:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbaJOOZX (ORCPT ); Wed, 15 Oct 2014 10:25:23 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:15578 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191AbaJOOZW (ORCPT ); Wed, 15 Oct 2014 10:25:22 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NDH00IXTPJ28K00@mailout1.w1.samsung.com>; Wed, 15 Oct 2014 15:28:14 +0100 (BST) X-AuditID: cbfec7f5-b7f776d000003e54-5b-543e83d0c58f Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 15.A0.15956.0D38E345; Wed, 15 Oct 2014 15:25:20 +0100 (BST) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NDH007U9PE3V0A0@eusync3.samsung.com>; Wed, 15 Oct 2014 15:25:20 +0100 (BST) From: Krzysztof Kozlowski To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v2 1/2] power: bq2415x_charger: Properly handle ENODEV from power_supply_get_by_phandle Date: Wed, 15 Oct 2014 16:25:09 +0200 Message-id: <1413383110-20310-1-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNJMWRmVeSWpSXmKPExsVy+t/xq7oXmu1CDBpvclhMevKe2WLiysnM Fq9fGFpc3jWHzeJz7xFGi9O7SywWbHzE6MDusXPWXXaPzSu0PDat6mTz6NuyitHj8ya5ANYo LpuU1JzMstQifbsErowJyy6wFizmq1h6fA9bA+MH7i5GTg4JAROJOzdXMEPYYhIX7q1nA7GF BJYyStzc6tDFyAVk9zFJtJ67ygSSYBMwlti8fAkbSEJEYDejxISpy1lAEswCnhLv/j5kB7GF BTIlrj97CDaVRUBVYu2MS2A1vALuEu1PJ7FBbJOTOHlsMusERu4FjAyrGEVTS5MLipPSc430 ihNzi0vz0vWS83M3MUIC5OsOxqXHrA4xCnAwKvHwchywDRFiTSwrrsw9xCjBwawkwjs/wS5E iDclsbIqtSg/vqg0J7X4ECMTB6dUA6PZvxDe0q+l3hz/DrCfm5SWcObr1Ac/O/49Fp14pWau eujrmc6XlPZ+5P8ssXXK6wT/pW3+RXbGZ18eNu//qcSl94N3n+y5wNwnlxXYxQ1kLl2SfxN8 tO3Cpadsu/KCJ+6+9tL65CHesx4twovmdDWdK62YUSHsqPX1LdulS72TFj8+oORUuX6iEktx RqKhFnNRcSIAzNvyou4BAAA= Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The power_supply_get_by_phandle() on error returns ENODEV or NULL. The driver later expects obtained pointer to power supply to be valid or NULL. If it is not NULL then it dereferences it in bq2415x_notifier_call() which would lead to dereferencing ENODEV-value pointer. Properly handle the power_supply_get_by_phandle() error case by replacing error value with NULL. This indicates that usb charger detection won't be used. Fix also memory leak of 'name' if power_supply_get_by_phandle() fails with NULL and probe should defer. Signed-off-by: Krzysztof Kozlowski Fixes: faffd234cf85 ("bq2415x_charger: Add DT support") Cc: --- Changes since v1: 1. Fix memory leak in probe defer (goto error_2) (suggested by Sebastian Reichel). 2. Don't fail the probe if 'ti,usb-charger-detection' is not present. Just print message. --- drivers/power/bq2415x_charger.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c index e384844a1ae1..edf945a5260f 100644 --- a/drivers/power/bq2415x_charger.c +++ b/drivers/power/bq2415x_charger.c @@ -1579,8 +1579,15 @@ static int bq2415x_probe(struct i2c_client *client, if (np) { bq->notify_psy = power_supply_get_by_phandle(np, "ti,usb-charger-detection"); - if (!bq->notify_psy) - return -EPROBE_DEFER; + if (IS_ERR(bq->notify_psy)) { + bq->notify_psy = NULL; + dev_info(&client->dev, + "no 'ti,usb-charger-detection' property (err=%ld)\n", + PTR_ERR(bq->notify_psy)); + } else if (!bq->notify_psy) { + ret = -EPROBE_DEFER; + goto error_2; + } } else if (pdata->notify_device) bq->notify_psy = power_supply_get_by_name(pdata->notify_device);