Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3165380rdh; Thu, 28 Sep 2023 04:52:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPf5Yi3x/qVRIJSxAEkH+hyhVqU+2WoKKvBi3yiOVOs8ufA5hwMcXBwsRawb1bMY+aR/j/ X-Received: by 2002:a05:6358:4311:b0:143:96ac:96ec with SMTP id r17-20020a056358431100b0014396ac96ecmr789363rwc.25.1695901955228; Thu, 28 Sep 2023 04:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695901955; cv=none; d=google.com; s=arc-20160816; b=QugKmqUfHaFk0qCfLu4yUZ2JWFwuOKAAm9Ffn3IB8Tjz4f/IjBVY6SqvMxCiqF7u4z W3tDDmKuHnpsmtqI7r/zeQesKJzii4J0CtNnTdSgkX/JljkCR9fQ33buICBmyR6Klj9V EoYsJ/837tOlzmRWsMXYLGaZfJfHRXfslZzjEOVC1tNJYU8zT8D8oF3aUeDfrZhqfXDa QZHgsxehm8S9/FN4qmUfsbLyGvA5yrVw5ldGI6SNJnX/xugRbPuocPobFwfEZQnOPFCy WZeou0H6ebmMV2NUZJK4YcXRWgcpU+W5P8e+I0wtLYj/ngDQZTqZ2xywxpTAQtnlxK57 EYFQ== 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=Y3919oFJXD3Z80tV6szKrbS40xM7VKr5B0qY8vY1KUA=; fh=6zcLRV1pPOwH0zY/+u1TWSk9Di1//Ydbqm4m430gjAI=; b=Rq3U8RdrvEHFXd5cNkY7EiVaeWcyW/6lxTnO7YMwRChFrBshSpW+OVF9U/9q2YQRPQ ANDPhjTOuL+d86xmNMK3ZlP90AVuiUjNI1CeMpLX2nSgUK3v5P3EpQC+eXsp+7Sxet2d IsHgAXMaqTyxzDfj9PDAGxLyLE7/TzZy6EZdDZQTBaKl8otOx3awX7SJCta+UG0h2a4L KF8+wORpYmi8ygF8kgfGmhU0uxX06eW4PJhxnC/gTFVRh7vWjs3j3DNXDvmPg6NvPTZv FSmh7x+20asAloqi1yW4PzI3xO03apJi9PREjFEx19+08VhFLLwaQt0yxpOwif7ahC1W 8Hxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BpgMCWn8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id i186-20020a6387c3000000b00577a7c39aacsi18172206pge.275.2023.09.28.04.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 04:52:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BpgMCWn8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id C0B3380481B9; Thu, 28 Sep 2023 00:27:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231260AbjI1H1F (ORCPT + 99 others); Thu, 28 Sep 2023 03:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbjI1H1D (ORCPT ); Thu, 28 Sep 2023 03:27:03 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F154495; Thu, 28 Sep 2023 00:27:00 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id CF9EC20005; Thu, 28 Sep 2023 07:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1695886019; 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=Y3919oFJXD3Z80tV6szKrbS40xM7VKr5B0qY8vY1KUA=; b=BpgMCWn8tz2opVdMbiT3hF/A4kjFLdb5PDjvMeLjoH5vHAxZmt/E7DXNGSy4PdgV9cZDhC wdM+cvEC7inO+Ku2aVxTwOMIccVlihoK28yzMj6f/jPFppIhM+s8T6xMPfuENruIG1vgEm 0TUcBl2HdhtFBuubkQRxgNyQ5RLCCbvva5iywDAM7LZTHum/991LyUsX0VWDbaNkZCr+do aHuViRopHgZ1TOG4an8zqTH2CGssR1JVwIjh359+nA+lnEC8qX4G07dh+auKrtp+5sYpkF uqv6/ukr/jqBdzoXd7q1V1/mQnMEo+nCetLwua+NiwgYy8rJ2stkyliok99tSg== Date: Thu, 28 Sep 2023 09:26:57 +0200 From: Herve Codina To: Lizhi Hou Cc: , , , , , Subject: Re: [PATCH 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed Message-ID: <20230928092657.5e575202@bootlin.com> In-Reply-To: <1694801287-17217-1-git-send-email-lizhi.hou@amd.com> References: <1694801287-17217-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 00:27:30 -0700 (PDT) Hi Lizhi, On Fri, 15 Sep 2023 11:08:06 -0700 Lizhi Hou wrote: > Destroy and free cset when failure happens. > > 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..498b5cae8bca 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 failed_alloc_cset; Usually goto labels indicate what the goto does instead of where we come from. https://elixir.bootlin.com/linux/v6.5/source/Documentation/process/coding-style.rst#L536 In this case, it should be "goto failed_free_name". > of_changeset_init(cset); > > np = of_changeset_create_node(cset, ppnode, name); > if (!np) > - goto failed; > - np->data = cset; > + goto failed_create_node; same comment > > ret = of_pci_add_properties(pdev, cset, np); > if (ret) > - goto failed; > + goto failed_add_prop; same comment > > ret = of_changeset_apply(cset); > if (ret) > - goto failed; > + goto failed_add_prop; same comment > > + np->data = cset; > pdev->dev.of_node = np; > kfree(name); > > return; > > -failed: > - if (np) > - of_node_put(np); > +failed_add_prop: > + of_node_put(np); > +failed_create_node: > + of_changeset_destroy(cset); > + kfree(cset); > +failed_alloc_cset: > kfree(name); > } > #endif Best regards, Hervé