Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp8006406ioo; Fri, 3 Jun 2022 19:41:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGdCjdtY80/aXWmR+7NfEM6uZ2sFHoL+eenW8pEGqpREytV7PVuUep2tquNGPfu91X0v69 X-Received: by 2002:a17:903:22c6:b0:167:5991:fb63 with SMTP id y6-20020a17090322c600b001675991fb63mr2683553plg.37.1654310498943; Fri, 03 Jun 2022 19:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654310498; cv=none; d=google.com; s=arc-20160816; b=aV6/qLFhcmDvn7n4YZiJ100++iQnfzGRnZNDiNse60SIjJNKX0BzCstUx9BGDQcqLS BCPj51s2PPCJCIz2JZV1BHdR+M92DGMTcaGFmR993InzLVxZV15kBp8JxP6iRwsbGDSC JQrmioATy8qfI6aePRAmOr7ys2KL/4cjElCfrjxXufAUAQ+gbe9FOSCTTLxwtczLRm0X s+ejfSkQWdaJ7JiAepGHOnNgicaFbsUWO6LMTcg9xwBkjOVsxEGreRSmbWhschOQEX7E DBjraGlou/hK4wXL0MoK5vbaSkMadBtNSZBwDQkrC6rZp/BMeLuAGca0tjHfnU2sPCDC 6pSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=C/BxYyzz/SrI0UbGmJUwdnu9XDC9HwR0+Uda2WNLV6M=; b=VPs4jmW2vEdVWCa9DG2VJOa1u1tB+GjghsuM5FR8YkqjY930Cz29ey5D8YpjuZUUi2 fMKIsqRhS7KPWQI2VRaq7DW3xvSfNeNIL2uGb4EPJCeMStQ7tIygylpZZNTFhpulx6z3 7s8UCrf7GUZaYIYhjMVIn+6H/gn0JTANxf12Y+R2ZKfrQJHe/Tk1AAY6tdZYR+1AvPRm +Fnwo8vzLkXaAQh4Q9PvLbnXUFtlSHqjPyort2ZEVz7tR/FCyxQvaQr17SOIsGmbck8/ Z1aKJUqZGjbM+iAOgyBZwRh0Nh9eaVRfaQhKm4tO/b4Yo8XZwT5jispLYaMrJ2AHd2DV iGcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lNBNeQ8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id my1-20020a17090b4c8100b001bd14e030adsi14973811pjb.133.2022.06.03.19.40.50; Fri, 03 Jun 2022 19:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lNBNeQ8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242746AbiFCN7D (ORCPT + 99 others); Fri, 3 Jun 2022 09:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238644AbiFCN7C (ORCPT ); Fri, 3 Jun 2022 09:59:02 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E4EAE082; Fri, 3 Jun 2022 06:59:01 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id 26FF81F45910 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1654264740; bh=1PokqYaPEgiXhLt5emusMefjpPlRtuRVPgBT7aSIqAM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=lNBNeQ8yPFDvNcvNqJFOjmOTdCKsOFJYIqyIDiAkKuUfJpgakVkYDKQJ06WktOsJY K4+jxiwjdc/9BaX+ysLBfnyDIjk7K71EJgH84mhGNvHaXDG2AEtbPkrxsxGOQYtASp dO9KwSOZoT//vsWI+08+CYrKrO1f1d2JgGBklCuDv3nj8HmkjgawELdyso3EYnrJam jwdPlQR2zAEbYzpdppEx2jpZehUrAw2cSAwWNDaCfPZybaU8zbEls0fzyyta+fd1up sLTfoeTs92lKFc1rgiJV6ho7/SEe74DUJ9eRqICOl7fR45IGFEmLeQ73F4BMjib/Iy OXat3n7Yh8s3w== Message-ID: Date: Fri, 3 Jun 2022 16:58:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v2] drm/tegra: dc: rgb: Fix refcount leak in tegra_dc_rgb_probe Content-Language: en-US To: Miaoqian Lin , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Mark Zhang , Terje Bergstrom , Dave Airlie , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220603132703.42085-1-linmq006@gmail.com> From: Dmitry Osipenko In-Reply-To: <20220603132703.42085-1-linmq006@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/3/22 16:27, Miaoqian Lin wrote: > of_get_child_by_name() returns a node pointer with refcount > incremented, we should use of_node_put() on it when not need anymore. > So add of_node_put() in error paths. > > Fixes: d8f4a9eda006 ("drm: Add NVIDIA Tegra20 support") > Signed-off-by: Miaoqian Lin > --- > changes in v2: > - update Fixes tag. > v1 Link: https://lore.kernel.org/r/20220602155615.43277-1-linmq006@gmail.com > --- > drivers/gpu/drm/tegra/rgb.c | 31 +++++++++++++++++++++---------- > 1 file changed, 21 insertions(+), 10 deletions(-) > > diff --git a/drivers/gpu/drm/tegra/rgb.c b/drivers/gpu/drm/tegra/rgb.c > index ff8fce36d2aa..cef2b1b72385 100644 > --- a/drivers/gpu/drm/tegra/rgb.c > +++ b/drivers/gpu/drm/tegra/rgb.c > @@ -196,12 +196,16 @@ int tegra_dc_rgb_probe(struct tegra_dc *dc) > int err; > > np = of_get_child_by_name(dc->dev->of_node, "rgb"); > - if (!np || !of_device_is_available(np)) > - return -ENODEV; > + if (!np || !of_device_is_available(np)) { > + err = -ENODEV; > + goto err_put_node; > + } > > rgb = devm_kzalloc(dc->dev, sizeof(*rgb), GFP_KERNEL); > - if (!rgb) > - return -ENOMEM; > + if (!rgb) { > + err = -ENOMEM; > + goto err_put_node; > + } > > rgb->output.dev = dc->dev; > rgb->output.of_node = np; > @@ -209,31 +213,34 @@ int tegra_dc_rgb_probe(struct tegra_dc *dc) > > err = tegra_output_probe(&rgb->output); > if (err < 0) > - return err; > + goto err_put_node; > + > > rgb->clk = devm_clk_get(dc->dev, NULL); > if (IS_ERR(rgb->clk)) { > dev_err(dc->dev, "failed to get clock\n"); > - return PTR_ERR(rgb->clk); > + err = PTR_ERR(rgb->clk); > + goto err_put_node; > } > > rgb->clk_parent = devm_clk_get(dc->dev, "parent"); > if (IS_ERR(rgb->clk_parent)) { > dev_err(dc->dev, "failed to get parent clock\n"); > - return PTR_ERR(rgb->clk_parent); > + err = PTR_ERR(rgb->clk_parent); > + goto err_put_node; > } > > err = clk_set_parent(rgb->clk, rgb->clk_parent); > if (err < 0) { > dev_err(dc->dev, "failed to set parent clock: %d\n", err); > - return err; > + goto err_put_node; > } > > rgb->pll_d_out0 = clk_get_sys(NULL, "pll_d_out0"); > if (IS_ERR(rgb->pll_d_out0)) { > err = PTR_ERR(rgb->pll_d_out0); > dev_err(dc->dev, "failed to get pll_d_out0: %d\n", err); > - return err; > + goto err_put_node; > } > > if (dc->soc->has_pll_d2_out0) { > @@ -241,13 +248,17 @@ int tegra_dc_rgb_probe(struct tegra_dc *dc) > if (IS_ERR(rgb->pll_d2_out0)) { > err = PTR_ERR(rgb->pll_d2_out0); > dev_err(dc->dev, "failed to get pll_d2_out0: %d\n", err); > - return err; > + goto err_put_node; > } > } > > dc->rgb = &rgb->output; > > return 0; > + > +err_put_node: > + of_node_put(np); > + return err; > } > > int tegra_dc_rgb_remove(struct tegra_dc *dc) Doesn't look like the node is put on driver removal either. Hence you should make it resource-managed. -- Best regards, Dmitry