Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4690233pxj; Wed, 12 May 2021 10:58:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy83jpk5XWJpEB6m7q/7cQARRH4YiyHpMz2YuB+J+mqg1pSt+XSWMYqLCPAJoOvawicmML6 X-Received: by 2002:a17:906:5652:: with SMTP id v18mr39172530ejr.457.1620842317951; Wed, 12 May 2021 10:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842317; cv=none; d=google.com; s=arc-20160816; b=IrEkWf/C1QE0ALgw6yWrBJzpdwPEVA77wpRgk3vwi3qdHqwbej/zN9wj5F8PkYsM9B Q7GfszS9gqHQNTvT87qI8XBivbsHUmKIsI1D4mOvZkcr477NJHOX3TDQHt/la6mjAdzw jOUMwTc0iikTh2a4eWeAs2u1FvunvYHeTC788tMY7u3Ht7qwqjDFZJkFqf7N+chpuwYs sRT8JlHM/BgGT4tSLtwpsCUObZZgvSsSzRwbvhUZxso4SLhVztbUUpZPySsjWZptPVVq d/6Y6MgCi3R3Da0X5fOSjtA0DGtkkYZA5KNe0S8pYE9fADVE8hXYHt1qR7Syuj8JL/xE z7Jw== 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=v6dkcAStiYqlwTZRpAJIQDEU/83HtImfs85tvfqw0kw=; b=jy8zIUmn/1N6a4wadUP534W4ul5g7HCOWbor2RXqJy+n1QXVACVPceDlHBR44gT7/D 1oKDevsM37sNRY/cCWRSGRUtKfXQzVww2OEBdLecUF0x56lNaMR1NJr+QxAI2SrD0g/f XiDfpVUnHVQYEZB7F4nCFBT6eYQjR5LKGjmXRONUdJWZc7aGcPVwq1m/CLuXZ6GB1uHH u6ENW8xc7j1zN0HJ24towlguBun03OvQQnvVtb/jvv2paHEMC4sOEMLQgAstEXNuc2p5 0eHfhVWAHdrh50WD+gmrIMEPK9GgV5Fs4Ty6U90BEXSTT1emZ+89SvFuSy5rg5+vHIma vomA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L8jKXV9B; 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 ds10si658797ejc.719.2021.05.12.10.58.13; Wed, 12 May 2021 10:58:37 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L8jKXV9B; 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 S1350271AbhELRru (ORCPT + 99 others); Wed, 12 May 2021 13:47:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:52008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240654AbhELQSj (ORCPT ); Wed, 12 May 2021 12:18:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7228E61C91; Wed, 12 May 2021 15:45:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834306; bh=hZWnAzRTgoMkcZpCZMtJj4pGVbRrv/fyZvi4D1X31cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L8jKXV9B601xBNWVuBtVQg7okccPiFpmqEzrFXgURv5TDld421OatOlmXS9hhOWwY +DkBfWZe6XQ59Ly6rOuBPu24DWdHBQrR1kHUq38bb/QSgo/Uj266E9Pg9gRr4HLDF/ Yqukx4DtRpEvB8VL006rtzLBVJYXd2DXKN6CFzvM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Qinglang Miao , Grygorii Strashko , Vignesh Raghavendra , Wolfram Sang , Sasha Levin Subject: [PATCH 5.11 492/601] i2c: omap: fix reference leak when pm_runtime_get_sync fails Date: Wed, 12 May 2021 16:49:29 +0200 Message-Id: <20210512144844.048620177@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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: Qinglang Miao [ Upstream commit 780f629741257ed6c54bd3eb53b57f648eabf200 ] The PM reference count is not expected to be incremented on return in omap_i2c_probe() and omap_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. I Replace it with pm_runtime_resume_and_get to keep usage counter balanced. What's more, error path 'err_free_mem' seems not like a proper name any more. So I change the name to err_disable_pm and move pm_runtime_disable below, for pm_runtime of 'pdev->dev' should be disabled when pm_runtime_resume_and_get fails. Fixes: 3b0fb97c8dc4 ("I2C: OMAP: Handle error check for pm runtime") Reported-by: Hulk Robot Signed-off-by: Qinglang Miao Reviewed-by: Grygorii Strashko Reviewed-by: Vignesh Raghavendra Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-omap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index 12ac4212aded..d4f6c6d60683 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c @@ -1404,9 +1404,9 @@ omap_i2c_probe(struct platform_device *pdev) pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT); pm_runtime_use_autosuspend(omap->dev); - r = pm_runtime_get_sync(omap->dev); + r = pm_runtime_resume_and_get(omap->dev); if (r < 0) - goto err_free_mem; + goto err_disable_pm; /* * Read the Rev hi bit-[15:14] ie scheme this is 1 indicates ver2. @@ -1513,8 +1513,8 @@ err_unuse_clocks: omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0); pm_runtime_dont_use_autosuspend(omap->dev); pm_runtime_put_sync(omap->dev); +err_disable_pm: pm_runtime_disable(&pdev->dev); -err_free_mem: return r; } @@ -1525,7 +1525,7 @@ static int omap_i2c_remove(struct platform_device *pdev) int ret; i2c_del_adapter(&omap->adapter); - ret = pm_runtime_get_sync(&pdev->dev); + ret = pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) return ret; -- 2.30.2