Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp599004rwr; Fri, 5 May 2023 01:58:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Jfkphl3u9872Nx297l3DbZf1E4kV+1U1NUF0KsmaUdaUrqbovEGezfYrynsxso+/W3S07 X-Received: by 2002:a05:6a20:8e09:b0:e7:7844:903a with SMTP id y9-20020a056a208e0900b000e77844903amr913653pzj.53.1683277127877; Fri, 05 May 2023 01:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683277127; cv=none; d=google.com; s=arc-20160816; b=Ip4cXyvH9I49J0kWmsgkkUK/4cwQi8cg65f61ykgkNsDgm/Ny6g+sUxXK9xJUZWKjJ wQw0f1Ia4C0xCp58c00Qf5O5g/1HpWCCB9sMkjkFDpHOWr8fgCfVtWKjleP1O2iLQm+e NByxG4NL9/2oS4liJ9rXWcsrst7Cb1O8FRHaG6ZRAAxRFpJ5AyJEQTNTGYpcgeBsh7Xa mEArZh0vSFyV8go9Z25xvFqkmYRnn/qLHDY6cUzeCLcdexZa/Lrfmk7O1mBnqZNmm1oI RJZ5ZOHFf1dMC6sqw5oIRwM1ygAMEetlwKln0O9VAwBX4gs8beWKLrBiOovFANExdUq5 ICtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=2vs7SAAt8+l/PM9SiSItNVD9yStpL/xzMqOEGPVkbJY=; b=eXSdaFRPTnrp9SQGV+AfSOjUd1RAZ7uo9pJ8UdXmDxHV0PglFE9v59LH0rS7rj/SJ1 5PHsMZhq6ntOmCMXKqu+/OaYlvxEL93m+obYxh+9yYWRn2bBhFLK/0T8GIAJzvCBa9aw LrcN/zOPyKP/Oj+skysG6JWjDcSViZFmv6Zec+dmc2YjvxrhQhetgL0+Ow9hXgb5/V+H /Rv1kp6c798JuRoSDhwl7svyoBXeKKUvmERMZbMbRLmV+tguBMy75EMiWau5o/dVJ8eb onG/QAB2818z1UaYW0+1zpi3QSw4b6MNkofMUwBxQjo7tvXslQGtFS9JrpSJ9b7lW1D2 k29A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j136-20020a636e8e000000b00524d2e488f8si1542439pgc.809.2023.05.05.01.58.32; Fri, 05 May 2023 01:58:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231225AbjEEIuJ (ORCPT + 99 others); Fri, 5 May 2023 04:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjEEIuI (ORCPT ); Fri, 5 May 2023 04:50:08 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6524D18916 for ; Fri, 5 May 2023 01:50:06 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QCPVY6jCwzpW7r; Fri, 5 May 2023 16:48:53 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Fri, 5 May 2023 16:50:01 +0800 From: Kefeng Wang To: Marc Zyngier , Thomas Gleixner , Greg Kroah-Hartman CC: , , Kefeng Wang , Dan Carpenter Subject: [PATCH] irqchip/mbigen: unify the error handling in mbigen_of_create_domain() Date: Fri, 5 May 2023 17:06:54 +0800 Message-ID: <20230505090654.12793-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Dan Carpenter reported that commit fea087fc291b "irqchip/mbigen: move to use bus_get_dev_root()" leads to the following Smatch static checker warning: drivers/irqchip/irq-mbigen.c:258 mbigen_of_create_domain() error: potentially dereferencing uninitialized 'child'. It should not cause a problem on real hardware, but better to fix the warning, let's move the bus_get_dev_root() out of the loop, and unify the error handling to silence it. Cc: Dan Carpenter Signed-off-by: Kefeng Wang --- drivers/irqchip/irq-mbigen.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c index eada5e0e3eb9..5101a3fb11df 100644 --- a/drivers/irqchip/irq-mbigen.c +++ b/drivers/irqchip/irq-mbigen.c @@ -240,26 +240,27 @@ static int mbigen_of_create_domain(struct platform_device *pdev, struct irq_domain *domain; struct device_node *np; u32 num_pins; + int ret = 0; + + parent = bus_get_dev_root(&platform_bus_type); + if (!parent) + return -ENODEV; for_each_child_of_node(pdev->dev.of_node, np) { if (!of_property_read_bool(np, "interrupt-controller")) continue; - parent = bus_get_dev_root(&platform_bus_type); - if (parent) { - child = of_platform_device_create(np, NULL, parent); - put_device(parent); - if (!child) { - of_node_put(np); - return -ENOMEM; - } + child = of_platform_device_create(np, NULL, parent); + if (!child) { + ret = -ENOMEM; + break; } if (of_property_read_u32(child->dev.of_node, "num-pins", &num_pins) < 0) { dev_err(&pdev->dev, "No num-pins property\n"); - of_node_put(np); - return -EINVAL; + ret = -EINVAL; + break; } domain = platform_msi_create_device_domain(&child->dev, num_pins, @@ -267,12 +268,16 @@ static int mbigen_of_create_domain(struct platform_device *pdev, &mbigen_domain_ops, mgn_chip); if (!domain) { - of_node_put(np); - return -ENOMEM; + ret = -ENOMEM; + break; } } - return 0; + put_device(parent); + if (ret) + of_node_put(np); + + return ret; } #ifdef CONFIG_ACPI -- 2.35.3