From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C3DAC433B4 for ; Tue, 18 May 2021 07:42:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1ADED611BF for ; Tue, 18 May 2021 07:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347174AbhERHnv (ORCPT ); Tue, 18 May 2021 03:43:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:35406 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239746AbhERHnt (ORCPT ); Tue, 18 May 2021 03:43:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C7A3061209; Tue, 18 May 2021 07:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621323751; bh=Im/ud3QbEyXaW+C1E0XlGLo8OIyfrTetRhyjc6Lp02I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YW7zuKLwTYwrSMdjAUGilRpBP8EsMEqPj2w6VTgLRHgRmOlc6J+rhc0e39C84tNPC 78aHx5aBElsmh8EuHDaWcPSfsk3A94r9rOWgUpgiKJgZkW+QakDwQk4GOyRZ2/nYQD LhJ9qKEQdfTv+lUH/aKqVTVu7UH1cql8/KOmKhSllAfY7045gkOFOQi8tasv+73EWF 6CLeTd1+5Q5RTZ58jSnbHlfUX7fxOOBmSyqUhZ0FNhwEMVN0EczVchDV8ddnepLAt+ 678zNcytpYByfXgPzejHondjyHSvA31zuIXNWVv4E4EFEdyaoRv2hkm3uy6myUsC3i 4jv5QwJT83oZQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1liuN3-0005tT-7f; Tue, 18 May 2021 09:42:29 +0200 Date: Tue, 18 May 2021 09:42:29 +0200 From: Johan Hovold To: Robert Foss Cc: Yu Kuai , Andrzej Hajda , Neil Armstrong , David Airlie , Daniel Vetter , dri-devel , linux-kernel , yi.zhang@huawei.com Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe() Message-ID: References: <20210517081601.1563193-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 17, 2021 at 11:27:38AM +0200, Robert Foss wrote: > Hey Yu, > > On Mon, 17 May 2021 at 10:08, Yu Kuai wrote: > > > > pm_runtime_get_sync will increment pm usage counter even it failed. > > Forgetting to putting operation will result in reference leak here. > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage > > counter balanced. > > > > Reported-by: Hulk Robot > > Signed-off-by: Yu Kuai > > --- > > drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > > index 0cd8f40fb690..305489d48c16 100644 > > --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > > @@ -2478,7 +2478,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev) > > clk_prepare_enable(clk); > > > > pm_runtime_enable(dev); > > - ret = pm_runtime_get_sync(dev); > > + ret = pm_runtime_resume_and_get(dev); > > if (ret < 0) { > > dev_err(dev, "pm_runtime_get_sync failed\n"); > > pm_runtime_disable(dev); > > The code is correct as it is. If pm_runtime_get_sync() fails and > increments[1] the pm.usage_count variable, that isn't a problem since > pm_runtime_disable() disables pm, and resets pm.usage_count variable > to zero[2]. No it doesn't; pm_runtime_disable() does not reset the counter and you still need to decrement the usage count when pm_runtime_get_sync() fails. > [1] https://elixir.bootlin.com/linux/latest/source/include/linux/pm_runtime.h#L384 > [2] https://elixir.bootlin.com/linux/latest/source/drivers/base/power/runtime.c#L1383 Johan From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3906C433ED for ; Tue, 18 May 2021 07:42:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8240C61261 for ; Tue, 18 May 2021 07:42:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8240C61261 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DBB76EAB0; Tue, 18 May 2021 07:42:33 +0000 (UTC) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2FB416EAB0 for ; Tue, 18 May 2021 07:42:32 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C7A3061209; Tue, 18 May 2021 07:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621323751; bh=Im/ud3QbEyXaW+C1E0XlGLo8OIyfrTetRhyjc6Lp02I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YW7zuKLwTYwrSMdjAUGilRpBP8EsMEqPj2w6VTgLRHgRmOlc6J+rhc0e39C84tNPC 78aHx5aBElsmh8EuHDaWcPSfsk3A94r9rOWgUpgiKJgZkW+QakDwQk4GOyRZ2/nYQD LhJ9qKEQdfTv+lUH/aKqVTVu7UH1cql8/KOmKhSllAfY7045gkOFOQi8tasv+73EWF 6CLeTd1+5Q5RTZ58jSnbHlfUX7fxOOBmSyqUhZ0FNhwEMVN0EczVchDV8ddnepLAt+ 678zNcytpYByfXgPzejHondjyHSvA31zuIXNWVv4E4EFEdyaoRv2hkm3uy6myUsC3i 4jv5QwJT83oZQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1liuN3-0005tT-7f; Tue, 18 May 2021 09:42:29 +0200 Date: Tue, 18 May 2021 09:42:29 +0200 From: Johan Hovold To: Robert Foss Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe() Message-ID: References: <20210517081601.1563193-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Neil Armstrong , David Airlie , yi.zhang@huawei.com, linux-kernel , dri-devel , Andrzej Hajda , Yu Kuai Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Mon, May 17, 2021 at 11:27:38AM +0200, Robert Foss wrote: > Hey Yu, > > On Mon, 17 May 2021 at 10:08, Yu Kuai wrote: > > > > pm_runtime_get_sync will increment pm usage counter even it failed. > > Forgetting to putting operation will result in reference leak here. > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage > > counter balanced. > > > > Reported-by: Hulk Robot > > Signed-off-by: Yu Kuai > > --- > > drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > > index 0cd8f40fb690..305489d48c16 100644 > > --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > > @@ -2478,7 +2478,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev) > > clk_prepare_enable(clk); > > > > pm_runtime_enable(dev); > > - ret = pm_runtime_get_sync(dev); > > + ret = pm_runtime_resume_and_get(dev); > > if (ret < 0) { > > dev_err(dev, "pm_runtime_get_sync failed\n"); > > pm_runtime_disable(dev); > > The code is correct as it is. If pm_runtime_get_sync() fails and > increments[1] the pm.usage_count variable, that isn't a problem since > pm_runtime_disable() disables pm, and resets pm.usage_count variable > to zero[2]. No it doesn't; pm_runtime_disable() does not reset the counter and you still need to decrement the usage count when pm_runtime_get_sync() fails. > [1] https://elixir.bootlin.com/linux/latest/source/include/linux/pm_runtime.h#L384 > [2] https://elixir.bootlin.com/linux/latest/source/drivers/base/power/runtime.c#L1383 Johan