Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4699090rdb; Fri, 15 Sep 2023 09:34:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMW8khVOA6u//jZHr3YXczq/vW8/slbRrHu49iEtrQqqRdrtv0pwamzKXC4PZF6x1WqIIq X-Received: by 2002:a17:903:1210:b0:1bb:7f71:df43 with SMTP id l16-20020a170903121000b001bb7f71df43mr2624342plh.34.1694795687788; Fri, 15 Sep 2023 09:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694795687; cv=none; d=google.com; s=arc-20160816; b=z0umrBra1r0sr7WRHSCZNMavCva5H+4cwx2UP/NLIDQawFuktZoLVFbr2lxoW7Lys7 XiAx8J4c1juW09hrykAU1VCQda6901y5Hel/xrxmZak01yk5k8d6N7tEAAhBecIr0mq8 d5Bhws8GqfEvXztbF2ImMSg+HeA2iyHBjY3wZ37KWeZ2zfMR99U45Y4QbJrIi5C3qAq8 Zs2Z+roN8TDRoVJHOCYg/bblblnWSb1dyDJPykG9aJy8udQ0XNentTfVD3s+RtF1RMjW YGaQ9eaEJHgER/9zebHvMmuTYv1gpC6cnEd20d+GhWk9etW2jB7CA3PmKVQoZwvXArKZ ZNUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=VKqV4qAaqSMLRrtpwzl8664JvBqHUtW8Vp2WKCLOiuw=; fh=tOqijPSGLq7h8RHi4dCGDh380EDQr8PALiFbHG5OAcQ=; b=qm250mDg5GRLny9l4sBLBWsKI6APZjwsE+CQ2nRYbxn/+BPDqrLQqcY03Z4pOxm+nS 3Ya812Ew07zj7fKh5ymBZjnPPKeo/YsGo3iMRXl9UtOQCaC1Xpbu0hmCLjZLFYguZQ7d r7HePn6ToEhsCsHgy8eQUp1efmynqdRL63tocA9ff0joYmOJ2PJ/rcB/+DSt8DDTfDko +0vR3z/1KyeRVoUg/OuMGvOrTS6eqxRay35XtxX6SsJ4Uzqeiz2q1m1RYibCVDcyZd6g w/3wVgA1nYLBQasZ7au0GBCxRAuG4icNdRRMd+3mARjKCa192truHPTI/SG3gocEAC5b kbTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u7aiWE+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id ay6-20020a1709028b8600b001bbd81eaabasi3557124plb.57.2023.09.15.09.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:34:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u7aiWE+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 372E6822DA37; Fri, 15 Sep 2023 09:21:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234685AbjIOQUq (ORCPT + 99 others); Fri, 15 Sep 2023 12:20:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234352AbjIOQUd (ORCPT ); Fri, 15 Sep 2023 12:20:33 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B58F92126; Fri, 15 Sep 2023 09:20:27 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F8DEC433C8; Fri, 15 Sep 2023 16:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694794827; bh=09qiNK97UkC7z4w2HDWfvU6mCQX7TU4riPt+V3SNirs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=u7aiWE+JTh1VIf7KfPFvuFYSjMH47l2bE2pQ45b5ZGBv1XjtbtV8C0tzoTkUuMU3/ FNhERerwaqnYmLToHhqgrpYes+tjS/BqQLOiRGRR/kiSs9MlOCX81Cn9m1FLexwrYW coIbwydPUEGcrPQsNYb5P7Q8iM6JRHsGTw36d6XDW8McPzEjuKBxCYBBC0J5XmL+UC EwuRLfebfMk2oUvGjyVlwZpqso5SvmODAFhbQN4rgjttZEOwepAOju7SUIYliYnpK5 GlAWGOqidqJHnT0Rnx7frJEvnlGvadid/HABrWAwuHzvusJ6yIpQScXM/2SyuBi6hN tav7dPMFN7vag== Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-502b1bbe5c3so3898852e87.1; Fri, 15 Sep 2023 09:20:27 -0700 (PDT) X-Gm-Message-State: AOJu0Yx+3gfkeQ1Q4LMWv6u7mWdQWnsUsl5PXjgjk5WpErFmTPJgOGMK fcQGo9MeLdKEBB5YHsSKDtNhrWzduW0nP95kkg== X-Received: by 2002:a05:6512:3103:b0:4fe:2d93:2b51 with SMTP id n3-20020a056512310300b004fe2d932b51mr1945694lfb.27.1694794825519; Fri, 15 Sep 2023 09:20:25 -0700 (PDT) MIME-Version: 1.0 References: <1694715351-58279-1-git-send-email-lizhi.hou@amd.com> In-Reply-To: <1694715351-58279-1-git-send-email-lizhi.hou@amd.com> From: Rob Herring Date: Fri, 15 Sep 2023 11:20:13 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed To: Lizhi Hou Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, herve.codina@bootlin.com, bhelgaas@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 15 Sep 2023 09:21:19 -0700 (PDT) On Thu, Sep 14, 2023 at 1:16=E2=80=AFPM 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 | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/of.c b/drivers/pci/of.c > index 2af64bcb7da3..67bbfa2fca59 100644 > --- a/drivers/pci/of.c > +++ b/drivers/pci/of.c > @@ -663,7 +663,6 @@ void of_pci_make_dev_node(struct pci_dev *pdev) > np =3D of_changeset_create_node(cset, ppnode, name); > if (!np) > goto failed; > - np->data =3D cset; > > ret =3D of_pci_add_properties(pdev, cset, np); > if (ret) > @@ -673,12 +672,17 @@ void of_pci_make_dev_node(struct pci_dev *pdev) > if (ret) > goto failed; > > + np->data =3D cset; > pdev->dev.of_node =3D np; > kfree(name); > > return; > > failed: > + if (cset) { Instead of adding more if's, use multiple goto labels which is the normal cleanup style. Note that there's a new cleanup.h thing that can do some automatic cleanups. Not sure if that works or helps here. > + of_changeset_destroy(cset); > + kfree(cset); > + } > if (np) > of_node_put(np); > kfree(name); > -- > 2.34.1 >