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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 D6669C433B4 for ; Tue, 18 May 2021 12:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0E0F61209 for ; Tue, 18 May 2021 12:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233424AbhERNAD (ORCPT ); Tue, 18 May 2021 09:00:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231321AbhERNAB (ORCPT ); Tue, 18 May 2021 09:00:01 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D94BAC061573 for ; Tue, 18 May 2021 05:58:43 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id g6-20020a17090adac6b029015d1a9a6f1aso1686379pjx.1 for ; Tue, 18 May 2021 05:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mv2uwTbL30jlJAM/eaiNlLKn6+rdPCA/0KtvmGZQeAA=; b=DNo0vG/Los+2xPXou0DmP/K7ITFwoVlcYcfGs3JPRFjshrw7yl0Kh/6NURDRr0GZM1 BrSt4M6vRuTzXy5MC0slfCjxj2bzDBFYZ3bDpnayjvlsrNygJ02FOmPOdIAHb+HjIrd1 NtLz7QZ2n7B8Ql62a/NR8mCNzr0bPF82QqbjZu2kNgwD7JV5N+Q9hvRwqB1/0Dm4W/Ox fAHMCtJkwQ1it3eGHd5KEI38XwQA+2uUh9WMb+X+UoFnniHOa0M84azWvZu5UBuKu/HU ZoCjFC77XPvi4D+yLfB67Q4t/OzhgSz6+xnQyCO01oreHsLZAsWNtnBdrN66kkmzWkl8 Uwuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mv2uwTbL30jlJAM/eaiNlLKn6+rdPCA/0KtvmGZQeAA=; b=QI52cKzAor14lkLP928QX/qEshI0LETsCv4pudo8JKGOqjfzZzzWX17QMYRVa2nmx3 +EqHzCmKEDoc+sBBwPmxSIoWnRZegl7IR8DX+KgWukpracsVwUUUKqtXLOlECAG/jZNl rBFC8Y/yf7mTablZfgBgxyVKMFqQUcyiMDi1Mm2nLUWOyEV21AGX/CFsLGz+HT+P4RLE asho8rYEnSAyO8GQCjJYkOz5C3ThUHjY9ODcruR79qm0vF6wkNtnJk9MZVY6aj6FOJlV ok8qWqBpre9sN70fv5gqoR6vToL7JikbqItm8IstSScLUm4i1pszkRK+kk7Kzc5AIDIY Dk+A== X-Gm-Message-State: AOAM530Luxyx9Ponf8T3LY9TMsrmhuSix5MjRuMA2DNyJm5GHZt9IzfI hm7Zu+GO4svz0BH2VylOTOMSXCK3rbl6KaAkQUCMLw== X-Google-Smtp-Source: ABdhPJwvPJXAq1cWqigGtb0woH3Q8hJnCu15moqg/VmcFxxsKkoR0ESvlmq4tiTL1iWXCRqFKiC/UCsODLkpBrmayDQ= X-Received: by 2002:a17:90a:e391:: with SMTP id b17mr606869pjz.75.1621342723427; Tue, 18 May 2021 05:58:43 -0700 (PDT) MIME-Version: 1.0 References: <20210517081601.1563193-1-yukuai3@huawei.com> In-Reply-To: From: Robert Foss Date: Tue, 18 May 2021 14:58:32 +0200 Message-ID: Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe() To: Johan Hovold Cc: Yu Kuai , Andrzej Hajda , Neil Armstrong , David Airlie , Daniel Vetter , dri-devel , linux-kernel , yi.zhang@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 May 2021 at 09:42, Johan Hovold wrote: > > 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"); This error message is a bit confusing now, could you update it. > > > 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. Thanks for chiming in Johan, you're absolutely right and I must have misread something. With the above fix, feel free to add my r-b. Reviewed-by: Robert Foss 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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,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 C6ABEC433ED for ; Tue, 18 May 2021 12:58:46 +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 8D49060FF0 for ; Tue, 18 May 2021 12:58:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D49060FF0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.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 D7B826E88D; Tue, 18 May 2021 12:58:45 +0000 (UTC) Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by gabe.freedesktop.org (Postfix) with ESMTPS id D04726E88D for ; Tue, 18 May 2021 12:58:43 +0000 (UTC) Received: by mail-pj1-x102a.google.com with SMTP id b13-20020a17090a8c8db029015cd97baea9so1712570pjo.0 for ; Tue, 18 May 2021 05:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mv2uwTbL30jlJAM/eaiNlLKn6+rdPCA/0KtvmGZQeAA=; b=DNo0vG/Los+2xPXou0DmP/K7ITFwoVlcYcfGs3JPRFjshrw7yl0Kh/6NURDRr0GZM1 BrSt4M6vRuTzXy5MC0slfCjxj2bzDBFYZ3bDpnayjvlsrNygJ02FOmPOdIAHb+HjIrd1 NtLz7QZ2n7B8Ql62a/NR8mCNzr0bPF82QqbjZu2kNgwD7JV5N+Q9hvRwqB1/0Dm4W/Ox fAHMCtJkwQ1it3eGHd5KEI38XwQA+2uUh9WMb+X+UoFnniHOa0M84azWvZu5UBuKu/HU ZoCjFC77XPvi4D+yLfB67Q4t/OzhgSz6+xnQyCO01oreHsLZAsWNtnBdrN66kkmzWkl8 Uwuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mv2uwTbL30jlJAM/eaiNlLKn6+rdPCA/0KtvmGZQeAA=; b=XmVJH/jItyT2DrKk8siQe2JaqAzI1bX+ql6yIEWXm+oQvvRNzIkRl6KV7Ga9yngpAy UicqynRJSXU+cy0wC2WPdFVny+4ov/LiZ05h0XugldgEgs7PKr1HzVMnhaEk0SNUKiua wKdRYem8q08K46egeKVxEAuE5/ubex62aPB+0uvxTpFbQy2s9LEoO5Sr7WxGUFm2I94E ooavCT372qp19NaqMkqpza7AWKngh8SBjcDl2k8cMTqmrzkYKXKtSL0YH+WKJJ/U0SFZ h7c7J0s3QVac8WCLLFGUkIuQXKj6BmotFZKBj/zDBqCAue6FjOpoqvhafEO5FI7RmkIB UF3w== X-Gm-Message-State: AOAM533992pBiypx5j1RLRjsRHhv06e7jWkgWwutMwb+OMcmsnLxxW4f TD9kBuL5VMFW1BprONcpbGCGLUOI833BbNGv2crMKg== X-Google-Smtp-Source: ABdhPJwvPJXAq1cWqigGtb0woH3Q8hJnCu15moqg/VmcFxxsKkoR0ESvlmq4tiTL1iWXCRqFKiC/UCsODLkpBrmayDQ= X-Received: by 2002:a17:90a:e391:: with SMTP id b17mr606869pjz.75.1621342723427; Tue, 18 May 2021 05:58:43 -0700 (PDT) MIME-Version: 1.0 References: <20210517081601.1563193-1-yukuai3@huawei.com> In-Reply-To: From: Robert Foss Date: Tue, 18 May 2021 14:58:32 +0200 Message-ID: Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe() To: Johan Hovold Content-Type: text/plain; charset="UTF-8" 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 Tue, 18 May 2021 at 09:42, Johan Hovold wrote: > > 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"); This error message is a bit confusing now, could you update it. > > > 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. Thanks for chiming in Johan, you're absolutely right and I must have misread something. With the above fix, feel free to add my r-b. Reviewed-by: Robert Foss