Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp36473rdb; Fri, 29 Sep 2023 15:49:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG39Xs7O9aIofTzlLpbOfkXe126gOGgp5b9A0t91j6KATmji9Shdz6x35JcDV1FQCEb3zVs X-Received: by 2002:a05:6870:b527:b0:1b4:60b3:98bc with SMTP id v39-20020a056870b52700b001b460b398bcmr6134464oap.2.1696027746936; Fri, 29 Sep 2023 15:49:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696027746; cv=none; d=google.com; s=arc-20160816; b=uzk+tEBWc5dvigbW54LfTsjX7nZkU8nNtC3IpPxmlLdu4dhsiOLgmFiVOTVrHsa87U soHM5xQDNWpITobFs66agaCDEu8bIdk3ju5FcvEE8Zf2lIQtQvlRCSlgO+OvwmiCLSHd iIiTmnOMn1R8zzxNA8BNZcgB9xnKi8Oi9sdd+m8KUZFx2M463ntTmY1Ot4aQ7AbI1PrR 1sDvswciky5JO+CKqihaNNfPz+5G51MlxgXXsUSVB1tBGjUkFCiv3Hd9mfQQpLYQhEHc SCNPvITf/Qa6RemYXz1PrDEV2QV3pgw38iALwYmqjRsoyM1BX/md96hxNhd2vCFYTHrn UMDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=1uao5uMu8U/6yd9rA87GbHwB0RqkAZ3usAhtFzlMOuk=; fh=hl/UrDdz/6OFGyglMrR3c0OrOcLV5uoGMaNCVzymZgY=; b=isus9/3IbrsmHhrXjKLVDDJLJatp3AtPNkK7eAkQ7mIxeIdTzUX+mZRUyKT50MMIw7 h53Nr9q0tGYAXDq2QpWhj29+oRA22Czzk4y/vkoAbn8SpHq5Iimq6sXxlFC8McCndniA 6iBFtnFFuyoQstvGTSBfT8ft//AQle4sT8oBaxqcQevwFrakknQ0QuimDAqmPkrUpiPd eRpibB8DVhSJswR1OF3vAXdjFXzqh2y6B8mb5bhEV/FpH7K61RrLZ8oAV5Oj/sfFGrje nvhQh7Adbjv79XwKclsNZN/qlpKpJd9BXvbLFqHfsMRzNVY+sl+E+wuA7bGS6jJ7AN6H Cw5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nHTf1To0; 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 j24-20020a63cf18000000b00578c3b7af9fsi21075772pgg.184.2023.09.29.15.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 15:49:06 -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=nHTf1To0; 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 665DB80A7309; Fri, 29 Sep 2023 15:37:28 -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 S233897AbjI2WhZ (ORCPT + 99 others); Fri, 29 Sep 2023 18:37:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233865AbjI2WhX (ORCPT ); Fri, 29 Sep 2023 18:37:23 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F38681B9; Fri, 29 Sep 2023 15:37:20 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29AD2C433C8; Fri, 29 Sep 2023 22:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696027040; bh=+FQSIscV9bqF6D32g6rcCgdI77KM9F6e8NRJftItj7k=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=nHTf1To0ChjzbhV1T/9z1W1L5KJpJqgPQ/nDjvgh2b2zZTkOjJ+jM7SpH5f8Sh9ma AQeyYKoWeOfqHnJVSZofA8QWDN1GT695GJf0glmYDxw0w+drOuUTjr9yul2v8Bziav 5Oq4SLHYkZtprKmZWIoexApRS1txHTfzueQq9lQao54pWDtUThjhjAo/9ZyYI4L0pI 3leK2elL54RqphCRfdXLA3R8ppBQUtDyBNwLOwaQzsnLk27oJHa6xXuFjlVGZ/i9p7 Tpz2gfVgcSYyja4qC0C3TRJEpCxvGGJUaHzLrqQfvDt5vmjo9Xe8sHk8zvDd673/ed zHO9EzwaH/bLA== Date: Fri, 29 Sep 2023 17:37:18 -0500 From: Bjorn Helgaas To: Lizhi Hou Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, herve.codina@bootlin.com, Jonathan.Cameron@huawei.com, bhelgaas@google.com, robh@kernel.org Subject: Re: [PATCH v3] PCI: of: Fix memory leak when of_changeset_create_node() failed Message-ID: <20230929223718.GA558826@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1696007417-42059-1-git-send-email-lizhi.hou@amd.com> 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, 29 Sep 2023 15:37:28 -0700 (PDT) On Fri, Sep 29, 2023 at 10:10:17AM -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 Applied with Herve's Reviewed-by to for-linus for v6.6, since 407d1a51921e appeared in v6.6-rc1, thanks! > --- > 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 > -- > 2.34.1 >