From patchwork Fri Sep 29 17:10:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 146788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp56446vqb; Fri, 29 Sep 2023 14:45:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTacXh15VSYiWdlqmxZS+cLWU+jy+3FXK6rv9Od1UXPCF1qbT4GMM3+lrMvFkL7TpvjEOb X-Received: by 2002:a05:6a20:1604:b0:14c:d494:77c5 with SMTP id l4-20020a056a20160400b0014cd49477c5mr6234882pzj.13.1696023905413; Fri, 29 Sep 2023 14:45:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696023905; cv=pass; d=google.com; s=arc-20160816; b=KopDyXi7r8KHCk8ubtNzZxLt6jGTSJ++o/yyVrq+BN2Flua4WDcgaLB9NyyV81qlJp o1ADdYayYfUvBVNvyqGqYiWOduAQuJ6xd+oa2hVe6E/KIyNlwiXJ0AIxXYYybVTgJl0i EtnVo/uMh4HYMi8QdVsQK59loPRy9SFtFnOjqRtBWXc0gZQIaTZXb2HNETMQ7tshrlFL R/C0pMRLAkqafyYUxsQhjwcaGELoUlZQQrk4t4Eh5BqiBQrtJckWjbWg+u0HgfJD7zNf hWXPu7Nn0ZXnLU5x+cZtQcJhyCV0wYIPYwzvPfbEJRErbyI/2fPgEv2WwxofMhKnaQ5r c0hQ== 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=MTKcwFawS1LXaUnHCj41gj17QWmGa5EYrJPB+u+eq7s=; fh=stF5Iidn64dwErGQFq92GQ6LLbSjxfyHYvYqgW1K9oM=; b=uHjaGgF2/Bm/0agqR5iI2GsvXF1EmN7DxrZKsqmePGwEM1IEnPWFDUk3oulSotZCVV firJqVG1aAxV4/NUkrOo4RTQg8x6k1YgQrBIVWj/14tTqs7hZXwUdTaEQq9C/4wosgN8 RKAaG4LlE9YZvbnVv0mTqND/aeg7z+R6IWRKf3YAtHh9UHwyxylagt/Iu3A6gNQsZuuM IinSwnyhX/AIKwQ0CYDEWuLn+IN6u/fwKEhQesrAge3Ut9IUZrKKKXN6svOdGiZVDqIy mkoR8XEXZ/QUCyH15vxIAJhQz6NUt2ndjfbVO49UR7nG5CUI4OUwR07QWh5ihBDZlNff oqmQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=cMMkOGbk; 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 p24-20020a637418000000b005740d553e73si10618686pgc.114.2023.09.29.14.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 14:45:05 -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=cMMkOGbk; 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 275AD8073281; Fri, 29 Sep 2023 10:11:07 -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 S233239AbjI2RK6 (ORCPT + 19 others); Fri, 29 Sep 2023 13:10:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232748AbjI2RK5 (ORCPT ); Fri, 29 Sep 2023 13:10:57 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2068.outbound.protection.outlook.com [40.107.95.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03E65193; Fri, 29 Sep 2023 10:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MgbcvSo0KA0DVOEGQsgWffmcrMfPHb+0BYgWn3v1R+lthj+3ssYYQk7Km6TXyIOQ4kDJHRa2eWSooKAcjeNY3ZUX1VKb0YaQ/cn2stYZ0SQBOSkc3KXIE72ZSWfinHe2m/nKC8GNFNXjnt3liqPZnRoxR5tOcLYnLbYvSojp5NH1ThUOuVah5txvfSIEvT8GZSIgMDmDu0rOrX5oWpnhVXJaOwsG5FogKiUF35S2olkB5YjN7qOdvNqMG6HfiAFkmymTankuXQi3sdK6N2qtkZpRSjzkMKKapwfr+XT/IzKrQPf+IEQozyQf47NbE5SrhlzbReCMYNAMTdO+/sX3mw== 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=MTKcwFawS1LXaUnHCj41gj17QWmGa5EYrJPB+u+eq7s=; b=V3O0/CeoZ9RQmm21ZGY3IMLUNJPebIIjYFASu8ww7m10VSEMJZLYZngwxOZ0MiSCn8hphVjyr64LWOmRGHHY+G8asy1liUFuetTZTU9r18IQBHJ0jHBD2wVGBn+dLlkWGRYYn3MfmQ6nr7UujxQ7XVVGWo0753VR5OC4XaO9ogpT9nz1laQgslkPEmpV7xE1DC6kRp6f+TebOF2jm5s4t9TbGLyyIjJ9+3V5L9eQqnI99v51mqN+WdKCsEjJYOfkt80dvxk7RcdTLlNmM2dT2LKWnlzmCGi/9AuQT/A16vD4MV+czwVKC/O06XBmj/Nex4QXd8zMLpVjq5e/1W3UqQ== 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=MTKcwFawS1LXaUnHCj41gj17QWmGa5EYrJPB+u+eq7s=; b=cMMkOGbkJxnP7alK1fXR7i6lB8ogIWPd8hxqYEfA5G4C2a7OxkapqdgQFaZTJz/+8VeMgJYWcDhgZX1dT8uSeKjkQGcNtvj4fX21/XvM9DK3VmFZZgpqlKJJGNFo+IaLM6o51FJXZfIfSRc2JKV/Ys6C3pL7oy2tc+Y3/5NmfzA= Received: from CH0PR13CA0043.namprd13.prod.outlook.com (2603:10b6:610:b2::18) by SA0PR12MB7091.namprd12.prod.outlook.com (2603:10b6:806:2d5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.21; Fri, 29 Sep 2023 17:10:52 +0000 Received: from DS2PEPF00003444.namprd04.prod.outlook.com (2603:10b6:610:b2:cafe::bb) by CH0PR13CA0043.outlook.office365.com (2603:10b6:610:b2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.15 via Frontend Transport; Fri, 29 Sep 2023 17:10:52 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003444.mail.protection.outlook.com (10.167.17.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Fri, 29 Sep 2023 17:10:52 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 29 Sep 2023 12:10:51 -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, 29 Sep 2023 12:10:50 -0500 From: Lizhi Hou To: , , , , CC: Lizhi Hou , , Subject: [PATCH v3] PCI: of_property: Fix uninitialized variable when of_irq_parse_raw() failed Date: Fri, 29 Sep 2023 10:10:48 -0700 Message-ID: <1696007448-42127-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: DS2PEPF00003444:EE_|SA0PR12MB7091:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dfd1ba6-20db-4f37-3a2e-08dbc10f0912 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0u7JXTonbkFfiSBTA6VbFlJY2jww201usveLscSduj7z50HF4UZOa2evaU977m4Y3aW64eMc3W5L3N2x/2zmsjrz6/zLmH1KDQLTeFlpfrnKL/PDUtFZcc6fa+dlM5NyVusVdWa3785SvJK6P6Eq+KZsxpypQ4BGtRk3e0n5nherffOvoZivRl61piB85ACiAioaYSkWT98fLCRaicuWGi+Ew6me38RGQxNqw/UMPs1nP4NZ7g3J44iSRPe5hOugWdFP48AgsiR+XOtphkykKbtWrs97//T0nnyzhWRChYkAGCIFGSrArnOu2PUNtmIy2uFR+e6gZRO1pV+whHiczUy4N4uTSBhncFpuVPu/gefSkeNvfLoyrdK+79eZbBo5lKNHiPWrwoxnX90CMNamS5FRNVwvAiSjkwCrzqwrTbV0gabMYr1KSEnQDw+NH+AI82RlK7cH/Dy9WtU+2ibpmL2Oz1c/NXoTjTCx4joSGXpxbm7b6JSwU+FBPjMqMdHzbcs50lIa5yOt7SbeuTewvfwpOcG79TISBJqXvTihGUA93yyselBQx1cq98hYeabs+4zP0LTETFs1N5sT/YOhhGrnWX82T8ZeiLTtrbPeYJ6Ht9Bfk+xg5otBEY485To6Ybm1VZNfiohEF9UyNL1J3HZkBdigEkEvkIZ5MsFjnqebm29CVTSw8vUMVD4mdyqFPVSIIN22krK8a2wy9w442zIsAFW65m1G6SM8aGwszGEuvXNVhVDTx1l38F2PaoNENN8uUdleK1DU7QmIzgmRhg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(376002)(396003)(136003)(39860400002)(230922051799003)(186009)(1800799009)(451199024)(82310400011)(64100799003)(36840700001)(46966006)(40470700004)(82740400003)(81166007)(356005)(86362001)(36756003)(40480700001)(26005)(40460700003)(70586007)(4326008)(8936002)(478600001)(5660300002)(316002)(426003)(966005)(41300700001)(8676002)(2906002)(36860700001)(83380400001)(336012)(110136005)(70206006)(47076005)(44832011)(54906003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2023 17:10:52.3135 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5dfd1ba6-20db-4f37-3a2e-08dbc10f0912 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003444.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7091 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, 29 Sep 2023 10:11:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778334527657693476 X-GMAIL-MSGID: 1778409962666120402 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/ Reviewed-by: Herve Codina Signed-off-by: Lizhi Hou --- 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]) {