Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp273407rwe; Wed, 24 Aug 2022 00:10:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Nfw2dDBpcHxX7rkI+1xuOPYWxxVm8Xn7qVCrEJBhOS3+XRqwBn0mUDmp9uSF1gGdHBZa9 X-Received: by 2002:a17:907:970b:b0:73d:5a29:959 with SMTP id jg11-20020a170907970b00b0073d5a290959mr2106257ejc.183.1661325009505; Wed, 24 Aug 2022 00:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661325009; cv=none; d=google.com; s=arc-20160816; b=Tjw+NVP8u87tx83mvhcy0dcBoszMIth5cmMDyRPz+LKR/iJZUj7qrNUZ5lb5BlsH74 4gtJKkGe1P8agARjmtxqo5vWcPRy7pruhzFtVaF0xolxEHCXZgtF0v1UFP9SWunHIvCB srLdUDhgEHtdo3n226QQ5vimIDjQ4rOE1y3SyOxiGgHYW1ri2rha5oG4rYpy32XMfQuz lM81e3gjSRFIj/saZCB9oEFjibGWOHqk8mJufiHHcynLaZU1uLWKXAR/xIfXxgTUg5Dm yDV/s12dMpg82m49Ollr5/Q3bi/es2/3qGGQ/1uMyzuqifEGIjEje//VAFkcQ+behdaT UW3Q== ARC-Message-Signature: i=1; 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=p10kD+gTdAN7sPfTgPFIBsiL3UbFKgINASKfJF4tRJE=; b=kfR1EqVg79WVS0B0rpHOr1pkCmIIC6Dhy4PMGKvog76AVC3cPIBlHphL9T26dvy3EI YeHLoN0GrOlVp4M2R2C2s+6NbLhJ5YmWTsSeCzXVT0d5pbB48KbqBsXhCv/thOfsAGtp NSf+nBktdirybeJRT7zUwfoiXS4RwetQj3OvPYSfTxecw+7HWW8EmOMU+ov15cu+a4Uy km0NezgcUVUWro2hU2HDxCKFINdRC0uZtOgfddolPpNswFm+Xv2QMS8+6u5T6zKYJS58 nNE8qVlhjtbXfxzWQN7X7A0hk8tkSKyqkdOSqIXh9/1EvPUyVV7aWRX5pjTBciBZJbX4 6QWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=K6j1eQqh; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr17-20020a170907721100b0073d95653bccsi1453037ejc.641.2022.08.24.00.09.43; Wed, 24 Aug 2022 00:10:09 -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; dkim=pass header.i=@mediatek.com header.s=dk header.b=K6j1eQqh; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235225AbiHXGoV (ORCPT + 99 others); Wed, 24 Aug 2022 02:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235170AbiHXGoK (ORCPT ); Wed, 24 Aug 2022 02:44:10 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B14AC86040 for ; Tue, 23 Aug 2022 23:44:08 -0700 (PDT) X-UUID: 27af79c72dd84538a44b4029e6e6f38f-20220824 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=p10kD+gTdAN7sPfTgPFIBsiL3UbFKgINASKfJF4tRJE=; b=K6j1eQqh9J+BbgHB8I+yj5u5yc/5tHzOO/zRHxKDz2XPElOsFLo3f+z5zmv5TFF/Nf6GBD1mgBBk3cckv5baeE4IA9q33WXDdTnInCY8Els+oY7SZ/24nh5vzfWxSNIMzblZppMFGRZYtDyjeDVdMXwPMXaN/s8I9+0RmK/XLs4=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.10,REQID:460c21c2-0dc2-4ba7-91fe-bd2f53190d38,OB:0,L OB:0,IP:0,URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Releas e_Ham,ACTION:release,TS:-25 X-CID-META: VersionHash:84eae18,CLOUDID:ed772468-a9d9-4672-a3c8-12721739a220,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil ,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 27af79c72dd84538a44b4029e6e6f38f-20220824 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 807634051; Wed, 24 Aug 2022 14:44:01 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 24 Aug 2022 14:44:00 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 24 Aug 2022 14:43:59 +0800 From: Yong Wu To: Joerg Roedel , Matthias Brugger , Will Deacon CC: Robin Murphy , , , , , , "Yong Wu" , AngeloGioacchino Del Regno , , , , , , , , Guenter Roeck , "Dan Carpenter" Subject: [PATCH v4 4/6] iommu/mediatek: Validate number of phandles associated with "mediatek,larbs" Date: Wed, 24 Aug 2022 14:43:04 +0800 Message-ID: <20220824064306.21495-5-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220824064306.21495-1-yong.wu@mediatek.com> References: <20220824064306.21495-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,URIBL_BLOCKED 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 From: Guenter Roeck Fix the smatch warnings: drivers/iommu/mtk_iommu.c:878 mtk_iommu_mm_dts_parse() error: uninitialized symbol 'larbnode'. If someone abuse the dtsi node(Don't follow the definition of dt-binding), for example "mediatek,larbs" is provided as boolean property, "larb_nr" will be zero and cause abnormal. To fix this problem and improve the code safety, add some checking for the invalid input from dtsi, e.g. checking the larb_nr/larbid valid range, and avoid "mediatek,larb-id" property conflicts in the smi-larb nodes. Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Guenter Roeck Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index f63d4210043d..21195ac060f1 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1048,6 +1048,8 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m larb_nr = of_count_phandle_with_args(dev->of_node, "mediatek,larbs", NULL); if (larb_nr < 0) return larb_nr; + if (larb_nr == 0 || larb_nr > MTK_LARB_NR_MAX) + return -EINVAL; for (i = 0; i < larb_nr; i++) { u32 id; @@ -1066,6 +1068,11 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m ret = of_property_read_u32(larbnode, "mediatek,larb-id", &id); if (ret)/* The id is consecutive if there is no this property */ id = i; + if (id >= MTK_LARB_NR_MAX) { + of_node_put(larbnode); + ret = -EINVAL; + goto err_larbdev_put; + } plarbdev = of_find_device_by_node(larbnode); of_node_put(larbnode); @@ -1073,6 +1080,11 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m ret = -ENODEV; goto err_larbdev_put; } + if (data->larb_imu[id].dev) { + platform_device_put(plarbdev); + ret = -EEXIST; + goto err_larbdev_put; + } data->larb_imu[id].dev = &plarbdev->dev; if (!plarbdev->dev.driver) { -- 2.18.0