From patchwork Fri May 5 09:06:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 90376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp256246vqo; Fri, 5 May 2023 02:10:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Fgn+sY4XGUoPNCrMarjfYmvItZ/4euxEowUrbMTCR5caTx/KrCCiTkYnytleZLKINdtuD X-Received: by 2002:a05:6a00:23c3:b0:643:64fb:3b6a with SMTP id g3-20020a056a0023c300b0064364fb3b6amr1540251pfc.13.1683277817919; Fri, 05 May 2023 02:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683277817; cv=none; d=google.com; s=arc-20160816; b=f37DgVrN5UqThIuYfJ4O/A370bt1JzOUT6AL3XTGIRWIL+1nAzWdNzpPolLoHE7SLm ZyqKn+vBaWUPt9xvb7s8SH+EDy/e9dYKlHOABh8jpLhwxxcZwtoMoVnflLP3Y6JwoHIe l2VBO7cjJp9HUkjxclaI47Y7gFJ+GmU2Uq0iNtsxuTko525Ws/wrZOqY+BF1YJ1mpoGj DWXQzXgW3LiK7vKPp4GHK010pr5XAI5ytPbfQ6ID5u5GDvBAGYBmdC8iJS4b8mCYUoYg /7LhCYC0fb4UhothjJwkJIdXqUuV0F7fDjae5ONaoUPFR7+Ow5cKodZ8htJgTxumzYTa 6onQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020aa78ece000000b0063b8a929ed4si1604778pfr.145.2023.05.05.02.10.03; Fri, 05 May 2023 02:10:17 -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 S231359AbjEEIuJ (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765044721433493902?= X-GMAIL-MSGID: =?utf-8?q?1765044721433493902?= 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