Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4307947pxu; Tue, 1 Dec 2020 01:30:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhvij5ZL4f9OtI5OgZJTOkH6V4geKNzJ/pN83HJjE0c7UmGtk6m9XeOiJwu5KtrUSVk0rY X-Received: by 2002:aa7:c248:: with SMTP id y8mr2105662edo.344.1606815014945; Tue, 01 Dec 2020 01:30:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606815014; cv=none; d=google.com; s=arc-20160816; b=Zeyrfs+m6xxMxpr7zC2Yx833ZlFSFhn17lCRy0JqhCGXMGBolByifSBesOuLmpAL2X /jhvIARdRn8l0/+CXTPnxauo/dTwb48KPTVaHFdP9G/l/32iHEaBVHaocHg3o5N7aj1N oASXcL4Ft+F3nnG1lhc0hh/8cQMgD89MOY0FPpMqsyyrFV/JzrOvXwAEHd9yRM7/+x6A zCI0t/JQoz2F3NjsPQBsQqH3XinCLI4dkUyVW0I1w9yAt9Vl25PrZZXj8Be3J6bCkyti kLpvaBTPpWiGxVztgyeapMB4KMwzBO0p0d6IxDYLBIsVveIaV4dJx1zJkT8raWzNvC9Y 7NWQ== 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=JpAkfZKZsR++eLNrHiqrfBFqqPmrU6WVTcCvmxXpbZc=; b=phz7FpQy/w1JCido94zaH/mh/dml7KQI+zLvrzVmIhZekEK5yveNYCqKRuSt8AB2Yz sB2OZBQCnJyOq8eWykv2kKFQAAcULLhUPkhqBXQSXxIXcN1jTlX0EspEz6s/qEg9LFBb T7R83cHgN/Mqfi4ByQzmlvV+xdXq1wA/WIK+5TfxNIqQM7RUjwujlCdgMG4NTUAJ5r71 1h51ATO91QC5h8J55MQqfl8Ws6/Tsh+S/jf8qDEidJlB0UgYauaRHScjN/sPFOkdjQ1k V7Pxffb3nVFAiW5bzOj5tG4Sh4+CvQ/cmrAg5ZfpXo+MvV3Q104vu7zshD0soQ6gHoBU qhhw== 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 s17si592190eju.360.2020.12.01.01.29.52; Tue, 01 Dec 2020 01:30:14 -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 S2390870AbgLAJYp (ORCPT + 99 others); Tue, 1 Dec 2020 04:24:45 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8897 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390814AbgLAJYb (ORCPT ); Tue, 1 Dec 2020 04:24:31 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Clc8q3Brfz75s8; Tue, 1 Dec 2020 17:23:23 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Tue, 1 Dec 2020 17:23:42 +0800 From: Qinglang Miao To: Oleksij Rempel , Pengutronix Kernel Team , Shawn Guo , Sascha Hauer , Fabio Estevam , NXP Linux Team CC: , , , Qinglang Miao Subject: [PATCH 4/8] i2c: imx: fix reference leak when pm_runtime_get_sync fails Date: Tue, 1 Dec 2020 17:31:41 +0800 Message-ID: <20201201093141.113135-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 In i2c_imx_xfer() and i2c_imx_remove(), the pm reference count is not expected to be incremented on return. However, pm_runtime_get_sync will increment 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: 3a5ee18d2a32 ("i2c: imx: implement master_xfer_atomic callback") Reported-by: Hulk Robot Signed-off-by: Qinglang Miao --- drivers/i2c/busses/i2c-imx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index c98529c76..93d2069da 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -1008,7 +1008,7 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter, struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter); int result; - result = pm_runtime_get_sync(i2c_imx->adapter.dev.parent); + result = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent); if (result < 0) return result; @@ -1252,7 +1252,7 @@ static int i2c_imx_remove(struct platform_device *pdev) struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); int irq, ret; - ret = pm_runtime_get_sync(&pdev->dev); + ret = pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) return ret; -- 2.23.0