From patchwork Thu Sep 28 16:47:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 146339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3650806vqu; Thu, 28 Sep 2023 15:58:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGELn38MdGwK+xjO9VkkxGT03+EVZto7eYgS37DmGn3ywzZ42DsaAHCQSSIH77QuCmDPdxg X-Received: by 2002:a05:6a21:1a6:b0:159:e4ab:15ce with SMTP id le38-20020a056a2101a600b00159e4ab15cemr4255972pzb.15.1695941880283; Thu, 28 Sep 2023 15:58:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1695941880; cv=pass; d=google.com; s=arc-20160816; b=f8BJM3Oc6l5p9Lcg5IOVjemr8wJFdJ3VCScoySdfW8pNGUeOY/55unqJGAiT1FycOC gro7vuFXHW/u52F94knDiFsVNv6enmD5v6IhCMJ3ClzAVTXuIKl9/t8kKVbahx0MFNm0 AR6GTC6A2k3YvwaN0C0JLNGzLFQ+C0cbWUKg12EcK0M8xhDDXUt1GQUKyDp31HwBR9OH H0m5qgnD1UsKgHwSx+3+IYqYwtYF3jFNKp3sz/ygrmDmJju69mmZEGKW5L1TIkoyxJl7 DxiY3JDmto8tfJK0DkJb3Ha8AQ1M26Xyz3XRa8y8DXCgHsMoN5+FbNACXDna7Ttzv7f5 Do/w== 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=nnGoVz5eJxpJPMb186PhPfpjO4+zF+4bmmmljn1HHjw=; fh=stF5Iidn64dwErGQFq92GQ6LLbSjxfyHYvYqgW1K9oM=; b=Xqa/oLB2Kfuune3t3jKEH6Mg0CT0tQ9P0xoPbF3YhMkD8GV5/jfavU8nhNeuusXRfP 53ERJNXIDCyrax1MrKjGbd76k9RZr2S895/HnVzqy2GQ52VGTlcGm4Kcs1KlgAbEcStz S0goM9pD4xlSK/YuD8Z6G+CFfBZQAMXkjETJW/0nF4Wp/Y4v1NQsxMH0LHDZBTYBLKFY P0cd3K7o6ctYxMaQS/oq4/eeo9eXTrvwcsLXXZbN/gUwWp5MuOXY32HK7aYShd2B27Va mJQjmSqMmybcvDTSJKu/ec0J0fU4j8+6w+4JwaeU1Tp9bJaP6XLA33jipZSZ2AjODceE nn6A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=S6RJG1hz; 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.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id q132-20020a632a8a000000b00578d6cb1a16si19536270pgq.178.2023.09.28.15.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 15:58:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=S6RJG1hz; 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.33 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 lipwig.vger.email (Postfix) with ESMTP id 70FF882A1000; Thu, 28 Sep 2023 09:48:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbjI1QsI (ORCPT + 21 others); Thu, 28 Sep 2023 12:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbjI1QsG (ORCPT ); Thu, 28 Sep 2023 12:48:06 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2043.outbound.protection.outlook.com [40.107.95.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17337193; Thu, 28 Sep 2023 09:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G43OJ0orNOHw7cFe03xRnNz10/76U6SMKAwrovrtMK5PobTRYCttc7A0JX7OvNGOCZa3uMantOlBXbgYJwCiZS5QnwVpsLzs1kxI3PbwBuvB7OpWfQ9MiSpsvFgnGWurzpXj1Tno9yI9z8eY8AJnIvlA/02y5L2PKx3zmzRbpiMH6QLQOilu2F4vE8ru1YNdVTUjYo8BaRKN+vRO622gM13HMGBpXc/0bwPrmToiVL3YxMjrIrL9DM/Fad+Z/kdvPelQbMTJ76bi4zcWdFJhA4QsY2D0vJRTzyYl+heVEv+pp9Lim9O9rJpVWNLOO3p88j6yIgJNMEeFxlngon+PvQ== 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=nnGoVz5eJxpJPMb186PhPfpjO4+zF+4bmmmljn1HHjw=; b=nZna2LwNJKHUnBvgtk0s6qeH68Inj1A6/KiewrXBIxgpKUwHP8SRNmyMDDPoLHItXXbqz2uLrJd9/cuWpaP3xdGNUTiR7+HLM4FO/vZ6zVgech6zzdmq5GNRvRY4jItx+8/chL+9EwzHDSi+hMpCzFiraddU21VvAA4YUMYLTeC6NK33moybM23Fp89Gj0zp6I5ftuBNQ6iiuHf+kJNwQcLamXJ1If5r4lhcBShtiGSS37qR1ePzAanhFk6KUQ1erxI99ZWp6IEj4TTbPxYbaJVt5HsdfXl82yLPxhdje1ru7FylYWlpgemZEcRa9VVr3+OGSQMhp7cL4zcE7YMKdA== 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=nnGoVz5eJxpJPMb186PhPfpjO4+zF+4bmmmljn1HHjw=; b=S6RJG1hzLn7gkW73Pf6o4B/FtRnnIzVELLDHG1cQW6i8aT4WbQXNLwNajuzqJeZ3z27/54Nqp4CrkYg35RzLaYB2UeuXBWXZMifDlVUS/5AmvPDSIEQOau6ZBtJpaPSTFtWs3J9pqFvKzKXW8yTPmA7SOHs174nYvmaD6vDkCfo= Received: from BL1PR13CA0207.namprd13.prod.outlook.com (2603:10b6:208:2be::32) by MN2PR12MB4126.namprd12.prod.outlook.com (2603:10b6:208:199::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.33; Thu, 28 Sep 2023 16:48:01 +0000 Received: from BL02EPF0001A108.namprd05.prod.outlook.com (2603:10b6:208:2be:cafe::2c) by BL1PR13CA0207.outlook.office365.com (2603:10b6:208:2be::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.12 via Frontend Transport; Thu, 28 Sep 2023 16:48:01 +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 BL02EPF0001A108.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Thu, 28 Sep 2023 16:48:01 +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; Thu, 28 Sep 2023 11:48:01 -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; Thu, 28 Sep 2023 11:48:00 -0500 From: Lizhi Hou To: , , , , CC: Lizhi Hou , , Subject: [PATCH v1 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed Date: Thu, 28 Sep 2023 09:47:10 -0700 Message-ID: <1695919631-7661-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: BL02EPF0001A108:EE_|MN2PR12MB4126:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c5bf754-4e81-427d-ade8-08dbc042adcf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ko/CuEdl1owr1FSb0xvCjzJB3VJTarVZSKlUR1yJ8wNgVhcSnW69nHCNVot+T6lm5G06qNTEWmPZV4XpMxnchS1+ffnvOKuRxLbHWi2mSI4uKFnnf/epf0Sx5JcZgykrEyaboxW5+MByBdrR6yXt5ETlnv97FY3b8tjRb1XWeABmd/LkZcwTjAUi0kDtqkHzsDbKK/thJecVyduZ0DTvamK2Usx8u98DM+ec/eZ6m06Ak6BZFth9i/WSYQLND3UMEqcU6SedRrDhNksInQR5N45C4DQOSf2q+5VQSFENNg+EkdRhHKlznTgwagPK6V/YSXva/hwyNghCOtzyRfikpx95lIlis5QFojgh/zTHYMwatJAiCQRvEZS11tbhb4xvFv4xvrGbVN7X0yU3LnY8ITQqI8a9EksXJ87B+Kseznzqu/TQ9DaaThYLOCbhLXI3jn/YaejGTXqgXuXf95aTT7/ow0XFeRt3ti9nkgmDhhvcc7sU9GwTKdwUo8MJ2xg6RJSMgKmKsnM2PAKSwoTiWIgMwC0vnyP7IpxrcsrApQKjLTIkEdOqKrGBFkUdjA39imtdsOz6UmhJXMrtayYed4cZsZPX9keEtHrb2lv8IVfnucrH5aJxWOlKm0960z24Ni6Xe1dcXuKcK3mL9I0GNAC8uf00A7kHzJiRk4pQU7Og/o9VOGkSjY6MJqMs2YIyBfkJU5RtBpL4gCxvLAFGyoVlFZ4gbedKlHz1tJJhtgQTFwcJs21XE5t7UY+u2E8LN2WG2Xfym7tMwdV014qREw== 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)(136003)(396003)(346002)(39860400002)(376002)(230922051799003)(64100799003)(82310400011)(186009)(451199024)(1800799009)(46966006)(40470700004)(36840700001)(336012)(966005)(478600001)(6666004)(54906003)(426003)(83380400001)(2616005)(26005)(110136005)(70586007)(41300700001)(8936002)(44832011)(316002)(4326008)(2906002)(8676002)(5660300002)(70206006)(36860700001)(36756003)(86362001)(47076005)(81166007)(82740400003)(356005)(40480700001)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 16:48:01.9031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c5bf754-4e81-427d-ade8-08dbc042adcf 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: BL02EPF0001A108.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4126 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 28 Sep 2023 09:48:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778323952959807825 X-GMAIL-MSGID: 1778323952959807825 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..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 From patchwork Thu Sep 28 16:47:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 146391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3719871vqu; Thu, 28 Sep 2023 18:46:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgVu22Tt0YmdFzFPstquGYnzNoBes7CJl1ccsIsPPz/3zVkbQZOeqHp07dvagbtoNObga9 X-Received: by 2002:a05:6a20:7f89:b0:14c:d5d8:9fed with SMTP id d9-20020a056a207f8900b0014cd5d89fedmr3545227pzj.54.1695951965146; Thu, 28 Sep 2023 18:46:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1695951965; cv=pass; d=google.com; s=arc-20160816; b=bxHzbTpLksFFEhKXrj2XwaY0ioe/iOz9LY4b46Ti0TBZCn1qzuqheBzVgL0Te1SyJG oAhAB86GmrIoomiA4KfCTkeM+73vNSMIcJN8KgOdbjqzBqajC3Q/NFA1GmJwVHO7CrEK t4+zZATL+LzxU9N13dlCUI4QJmm+Wv4sDuTQdjCzEITowtC99/UyLMRWJI1hL0Hfg56X DBFU2oZ2gGI86FskrPTbygK3IgWdwc5+tVAB0GQWS78Yqj1Y4Vz2JJ5tY5WqfuX3FSAx tKthmwtGbWwN4lJlr7to+pAgvuydTAZhyUp+BbyjBa9uT/I+Dt1x7fHn3dpppfqRR2o5 5LsQ== 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=MTKcwFawS1LXaUnHCj41gj17QWmGa5EYrJPB+u+eq7s=; fh=stF5Iidn64dwErGQFq92GQ6LLbSjxfyHYvYqgW1K9oM=; b=Y1drxl+fTPRvkqRsKxFXHR2eWzXbhVh1ZS0FjoMm7PaCcotKpdRzdSP42ttu95KFUt z3b/Y+cwDLCPPnIDI/UEo7HETR4AtduOnwvEqtpzKSljT2MD0E/JmFMcvjYjh9q+rJeJ mS/576/gsqAPCv7h9UtjK2Gp5j7ZKOCcsyPd+97KjDWkXtCNUAujSpHYqVP3ppzdyNs7 Ggmw4KDZb4Tnb9xfQzwLSQ+dxJhicmbL9Nwt23qQdx2uTvHeKuzuRxcNFkU5ag+eL50Q VmXXrA/+At7rBUQVJJBfqy3NY8Ywky5ZMxSx1Doq+wreHVtF7RzrHD0CC2ME1lcZVdXB LnUQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=QAF7VLVC; 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.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id b12-20020a170902d50c00b001c724cd1128si7242047plg.276.2023.09.28.18.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 18:46:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=QAF7VLVC; 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.31 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 morse.vger.email (Postfix) with ESMTP id 14443801D919; Thu, 28 Sep 2023 09:48:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbjI1QsK (ORCPT + 21 others); Thu, 28 Sep 2023 12:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbjI1QsG (ORCPT ); Thu, 28 Sep 2023 12:48:06 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2045.outbound.protection.outlook.com [40.107.100.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FCFC1AC; Thu, 28 Sep 2023 09:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NxDNUnTj++l42s8Dq9cPDZVu0+5SPXtr3VsVXeHuAzdeI1FcNKjvJCTTfwTMbHTAi3D2rBxcY6+dUqMhTII1m7wVx8L0nwi8MyAKSEzt0PQQ4o7gW41SQcIDZRRCNXEd0T1BBAthDiVxcnM2bnxcDF6FOZ/e73vzSnYKM+f/ODZ6loxLMvK//+lQmNF3vhci+RfeNvj1Y8EiEKxRrqsD0NxYxND06B3o/tx/gjxbfXIBtMwpjEtFmIEWQHN4tgKttNHgkHA749EFKymP0syjqqdzuw+okP5ed95XaEo5zs/qaBVBHH8VTtWuFfnXJZ0VBVLLJ/NF5rNYF8iE1RNj7g== 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=d6xKmQ5CjHu+/j3/DyDH++eOq7KA9/zZvDGF/AlskWVhcKAPVaz2UeUaeDbdC30Svv2aSg8Egd/vjsdBD18JlNTeUcwK3Yj4UwyzoMfbEhWgAnpSaDsseEKX46s2Kh/6fmVUTwBav6+LhUw0uaqLjz+wO96TG4rEutbAgTo8d+quIk1bnelMBGA9msweX3EHSM1QZMF4uH3iRagcYbQRuCy37ZocBdbBB9KC8mXPEoHr7AB/L+tCh2i2X4x+IcvyRS4zoqtIVuQE/lo+2VFdLkJua00IXgv/K6eXdbXRs/eIRiieJYs6jIB8aM0P365Nmu4uxRChNa7OQLpFxrEUQQ== 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=QAF7VLVC9eBaTll1PDaIa9Z67KY1opkGH6CFPyn+lC4B4jjg4yGCgG7U4Islfy0epTQgib3zN3g+10e8HpY7nZKMBsqE8kw8OXSmi9lua3P5ug6h4HyfrUe3jD4WTeEgEvqHJVS7xhje2+C4a4cqJPym/SWNcwDJCGPQ+FnSPC4= Received: from BLAPR03CA0120.namprd03.prod.outlook.com (2603:10b6:208:32a::35) by PH7PR12MB8777.namprd12.prod.outlook.com (2603:10b6:510:26b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Thu, 28 Sep 2023 16:48:03 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:208:32a:cafe::7b) by BLAPR03CA0120.outlook.office365.com (2603:10b6:208:32a::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25 via Frontend Transport; Thu, 28 Sep 2023 16:48:02 +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 BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Thu, 28 Sep 2023 16:48:02 +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; Thu, 28 Sep 2023 11:48:02 -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; Thu, 28 Sep 2023 11:48:01 -0500 From: Lizhi Hou To: , , , , CC: Lizhi Hou , , Subject: [PATCH v1 2/2] PCI: of_property: Fix uninitialized variable when of_irq_parse_raw() failed Date: Thu, 28 Sep 2023 09:47:11 -0700 Message-ID: <1695919631-7661-2-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1695919631-7661-1-git-send-email-lizhi.hou@amd.com> References: <1695919631-7661-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A101:EE_|PH7PR12MB8777:EE_ X-MS-Office365-Filtering-Correlation-Id: d13cbf3b-479f-4803-6b80-08dbc042ae57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XQNnr3KKhg6DkLvseXbDlFOjI2I0+kDe2nYJ4JGkiPNsOLmLqq5RFBPnrqgKR4prBLhrq5F0gYBiDXw4gBBCNJwvxD6yIlNyi8OQ0IGFF84PqD1/97egA0VCL/09VrIPwfOBNwGKd4EaIS2vMjJLL+8GObja5B9y7GXgRuOwoM8tdu2c3h4hpLmtrML+ypvLuBUK1y9trA/TBBlDh+sAZUVnOxWFDgQU9teF0opKNJ6nJ61taNrfyZLQW82r04xQvR8CzbK0xfWUtUKR787X9VX+V09UBWnAmXMBtsD3EhP/E07xGD1FjkYY57Kcn70cfuw2OFVOWemxi3H1iGu+0EUY0yxPpUPxoLn0mML0rYOLCCFdvnLgPfU2BKKee1fb0bJJMyTqBN+gm6lN1tsP5ZbTVx/tfR1e/UBYE0uIam672d3aFwJ2wBa5ZJvFySrPRHyELlB0GZRmnPMqsnMnkXMia/JBlgWfYDPUPaFY+S82PEWbP2i9am2Gvd5VtfCS9J40axA2niEghIDuYEh0nN4IB8PQIXnXaxMALFqFC0g02v8hZnM4z6Q/tehEqWnlPB7UByHVAwjMET+hvQhMwI8+wNgWYzIPl+Tj/AG6SnlBsR69j/sponD5NSTyL3mjNMX6jWUSGUPjIgZ36XbNmg9lf95eH6DJLcI812FxY/7KUYooUqWZSiYfDBWQW+mEWg2QIaOFXBNh8oaH085mf0mQenhK6tKuK/rLHTPQ7HcEqWq9vtTksGSEbn3ijRE0+Nvysf4WWlOa6cqDagN7UA== 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)(136003)(39860400002)(376002)(346002)(396003)(230922051799003)(82310400011)(1800799009)(64100799003)(186009)(451199024)(36840700001)(46966006)(40470700004)(40480700001)(6666004)(81166007)(70586007)(2906002)(356005)(83380400001)(36860700001)(82740400003)(70206006)(110136005)(966005)(26005)(5660300002)(336012)(41300700001)(4326008)(44832011)(47076005)(478600001)(8676002)(54906003)(426003)(8936002)(2616005)(316002)(36756003)(86362001)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 16:48:02.7927 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d13cbf3b-479f-4803-6b80-08dbc042ae57 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: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8777 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 09:48:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778334527657693476 X-GMAIL-MSGID: 1778334527657693476 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]) {