Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp4167975rdh; Fri, 29 Sep 2023 13:20:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpNccm/wbbO0Rsx678YDjMR1Wit9BA5l9K94/nRC9ftToOarb/8s42xV2vON5EeGLIRIC/ X-Received: by 2002:a17:90a:d507:b0:276:5512:13ab with SMTP id t7-20020a17090ad50700b00276551213abmr8454727pju.10.1696018848974; Fri, 29 Sep 2023 13:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696018848; cv=none; d=google.com; s=arc-20160816; b=gqgim4xDMoUSOiZvSpPKEaFwYRBWdieTYQGdldGlk+Oj9lDSHLKf2a8QYF1e6NUCjb AH7GBpr1Ye4YOeonlXKoJa/CaS23/A3f0yp1azhmpWGijik0jLJwqpeg/NIRdFmBu+9P QyxfPt311vgUw1PUsYH3Ru8WNKIP9c4eysKHs38sujWjesgGxdFAcTMDevpvmY+c32jw xGuqh+2XyTLPH65XBMnPYPFnA3hZ9HMw4Y7aH9bIIXEMcU5m4u3BjzxR7cgcxEf7iqop j2z6YKYQ+DkpT11jMMRm2KLT7dtCbWPJxFvmXc+QSxAAf59fSnUY3b1Ig8O17m7QH07r p/4Q== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=HG2dvDUve3uTM4Z7g3W9DUMv+LMY4laZ6mDUP3Xm8vo=; fh=6zcLRV1pPOwH0zY/+u1TWSk9Di1//Ydbqm4m430gjAI=; b=J3iQVj6LYoQ+nO52Ww+Fk/qoJGSoLeQACGh9AG3G8MjKSQC1UKXNubIt+PvS90cWp9 iCJd+p8Qt9+4DrT4GO+RxzT7Pim5QMvH47XfkULG+HckJNwrcEdgpH1UBvdBg6kRDtcu pl407ZinaSudDQ30zkRfCpq8sgxn90L6ESyEjqdiQak/FeIjnA4gjsxOfTIfc364SULx ihfUMJ3W+SDQ5DEBGUw47oFeO3bSTkDPppy61jazp4urd/Vb/zZNv9ZhUbGz5bscbFXI qwCNzq3g5r85r3A5Ax30Nbi8K1uD0pIYTCo8H0gUFUCYakDua1e/1YxYUiY/d11rFsEq gkdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Skjkzz+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id t185-20020a6381c2000000b0057761dd9c56si2589476pgd.322.2023.09.29.13.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 13:20:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Skjkzz+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 76CDF8145554; Fri, 29 Sep 2023 10:19:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232800AbjI2RSc (ORCPT + 99 others); Fri, 29 Sep 2023 13:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbjI2RSb (ORCPT ); Fri, 29 Sep 2023 13:18:31 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56952B4; Fri, 29 Sep 2023 10:18:28 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8E05E240005; Fri, 29 Sep 2023 17:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696007906; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HG2dvDUve3uTM4Z7g3W9DUMv+LMY4laZ6mDUP3Xm8vo=; b=Skjkzz+JxZ//KdyFOwjlbpudULf17RSn+Xo2plOZ0ngc6NQJCu0WbnKP8RgTKcLNNy1M+x +Bt19CM4S2WBesX60Wb8/wGMDigsV8Bw1TmVHEZd7h841smsgMoiLiHkIc8BE0NRlZUggu KR3KpbD6L9ZjYZ26clUvHoROL//iB73zR7/dwxXedG6gnfjYqxO93x1Bv+TqWtl2KuAUcm Ie3eW5lo6vgCOMX7lwBiVI84e+luInWx/9mgVb1r5rnMqkop/moXEXgK9Ay0eW9Cpfe/y7 6B1+nkZuFdwy6s1Ly/vGf8+90NVJrVFThSpROvskeLOxhqqTsfgnakQfNgGbOQ== Date: Fri, 29 Sep 2023 19:18:24 +0200 From: Herve Codina To: Lizhi Hou Cc: , , , , , Subject: Re: [PATCH v3] PCI: of: Fix memory leak when of_changeset_create_node() failed Message-ID: <20230929191824.25ef93f1@bootlin.com> In-Reply-To: <1696007417-42059-1-git-send-email-lizhi.hou@amd.com> References: <1696007417-42059-1-git-send-email-lizhi.hou@amd.com> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 29 Sep 2023 10:19:11 -0700 (PDT) Hi Lizhi, On Fri, 29 Sep 2023 10:10:17 -0700 Lizhi Hou wrote: > In function of_pci_make_dev_node(), the cset needs to be destroyed and > freed when of_changeset_create_node() returns null. > > Fixes: 407d1a51921e ("PCI: Create device tree node for bridge") > Reported-by: Herve Codina > Closes: https://lore.kernel.org/all/20230911171319.495bb837@bootlin.com/ > Signed-off-by: Lizhi Hou > --- > drivers/pci/of.c | 19 +++++++++++-------- > 1 file changed, 11 insertions(+), 8 deletions(-) > > diff --git a/drivers/pci/of.c b/drivers/pci/of.c > index 2af64bcb7da3..51e3dd0ea5ab 100644 > --- a/drivers/pci/of.c > +++ b/drivers/pci/of.c > @@ -657,30 +657,33 @@ void of_pci_make_dev_node(struct pci_dev *pdev) > > cset = kmalloc(sizeof(*cset), GFP_KERNEL); > if (!cset) > - goto failed; > + goto out_free_name; > of_changeset_init(cset); > > np = of_changeset_create_node(cset, ppnode, name); > if (!np) > - goto failed; > - np->data = cset; > + goto out_destroy_cset; > > ret = of_pci_add_properties(pdev, cset, np); > if (ret) > - goto failed; > + goto out_free_node; > > ret = of_changeset_apply(cset); > if (ret) > - goto failed; > + goto out_free_node; > > + np->data = cset; > pdev->dev.of_node = np; > kfree(name); > > return; > > -failed: > - if (np) > - of_node_put(np); > +out_free_node: > + of_node_put(np); > +out_destroy_cset: > + of_changeset_destroy(cset); > + kfree(cset); > +out_free_name: > kfree(name); > } > #endif Reviewed-by: Herve Codina Best regards, Hervé