Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp408284pxu; Tue, 1 Dec 2020 14:31:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQ0KsI0lVZpoGCeTsqzj7ITiBSM56LlvsjascGVBE9fldmuUikDvMBp8YtoNHSYXdNf1xu X-Received: by 2002:a17:906:4348:: with SMTP id z8mr5346178ejm.119.1606861876170; Tue, 01 Dec 2020 14:31:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861876; cv=none; d=google.com; s=arc-20160816; b=xIJal1Db5XOe9OoYO9A7lD18GpBOlmxjamXX/eOiWSVQUkQegyihB7YqYOn/ZFghkV ++90LvuQ1ehS99cHucATjgJ+cbMyZDMAlzTGkBsaPPOFXjH18s567t2z4QeEOcGsgCev XsouSd/S2yiE8pxs2+GE0+zjMyvKqFzi2qY4V206sHyzga8BqRSbEbUdAfNRJwcHmEIf dEuDRP08TmgnhWdpTVHeihJ4pPU/LuBReidjEV4Kcs/B/OkgVdHTNCNAFEvCs38rhvYG mAfTurPH6VaUQ8XdxuqPwinxzWnFA2ffD0V/sS5Gq/jJnnQkA+b/8t1RCPKHGIqYWWMc 26xw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XeU7ci+A8DpX0D8pakXlPbK3xk3H7HjXc7R2nb+f8rc=; b=XSch6/ebtr0LJMV1xoYIPqt6D5uYRa8W7/7GfA/bmWKAvG0cLF137X3yiWI4VWCjmg /T/lAGgqATT2ZZeHpyNjYxOEyWZaG7OvToHm8CjUXwQvZh1ex7ldYwxo0i/VZ4N/AlYh GbvfcfdrMFP7KO/l6YFXHUcbCneAb0TfobV+icNMssFDK/Fz7ueZNswEeqVqiZk6h/OG 11icvl6uq5NyqYDNl+s9BPIcJT4e7Tvy44oFW/MWu3bAFM7lBuon4hq120oqyLam/hLE qnm/nKrkqOYtvmOTqiWt26Isc/0KKRDnIRq+H0bFPtlAj7Q51OPKuc2ba3R149EV9pfJ 8rZA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si744987eda.607.2020.12.01.14.30.53; Tue, 01 Dec 2020 14:31:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388544AbgLAJYI (ORCPT + 99 others); Tue, 1 Dec 2020 04:24:08 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:8223 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729570AbgLAJYF (ORCPT ); Tue, 1 Dec 2020 04:24:05 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Clc8C4SMkzkj9j; Tue, 1 Dec 2020 17:22:51 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Tue, 1 Dec 2020 17:23:18 +0800 From: Qinglang Miao To: Michal Simek CC: , , , Qinglang Miao Subject: [PATCH 1/8] i2c: cadence: fix reference leak when pm_runtime_get_sync fails Date: Tue, 1 Dec 2020 17:31:17 +0800 Message-ID: <20201201093117.112900-1-miaoqinglang@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201201092924.112461-1-miaoqinglang@huawei.com> References: <20201201092924.112461-1-miaoqinglang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The PM reference count is not expected to be incremented on return in functions cdns_i2c_master_xfer and cdns_reg_slave. However, pm_runtime_get_sync will increment pm usage counter even failed. Forgetting to putting operation will result in a reference leak here. Replace it with pm_runtime_resume_and_get to keep usage counter balanced. Fixes: 7fa32329ca03 ("i2c: cadence: Move to sensible power management") Reported-by: Hulk Robot Signed-off-by: Qinglang Miao --- drivers/i2c/busses/i2c-cadence.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index e4b7f2a95..e8eae8725 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -789,7 +789,7 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, bool change_role = false; #endif - ret = pm_runtime_get_sync(id->dev); + ret = pm_runtime_resume_and_get(id->dev); if (ret < 0) return ret; @@ -911,7 +911,7 @@ static int cdns_reg_slave(struct i2c_client *slave) if (slave->flags & I2C_CLIENT_TEN) return -EAFNOSUPPORT; - ret = pm_runtime_get_sync(id->dev); + ret = pm_runtime_resume_and_get(id->dev); if (ret < 0) return ret; -- 2.23.0