Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1595724pxj; Wed, 19 May 2021 09:22:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMgYEP2Fl1NjdI0qgPWkgn6RF9W9a+NnymKM8xGO1QjuUFz/EAVjrHkvQkofJ2JYCvpoMX X-Received: by 2002:a05:6638:dd2:: with SMTP id m18mr14226197jaj.40.1621441373679; Wed, 19 May 2021 09:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621441373; cv=none; d=google.com; s=arc-20160816; b=AIV4fO/TCFNitibryTjOsuxGu0rgnIPRv50dZNyQh7I+oFbjtddflKeCiRz5ocd69V yz8SbNX8Jyg/2i/L3edfuz24NXL+UIWY5Aq7uNkpeOAkAXerE7oXU7/Lk/84KPjIqf90 Ctwvo43BRl67YB9qSyBLQxykWDBwAMoHwfVHA7rwiBzbYgBFyspd48E080lpA4u+UXXq 3AueWhuB0f8r8z/usmmjL2fTSNC8wl3BGS0pJjex4+20p1ZNDSRjDC1vjZUrqZclanQ5 R6jf1Tfj0dcJOLz8CpEno2Kb4PEZ/PuuaXJbfJzXIOJD/x5L4AOKXV/l4mNa8BbdFFYa YIeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sJsObUqc4BDyFsRGCrgI5bvSOewSFSst5bXMJ4aTl8o=; b=dU1gUEOrZ3zgaN0YacO/Srtdw5N7/53810btlhIRgM9xp/dzVWr1foDHoBOjfvw1DI 10VJawGwnKwDdARDqbRIqHYxfAXWCXsLjuFm36uY1zai8Z7lFZdvERAQWWJL8ZBJQCZ3 TAEJjbD7kFALmT582Zw9o00P/s9FgyIK0N4e8vnHR5ePLoGRR2djrHCuL51WzACud/86 px7I+r3SP3R1bg+BgCV2pM5T/ZQzirhgkt//R37KZt9OV6Z+k7u+zcF/TQLQzKs7TzgO ssaIYif5Gvl7T6DAOf8VG3HQgBjIPDmMhKxwK0N1L8qmpK7SdDBQWF41o49+Gy2B9Yp2 OR3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YW7zuKLw; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si13055387ioi.33.2021.05.19.09.22.38; Wed, 19 May 2021 09:22:53 -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=@kernel.org header.s=k20201202 header.b=YW7zuKLw; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346766AbhERHnu (ORCPT + 99 others); Tue, 18 May 2021 03:43:50 -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