Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4306987pxu; Tue, 1 Dec 2020 01:28:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYSg7T2LLJZHU8geuApLyvBAQBTbUlMxkH39M/U7jM6uaeM8FcBohrw88csmtbaZFPTEng X-Received: by 2002:a17:906:b857:: with SMTP id ga23mr2177756ejb.122.1606814900555; Tue, 01 Dec 2020 01:28:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606814900; cv=none; d=google.com; s=arc-20160816; b=ZM1SnFc6oUJW1vPM5Vr3ja0dYR/DoOnNPK56euq4Kp3O4Owgr/dWMaL845A8if9DyC gj4kXZiimUu3Aa5xmfNlBnKxA7nEo1VIjaxOcFQOsxZQ7KnBOuatiJ5aPzqmxCJm3IbU q7cBdCm75+oWbLmyf0+JGpT/EqGpoeiBtS4TzKE4gMin7zKoLXoqcgZ5kn0zSz0KUg/F jpBaxgHYFQRvBSze7wN3qHB2lFxFcB02aXnM4ASmf/VV+OJsoXEMscEnyEph2biG8Ht2 NbPnRL4TXOXHJbXMYegJjgZsyNVeEH6t1BlKLb9HZcufHJzvRArrqbZ1FZNyq9qoqODq ND9A== 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=SJr+VkBWvDcITP6uWLbohgYyp0lM4RJFPqSlcOU02/M=; b=QmMabf6jfPVi3KGopqxn/D2bxzpIJ5v4dm3zroiengqJ9DxZk9EgwWO/lhiERE1SCV rwkcYndNgEXkkZRPSGdL5Erh4kN59sdAa6uPvfAtk+y82maryv14jRNhRrvN4o+oVI5d Q/4gGBpxPonArLfNElgPoCSxQVtVc2XBscbNexEfdK835j8gFMlKlGAFLVrQsbV7IWoH 4SJih2H85AIYV5uU/cVMMYasFVNlSs0iO2w28PU3xiihlffFz2b1L8Q81Zi+JX+Y14su wSCiG/gh1WGzjOLs//TT6/59dM/zDvszCkpwXYQVuLWIwLEjYELE5FxA12hxm4IAUM43 ib2w== 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 k19si563014ejs.41.2020.12.01.01.27.58; Tue, 01 Dec 2020 01:28:20 -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 S2390900AbgLAJY5 (ORCPT + 99 others); Tue, 1 Dec 2020 04:24:57 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8898 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390851AbgLAJYl (ORCPT ); Tue, 1 Dec 2020 04:24:41 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Clc8z0W02z75dS; Tue, 1 Dec 2020 17:23:31 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Tue, 1 Dec 2020 17:23:47 +0800 From: Qinglang Miao To: Michal Simek CC: , , , Qinglang Miao Subject: [PATCH 8/8] i2c: xiic: fix reference leak when pm_runtime_get_sync fails Date: Tue, 1 Dec 2020 17:31:46 +0800 Message-ID: <20201201093146.113316-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 xiic_xfer and xiic_i2c_remove. However, pm_runtime_get_sync will increment the PM reference count 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: 10b17004a74c ("i2c: xiic: Fix the clocking across bind unbind") Reported-by: Hulk Robot Signed-off-by: Qinglang Miao --- drivers/i2c/busses/i2c-xiic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 087b29519..2a8568b97 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -706,7 +706,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) dev_dbg(adap->dev.parent, "%s entry SR: 0x%x\n", __func__, xiic_getreg8(i2c, XIIC_SR_REG_OFFSET)); - err = pm_runtime_get_sync(i2c->dev); + err = pm_runtime_resume_and_get(i2c->dev); if (err < 0) return err; @@ -873,7 +873,7 @@ static int xiic_i2c_remove(struct platform_device *pdev) /* remove adapter & data */ i2c_del_adapter(&i2c->adap); - ret = pm_runtime_get_sync(i2c->dev); + ret = pm_runtime_resume_and_get(i2c->dev); if (ret < 0) return ret; -- 2.23.0