Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4623840pxj; Wed, 12 May 2021 09:28:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7CEMuyA8QK8q6MIIQHUqzeBk00w8oGVdbpNG0TEiu2qRmLQJMw6WlK1p3iZAIVsDOTa1F X-Received: by 2002:a05:6808:90d:: with SMTP id w13mr12099798oih.71.1620836897373; Wed, 12 May 2021 09:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836897; cv=none; d=google.com; s=arc-20160816; b=0+WPMrviqi7jbF6/F1wI80769+UFNE/Sag4lic167TfI08KbvhBfIWbMmE2AuLpPrb X9MxmPIIRkHl5zRLGrjdvhVRyHBbvxVK+bXaDmh0b85ay2V1bLPrPDSsThxr+IjPuB8H Ye9nQNPn7Xb5aAFSoodDS5TjjvW3ag5IWjyhFu6MeILAQ+4tx41BzPGVo7EZp2fEkA2d voHqD4evOPt25qdp9ol999h0Fv+NY88yW/haU4ll+mfCNpB7NmInkUOg5jBxQqqkHvU0 /wR9RIyduj8VoaNCUxnJEUNH0yE08S7swRO/ty4RcawnMu5dWO0pLuutgpXOynZaxRg+ Se2A== 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=kDWs0FaiLGyY1QtNqTDRe25McsqqUYeLhRa9rTmBGGM6mXJ31zDfL+JpcpIjz2b6la H/0AbObt/UWHTZ/FRMvhfIELCwfUNBE63HQpebBdZbh0HCRZk8ekoTBvBVwGJPbpXMZT EpJ6Lg4aHz7yX9q12eci2kGrIgzNUmGQycZMlMAT3O3Kgo0jwNHWwGwW+YG95cG3JuE8 1oy81HfYI/g54+kn6hcGyXwUiducnyt9/ur3PfbVvltbxQ/9PIMM+EwmaVvAcPOMRmcl VUND7HWLYaWj8jMK+WUxNnmtuwnuz4zlyLmz0V93MmxwISUltumOafSgs9FNpbYgqUNa vofQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ko+uYjye; 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 c185si404580oif.214.2021.05.12.09.28.03; Wed, 12 May 2021 09:28:17 -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=ko+uYjye; 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 S235063AbhELQ2O (ORCPT + 99 others); Wed, 12 May 2021 12:28:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:56820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbhELPiU (ORCPT ); Wed, 12 May 2021 11:38:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 65B9E61C65; Wed, 12 May 2021 15:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832809; bh=hZWnAzRTgoMkcZpCZMtJj4pGVbRrv/fyZvi4D1X31cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ko+uYjyek01xGiQGJe+uFoODDzdAr7am9jSBDjF7tvdkIOrmpSL2KaUOqa5qlkVEQ NZqMQEHWpJTLNNPZdGAD8KVb/Qm74md0Jlm+Ylc7bQAJ2WpYYt18vIxKyTQDceB41S nQgSvrye/aACmoUkakIVLClYYhj3w+S5oMyzeJ2M= 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.10 432/530] i2c: omap: fix reference leak when pm_runtime_get_sync fails Date: Wed, 12 May 2021 16:49:02 +0200 Message-Id: <20210512144833.964451752@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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