From patchwork Fri Sep 15 18:08:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 140909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1457050vqi; Fri, 15 Sep 2023 20:31:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFb9ihEG62vq6HtMCyWEDQhS2ZhzWumuFzhV3T2UvdPCuDVZ/20aGNC2jLWKruzy/AH76wY X-Received: by 2002:a05:6358:27aa:b0:125:a552:4389 with SMTP id l42-20020a05635827aa00b00125a5524389mr4299473rwb.22.1694835079507; Fri, 15 Sep 2023 20:31:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694835079; cv=pass; d=google.com; s=arc-20160816; b=JTJQiRQIdqYIkAu7sIIuJHGz86NX77hWNpXaYPSp0xlxHNcE1Hu0Mfmp74QbbuOU2g 3rP29n/SPvCDuE5oW2tCu7VNOX/Rjit6d2bPz6IIK+ZMlOjkfWOi6QC2z9bF/zomlEze aPoA1bsWMAKs5EQFZEC5gQ+eZZ94NnNctVXqebpX1E69ytMKkbzb5UWJ2pBuZD94Abyw EuxlSSCd03lDZz4+tLVJHA7mqk0Hxw87b+L+ZbXXIpBB2yRpIInuEWyJ4P5zfNQWu9WK JqTfyAzjPzAPOrXSGOUA6Qi0jhSkbEfbLHnlmH6vY5Am3A0F3NS8OK5l8UoEtWc8qzKb Fp/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=gjyaxVsTLBhP//KKYCPbJ27HdfiX3W3zpkxt1SQlsZc=; fh=stF5Iidn64dwErGQFq92GQ6LLbSjxfyHYvYqgW1K9oM=; b=0foKschRONeQaceJkX4Ny7qbuQWDrcfAcvpDfM3fepcE9LLv73Pei5ZcA6ipERNJqF PZSEUPov/W/woxZtTf6f0MmQtVap1P4gO4RC/B+dp220NNVs69MPxmNhKqOrQFovC0PX 9VE+6nAE0laB5O4OrRrkfRnfQP5GeQ0xgeYo+A3wlQgG316ADoBdwSniAGYPcpDNSXbC 8BPGFimsNzLxRu1/zJgvVn4AP6nU8QcZfaeP/VqvXB+5XJqz/T6A5OaYcs7nOBS0yj1r vWiNfnva7aChZ3gJSOaZY1DuekMXs7ayVoPyMUGZTZnd9oKBJIawnL5POGVfhtRd9CQN qPcw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xhDGzLyo; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id e126-20020a636984000000b0056b4065299esi4242402pgc.621.2023.09.15.20.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 20:31:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xhDGzLyo; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 27C208092C87; Fri, 15 Sep 2023 12:00:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236745AbjIOS7s (ORCPT + 30 others); Fri, 15 Sep 2023 14:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236641AbjIOS7Q (ORCPT ); Fri, 15 Sep 2023 14:59:16 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2051.outbound.protection.outlook.com [40.107.94.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78C5AF9; Fri, 15 Sep 2023 11:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hootONcXvIkJMkj4bo9UwN9nvylPlOWitxeOEpiVa7yq4umaOwexFR3uttSu1Knrjk4RM732L/UAw0tEQ2hM2xMyf/1zk2cbK+OoX5YeRwjQlbGtUpsGBOcWK1fCs3S+jtoR0/B+C9c1GD/kZUbPJmXOXpT+9EO/7WwX+o9M2ddmlwI+xFxFkLOq2u63ihyCspCM1bQuqobOyEY0L85PDuTyDcnUs4Jr7zHuCkDBqMvVrqQbw9vEhv2JlsUCmC9fw2JHTQrpz8VGfQHcUbyZuIGxtQqq9L70iOIYxtI6LY4XgBKVNJIIzEC0utnCF7pIcsIrO7YxCZr1DM6Pn4EdPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gjyaxVsTLBhP//KKYCPbJ27HdfiX3W3zpkxt1SQlsZc=; b=ZXHOW5EJ8+xarP118dU6tIqkN67zFeknzDxQXQISso2CrYLOMNJkSLfpchnGjP0vo50Q4wU8T9In5z9fBtDFZ+OvBtyE2/0krbRysv8hW0bLBku9poOyijaAA1YXVfHc6BgdmK2OpXdggkJO4ceqaI1nLVtKE0DpNOCSaTTEV7Pheew1y1PtCrNKkxrryF8pfwdsd4pdolS9CqEwYLL5mxttFSgzE0vO5/eglPQeBlHNkJNAwenOUFeOmqQdJdys2SmqTrTNf27kqmuLyviu43YC31H0BICphvOufuOcqbgkrBmx5+K9I84XwKj1RMgDrLqV+2Ps3g+YKB1gZKgFSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gjyaxVsTLBhP//KKYCPbJ27HdfiX3W3zpkxt1SQlsZc=; b=xhDGzLyodC7uh79AeF2h+WHQVh3bQTWuQ1kZpaOQyV2bWbT10OZhRuVbhdDn9p6eVTnQNgr8eXg7RRwKY3/QN2GMXy2b4zc/kYk/fzU2cORUdrru+uBmhTDK4lTSBnfg2P/UvLz8VJ8otY93VXneS5BppZ1b6Fo5UdLXRELpdtQ= Received: from BL1PR13CA0151.namprd13.prod.outlook.com (2603:10b6:208:2bd::6) by SJ0PR12MB5610.namprd12.prod.outlook.com (2603:10b6:a03:423::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.19; Fri, 15 Sep 2023 18:59:09 +0000 Received: from BL02EPF0001A0F9.namprd03.prod.outlook.com (2603:10b6:208:2bd:cafe::8c) by BL1PR13CA0151.outlook.office365.com (2603:10b6:208:2bd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.22 via Frontend Transport; Fri, 15 Sep 2023 18:59:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A0F9.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.19 via Frontend Transport; Fri, 15 Sep 2023 18:59:08 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 15 Sep 2023 13:59:08 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 15 Sep 2023 13:59:07 -0500 From: Lizhi Hou To: , , , , CC: Lizhi Hou , , Subject: [PATCH 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed Date: Fri, 15 Sep 2023 11:08:06 -0700 Message-ID: <1694801287-17217-1-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0F9:EE_|SJ0PR12MB5610:EE_ X-MS-Office365-Filtering-Correlation-Id: 9dad24ac-d755-4ca9-f7fb-08dbb61dd782 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: emtoL4aaGJ/LY+LTUjwq1FdGkKDazvmqrACL3+9X5RjHvKV4bSoVanYQwW8w+kolpkK+mo+tZ2sOnoNOnvNLn9anGvkL39FzOIGIPKxRX12Fpjv3mL884ra/0NVocMRTcGL9NX9x6YvIN2x29VisIDrcqseS1QxHdZG35E1fA6ZdjSm3qMQAC3Q+v+P5gljeCk5eT4/v3tl2G8wRuTvKmvzMpL+g6+QWC5LU/Vq455MWhNoOUMNfggll69/iEm3Ml77UMB/K49Bi4pIoQBoFyzkYy9xO80USLjdK9QaXZ7+pkNXEMIlwB+BlQweUjZK+IuAhrbSCh6nwB57GzOCJN5OPSn3cV0M41nh71vnJtqy2qbShIcWd2CSgN2bERsE3e34r9bSXBWiF63lPcgTaY9usiVXMDxqWvd0A8JhyDPC/00D6crul4j7De6R3iIPBnzfyxydr5cc//CQ0DVP/B6NvuvlUnBM4BtV1P2rfiwlxzgRYhUunFmQ5TtfiJVT66xiBTrohFdgssGuYjcOh551eUGknbajz0a1g4Ernfg4V6V+7Rv0JJa0RGmX5kVJRlnWKYXkWh+AbshmRtwFvKTbqURkWT2O4esBNvdoEVsy1r+PpUwZ3Cxd9nj0wzODO2z8FIk49Hi3uz9P/AwAGkqZJ2+17EZmv+Rw1LMGxhTXeQKrUN23MgGq6abKVK4Dl1t5s+C0z3G4W3pjLP09chcChss6WXZap4792HCvLESl+1hXV3POBMfk9f77BGWCbgcH7OgHZK/GRkGOpvb4SgQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(346002)(136003)(39860400002)(396003)(1800799009)(451199024)(186009)(82310400011)(46966006)(36840700001)(40470700004)(40460700003)(36860700001)(2906002)(47076005)(36756003)(86362001)(356005)(81166007)(4326008)(8676002)(40480700001)(8936002)(2616005)(5660300002)(26005)(70206006)(70586007)(110136005)(54906003)(316002)(426003)(41300700001)(82740400003)(336012)(966005)(478600001)(83380400001)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 18:59:08.8579 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9dad24ac-d755-4ca9-f7fb-08dbb61dd782 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0F9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5610 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 15 Sep 2023 12:00:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777038792458084473 X-GMAIL-MSGID: 1777163388183016358 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; of_changeset_init(cset); np = of_changeset_create_node(cset, ppnode, name); if (!np) - goto failed; - np->data = cset; + goto failed_create_node; ret = of_pci_add_properties(pdev, cset, np); if (ret) - goto failed; + goto failed_add_prop; ret = of_changeset_apply(cset); if (ret) - goto failed; + goto failed_add_prop; + 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 From patchwork Fri Sep 15 18:08:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 140658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1291525vqi; Fri, 15 Sep 2023 13:07:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8V6luiNvgeXiYzT6STKoq93IPYS2FQvrclgrA6pSkRv5WKlXEXluaMY2r1iGuqudksCw3 X-Received: by 2002:a05:6a20:3d24:b0:135:110c:c6e1 with SMTP id y36-20020a056a203d2400b00135110cc6e1mr3346273pzi.7.1694808430965; Fri, 15 Sep 2023 13:07:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694808430; cv=pass; d=google.com; s=arc-20160816; b=DAhhvHWiOcFZKAC7M0xHJl22CE+GwT6pyyhlzFa3HGeCAtvNH1r2mitnFzHNmiinFq wRhXEXewlJG0JB4ARjpF9XPEEvi94KMOHW4GuUpvTv6fXiZOmA7jLVdK8agNlxFUvAbA xcRdabHsq6i4YpLPZ87G4c3Qq39o5iJuGYdREtQ24xw5jvDccFv8shFhNvUVB5UxRSh+ nznp9m359NQm/6orIdGR42DYM/8lmeFAhYcBO1c22+zxdGQb4PBtM2w50GOmQjVC5t74 ZPdua96CuGdT46paIh69OmqNi1Vk36awL+DEZZ6ps4bXkfqOWF92naslGRWObx/abjzA mNBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nM6ZWZakbe+IBI1miklYz4jGu8Gbpl9xf2mO7nvcpH0=; fh=stF5Iidn64dwErGQFq92GQ6LLbSjxfyHYvYqgW1K9oM=; b=DAHnbpMDwDDrzh3LbN5mbW+VaL8ZNb9cEuWGroplq8nVTyTU10MacwipNt7tcTdIzX X+apQEeBnQ7Bm4fBEzzcIvgibS+2BsZeueTmx+L8Hlzq7oSbgsZvbpmFUwCegfI159KM O7K1GK6hO9jPI8NOq4KBJ0KLfOBDF+JwyUczep8q1sygLmdAzSKCIlB92ZT67SMCerI8 OnFKkEoUIWuAyci3aD8cufxNbGMQSK2ucRbbL4UuRP77wRconzvRmq7DDtXkL+D0OeVB TAtBU9edofhK0naqGrKx1HV3wZATbDjJb3EDsRDuwOpgnaVs6FPca3JPG+/216TtfMIM a2Jw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=nPCuxiBU; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d10-20020a056a00198a00b006901f2f2577si3835606pfl.380.2023.09.15.13.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:07:10 -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=@amd.com header.s=selector1 header.b=nPCuxiBU; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 7E568837343B; Fri, 15 Sep 2023 12:00:20 -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 S236598AbjIOS7p (ORCPT + 30 others); Fri, 15 Sep 2023 14:59:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236652AbjIOS7R (ORCPT ); Fri, 15 Sep 2023 14:59:17 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2074.outbound.protection.outlook.com [40.107.102.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E89E1AF; Fri, 15 Sep 2023 11:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jpVoEKcxpwiuzKcMbtoMhAq/5sEcEBrwLLR0DkD7jGZk9KXyXMimdIbfLQ7EfznxkG0ilyUE9E/P0AjJ2xrj0kXMQOTnWa1Zjqct3S+xBq/Ajlc7ETfpwyKrf5sE2uRrYiWlEMlDRDfGw6AycXYIuxjH2IlDd3GoURV28XrF3rrWB2gJ5vkvNP5Y2fA3DvCaGnT32ypfxeo/RLNV5JGo4hX6GItzjvM+wsrDz9rEADN3RP1Cf3OUbo7V5CvrEfab08TulpVqXI4wmnlPZIGDap4yj0C/K/mydpQUOYqfO0LNXB7+svVjnvgAVAJ2nJ76QhCLZlTgU1zc5rtkY7gvSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nM6ZWZakbe+IBI1miklYz4jGu8Gbpl9xf2mO7nvcpH0=; b=ZDjbu/qySScK8yNrOTl14z4mCJGXNsA0lzfyihH0t159xdOXo/qWYaldzZgwPk8Kn9e+CA9ziFOwNFgC1geXI4Pf64F2aF9bjzbkUAozv5DjEka+MA/g6mbPOZg83J8uR4mLM8cU1eY6ZMkqJSXiFG+/0b2w1jx9PEAyTLY2qKi7mIEMIbd3cMDrqRjembkezxIVRaGpnxPHHpslyPXVOlyP79o0iHcOangcT5ioMtjaKjBQQs6x7VWZGTJiIoFNjSz8xA4NQSG8c9Up09fqFlHofjVKq7gMWDl0cFglBmYUKxNzclWqxjVaBTPoTECS/Y6pQDfgbm7gND4yCgRMAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nM6ZWZakbe+IBI1miklYz4jGu8Gbpl9xf2mO7nvcpH0=; b=nPCuxiBUdewwJAVkIR6R4+vmHvgrbZaBbjsETge6qg2vOeG1khS5MQDBUjN8fdf1w7ChFiFX9p1kf4uMVUiyVsl5MppbyMGXubYdBmvcYWDRoY/p0nCywNxl2qO+/xegjUvdEvSbsENQCkMQ2vn79bFvxrNEVrdXZYXzMRWMO6w= Received: from BL1PR13CA0178.namprd13.prod.outlook.com (2603:10b6:208:2bd::33) by BN9PR12MB5381.namprd12.prod.outlook.com (2603:10b6:408:102::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21; Fri, 15 Sep 2023 18:59:09 +0000 Received: from BL02EPF0001A0F9.namprd03.prod.outlook.com (2603:10b6:208:2bd:cafe::ac) by BL1PR13CA0178.outlook.office365.com (2603:10b6:208:2bd::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21 via Frontend Transport; Fri, 15 Sep 2023 18:59:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A0F9.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.19 via Frontend Transport; Fri, 15 Sep 2023 18:59:09 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 15 Sep 2023 13:59:09 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 15 Sep 2023 13:59:08 -0500 From: Lizhi Hou To: , , , , CC: Lizhi Hou , , Subject: [PATCH 2/2] PCI: of_property: Fix uninitialized variable when of_irq_parse_raw() failed Date: Fri, 15 Sep 2023 11:08:07 -0700 Message-ID: <1694801287-17217-2-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1694801287-17217-1-git-send-email-lizhi.hou@amd.com> References: <1694801287-17217-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0F9:EE_|BN9PR12MB5381:EE_ X-MS-Office365-Filtering-Correlation-Id: e65c5161-bd34-4747-0543-08dbb61dd812 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nNvggFL68bNTYVWHSPdxZdudNoxKDmhsjIWOkQCIGhD7ZaS3EEPO+L4A46J+e47l+jO1epGwgKwZ9qDxUG2KBJoMBTbk6VFUOxoSW955SKaeyxYuiADbXEy+d9zTdlT5MWcPsKFu27u3yZG/A4BMv4rsYOnmoTG8j4I6BtPvdX8qCZXvEyUkqxFdyPdKcGXBJnlnRxyx+IJsck3QGG1L2bF3Hi0WJiTamjBe62ONg08N+0qKbMEmmrnP5YLhhrv40jwpKxTgao3r39XIz6JFU7yYnBEbwu+jGvK+aVEfH2r2t0pQ7ZD0qLVnx3jALRiITR6nNkneX42aMKgrm1LSacOe/KiI8n5HJrJHgmszy0mgVd4wNwHZdd1j+RqwVdGbtiuyOA6dUdZFoDmtDdl1jA5cJhlSzTEPBh5STr22KmpcLxq3+IlcEhAOFAqURwqJk0WJvg66nlyazv7CZtyxafVEOVPawUrW3yGlefo1t51WZxT99sSfm9lEVd8v7Q7tegQsl23G231KQcJjkAZWBt/rPJYu1nvTN4LVJs2yay/XSV3D2IBX+M7tVNejK38OOQn6OvYidW3a5H1xy295oewCWBbd++Q7OQIBzWYeQLe81lxxPe5k26SoyvtPWGwpAmlF2ArSw540rAUmTG947xWPm1Wa0tM0QhbM16ooh4AnagboOMmMp06XIytMGlDJKtW5XsrONQtsl27nWfHJlFtLo20f+svrxJu8e7hOWgw02M/FuWTrcWdvJmRV66acySdK/DJ2+Kd6XsKLOuD5Ng== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(39860400002)(346002)(376002)(136003)(82310400011)(451199024)(1800799009)(186009)(36840700001)(40470700004)(46966006)(336012)(40480700001)(2906002)(426003)(83380400001)(2616005)(478600001)(966005)(26005)(86362001)(40460700003)(356005)(36860700001)(70206006)(36756003)(70586007)(82740400003)(81166007)(47076005)(5660300002)(54906003)(316002)(41300700001)(110136005)(44832011)(4326008)(8676002)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 18:59:09.8111 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e65c5161-bd34-4747-0543-08dbb61dd812 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0F9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5381 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no 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 12:00:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777135445437076875 X-GMAIL-MSGID: 1777135445437076875 In function of_pci_prop_intr_map(), addr_sz[i] will be uninitialized if of_irq_parse_raw() returns failure. Add addr_sz array initialization. And when parsing irq failed, skip generating interrupt-map pair for the pin. Fixes: 407d1a51921e ("PCI: Create device tree node for bridge") Reported-by: Jonathan Cameron Closes: https://lore.kernel.org/all/20230911154856.000076c3@Huawei.com/ Signed-off-by: Lizhi Hou Reviewed-by: Herve Codina --- drivers/pci/of_property.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c index 710ec35ba4a1..c2c7334152bc 100644 --- a/drivers/pci/of_property.c +++ b/drivers/pci/of_property.c @@ -186,8 +186,8 @@ static int of_pci_prop_interrupts(struct pci_dev *pdev, static int of_pci_prop_intr_map(struct pci_dev *pdev, struct of_changeset *ocs, struct device_node *np) { + u32 i, addr_sz[OF_PCI_MAX_INT_PIN] = { 0 }, map_sz = 0; struct of_phandle_args out_irq[OF_PCI_MAX_INT_PIN]; - u32 i, addr_sz[OF_PCI_MAX_INT_PIN], map_sz = 0; __be32 laddr[OF_PCI_ADDRESS_CELLS] = { 0 }; u32 int_map_mask[] = { 0xffff00, 0, 0, 7 }; struct device_node *pnode; @@ -213,33 +213,44 @@ static int of_pci_prop_intr_map(struct pci_dev *pdev, struct of_changeset *ocs, out_irq[i].args[0] = pin; ret = of_irq_parse_raw(laddr, &out_irq[i]); if (ret) { - pci_err(pdev, "parse irq %d failed, ret %d", pin, ret); + out_irq[i].np = NULL; + pci_dbg(pdev, "parse irq %d failed, ret %d", pin, ret); continue; } - ret = of_property_read_u32(out_irq[i].np, "#address-cells", - &addr_sz[i]); - if (ret) - addr_sz[i] = 0; + of_property_read_u32(out_irq[i].np, "#address-cells", + &addr_sz[i]); } list_for_each_entry(child, &pdev->subordinate->devices, bus_list) { for (pin = 1; pin <= OF_PCI_MAX_INT_PIN; pin++) { i = pci_swizzle_interrupt_pin(child, pin) - 1; + if (!out_irq[i].np) + continue; map_sz += 5 + addr_sz[i] + out_irq[i].args_count; } } + /* + * Parsing interrupt failed for all pins. In this case, it does not + * need to generate interrupt-map property. + */ + if (!map_sz) + return 0; + int_map = kcalloc(map_sz, sizeof(u32), GFP_KERNEL); mapp = int_map; list_for_each_entry(child, &pdev->subordinate->devices, bus_list) { for (pin = 1; pin <= OF_PCI_MAX_INT_PIN; pin++) { + i = pci_swizzle_interrupt_pin(child, pin) - 1; + if (!out_irq[i].np) + continue; + *mapp = (child->bus->number << 16) | (child->devfn << 8); mapp += OF_PCI_ADDRESS_CELLS; *mapp = pin; mapp++; - i = pci_swizzle_interrupt_pin(child, pin) - 1; *mapp = out_irq[i].np->phandle; mapp++; if (addr_sz[i]) {