Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9043363pxu; Mon, 28 Dec 2020 05:15:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgkRXBT7R92hcZus0MKuKjvX4riAuZ4LOFxMhXO54LE9lhY5z3EFNRFBQjgPFHzlz/hEn3 X-Received: by 2002:a05:6402:45:: with SMTP id f5mr41921447edu.273.1609161302961; Mon, 28 Dec 2020 05:15:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161302; cv=none; d=google.com; s=arc-20160816; b=reLmXjSBn90+UliHdCVR0ilgyEfTwPuL5+b/7JOi2JcHQurZ2RnABopmMLh5b0vieO elqdUEnMZTGGmPOFK9A5DeRBhgQkOdfMdaEhIb3qnPGci6S3vNxd+9mRIF49Hsky+UfM 7GmIwJcvf+QcxTWyJB5ukSixtg+HdQfg5CnMSinT4p4IqBHAqZTFpzr+0CHfw+ryJALL XKPkBho7bbykFuKykI2AsLiOzb5EQKyDVPCckr8EZyqF/OLoUu53ohSUWINcqt1HXsuT ou7nf/VuHGoay2a4gH7lRX6VyWQdGUCOBsxHY7It4jrvj9G1Ot2W4FKIgWMD2zf3b13d DPtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=V98DHcmxLlsIN0DUdMIs4sTW51Exe4gISC/wdjNW/s0=; b=k0IPD+/V32XZPoNZmPzNe+0/JIN9w18Pnt6nAoQZnhV4xmurm34VAK5KiQOp/J2ONL LtGn9bkXaTXO2yBPj0gKj2JL/J2w+iuD0oMD5os+BV/uj0ZExSvdcMeu6LPaxgUOx3fv QqVnFYqCIclecDNH99U0NXsnY6aHDGAwdeNVjfRPQ3TEu+WwH/vkRcMYtVc79cVrIaNA 0tvBXE/5yQvmyT7umZKpZRFb7h72jh9NBITf1B2G9fVLI+THRfpZgFX4YUdnJ5/YDaAq egRvh0Dl5uYjmcbewWXt7qgwPROl240rvMLThfBculOlqJOUWKFImCMuPUNAx6zHNlTU HDNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QTuYFFNN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ak15si18415836ejc.654.2020.12.28.05.14.40; Mon, 28 Dec 2020 05:15:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QTuYFFNN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732139AbgL1NMp (ORCPT + 99 others); Mon, 28 Dec 2020 08:12:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:40288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732060AbgL1NMo (ORCPT ); Mon, 28 Dec 2020 08:12:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46F0C207C9; Mon, 28 Dec 2020 13:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161148; bh=2glVNUrl1kTnih0364pyiCKw3/pHFn1/8C+G3vDo8HQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QTuYFFNNIlKaYit4bFkl+YB981hKKWMxbjH1N5s6AeVZIEcSY4vE2GS8NCK44Re+N Rw1Ji12/Pj9GGenJSqIwrXbRXMCYZbSyu15QDK05sNRt7xdw32t0/ofM1nQWOtG79i QqesDBB2KWQCd1bTCIxpwFAeCZThE2AH5Zhj8mMQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Qilong , Sebastian Reichel , Sasha Levin Subject: [PATCH 4.14 118/242] power: supply: bq24190_charger: fix reference leak Date: Mon, 28 Dec 2020 13:48:43 +0100 Message-Id: <20201228124910.503919251@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Qilong [ Upstream commit b2f6cb78eaa1cad57dd3fe11d0458cd4fae9a584 ] pm_runtime_get_sync will increment pm usage counter even it failed. Forgetting to call pm_runtime_put_noidle will result in reference leak in callers(bq24190_sysfs_show, bq24190_charger_get_property, bq24190_charger_set_property, bq24190_battery_get_property, bq24190_battery_set_property), so we should fix it. Fixes: f385e6e2a1532 ("power: bq24190_charger: Use PM runtime autosuspend") Signed-off-by: Zhang Qilong Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/bq24190_charger.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index 35ff406aca483..0906f6b562bc4 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -450,8 +450,10 @@ static ssize_t bq24190_sysfs_show(struct device *dev, return -EINVAL; ret = pm_runtime_get_sync(bdi->dev); - if (ret < 0) + if (ret < 0) { + pm_runtime_put_noidle(bdi->dev); return ret; + } ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v); if (ret) @@ -1086,8 +1088,10 @@ static int bq24190_charger_get_property(struct power_supply *psy, dev_dbg(bdi->dev, "prop: %d\n", psp); ret = pm_runtime_get_sync(bdi->dev); - if (ret < 0) + if (ret < 0) { + pm_runtime_put_noidle(bdi->dev); return ret; + } switch (psp) { case POWER_SUPPLY_PROP_CHARGE_TYPE: @@ -1158,8 +1162,10 @@ static int bq24190_charger_set_property(struct power_supply *psy, dev_dbg(bdi->dev, "prop: %d\n", psp); ret = pm_runtime_get_sync(bdi->dev); - if (ret < 0) + if (ret < 0) { + pm_runtime_put_noidle(bdi->dev); return ret; + } switch (psp) { case POWER_SUPPLY_PROP_ONLINE: @@ -1424,8 +1430,10 @@ static int bq24190_battery_get_property(struct power_supply *psy, dev_dbg(bdi->dev, "prop: %d\n", psp); ret = pm_runtime_get_sync(bdi->dev); - if (ret < 0) + if (ret < 0) { + pm_runtime_put_noidle(bdi->dev); return ret; + } switch (psp) { case POWER_SUPPLY_PROP_STATUS: @@ -1470,8 +1478,10 @@ static int bq24190_battery_set_property(struct power_supply *psy, dev_dbg(bdi->dev, "prop: %d\n", psp); ret = pm_runtime_get_sync(bdi->dev); - if (ret < 0) + if (ret < 0) { + pm_runtime_put_noidle(bdi->dev); return ret; + } switch (psp) { case POWER_SUPPLY_PROP_ONLINE: -- 2.27.0