Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp328863pxf; Thu, 8 Apr 2021 04:07:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3yyEJ1nj6HtBS0hv2QXyvyjQHrlliGdggkI0dxv3itdE84TMBvwxHSc09BLhBQjZm7ie2 X-Received: by 2002:a05:6a00:214d:b029:218:4f9:d5ba with SMTP id o13-20020a056a00214db029021804f9d5bamr7074251pfk.3.1617880061454; Thu, 08 Apr 2021 04:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617880061; cv=none; d=google.com; s=arc-20160816; b=NSSxGd6uL6FX8xGII5aDcqV+f+t/8kXRPhf8gfQtVzXxUeFvNO/JJuBo36swWFs071 HXysCYrG2ryXQVJD3aRXUIXhLwN/2N7hz4yz7BVXkucZMMCdK3Wfs8I0cEIBIJbt+lC0 CUSB1MLpqdBzyqQC7SI75m65+aWDuwrnEtDgHY2xNguKDwfUZjVNz4Vq+jrvYK8MBWjs R3JAH3KDTgRz/a0tyOTLcbMsUd3PQQ7o+AYlDXCxHa8j3Lz1K5cKKZZjoqyMhxkek1Nt Ry+GQdnJL+I7y23aYU7pqLA1tA+B5skNEZpjk7TU5wMLStbqBEmnSDHkb9mlx4u5jrTc mkXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=PkmDseCxJQiLYWO+xQyWYUZsGxrAT2yAhZl8v4j0enY=; b=EC2MsGm3dZPbqG1DXeGcf0aeClxfxyUTzozo6xZ44Z4CocXn49Or1z3u6uAHLSXWh/ NTEK98owOeADk2B2YLA3vRCJQXR1rmB0S6LrHBpih4PPTSMWkieVo49WiuESSOC3w0dq xclWl8yYyuO4tfOeldL6ILl/gcEXKhXiKALCdRX6Oang9GXYiuB6DZ52CXxjKGc98Pcn +1kCQUH2kqafHex8FQMgqsqgXZ1y9Pm7/eUEx4WUrpUKvBaWmgdkHRN87l0q87g9/F7P VcbrDxowpsXvQAca5bMEIblI+KZbfeR7u3TEUWf0WbhJ4u6LSJmmnRJX58rLeB2C1QCD He9w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r6si441171pld.349.2021.04.08.04.07.28; Thu, 08 Apr 2021 04:07:41 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230443AbhDHLGx (ORCPT + 99 others); Thu, 8 Apr 2021 07:06:53 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:16407 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbhDHLGw (ORCPT ); Thu, 8 Apr 2021 07:06:52 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FGJLr3mpgzkjXg; Thu, 8 Apr 2021 19:04:52 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.149) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Thu, 8 Apr 2021 19:06:34 +0800 From: Ye Weihua To: , , , , , CC: , , , , Subject: [PATCH -next] i2c: imx: Fix PM reference leak in i2c_imx_reg_slave() Date: Thu, 8 Apr 2021 19:06:38 +0800 Message-ID: <20210408110638.200761-1-yeweihua4@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.149] 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 these functions. However, pm_runtime_get_sync() will increment the PM reference count even on failure. forgetting to put the reference again will result in a leak. Replace it with pm_runtime_resume_and_get() to keep the usage counter balanced. Reported-by: Hulk Robot Signed-off-by: Ye Weihua --- drivers/i2c/busses/i2c-imx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index b80fdc1f0092..dc5ca71906db 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -801,7 +801,7 @@ static int i2c_imx_reg_slave(struct i2c_client *client) i2c_imx->last_slave_event = I2C_SLAVE_STOP; /* Resume */ - ret = pm_runtime_get_sync(i2c_imx->adapter.dev.parent); + ret = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent); if (ret < 0) { dev_err(&i2c_imx->adapter.dev, "failed to resume i2c controller"); return ret; @@ -1253,7 +1253,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; @@ -1496,7 +1496,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.17.1