From nobody Sat Sep 21 15:33:34 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 737EBECAAD8 for ; Tue, 20 Sep 2022 06:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbiITGjh (ORCPT ); Tue, 20 Sep 2022 02:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbiITGjM (ORCPT ); Tue, 20 Sep 2022 02:39:12 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82E62A4 for ; Mon, 19 Sep 2022 23:38:22 -0700 (PDT) X-UUID: 985f62a9756d4117b93e54d36626e91b-20220920 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=/IAZooj+7gssLY3QmmqdAbA97+rxDcmChgbbJ9ebuK8=; b=HFA3aHUnjLPnWwYLuVycGF2ZUxSA41OP+yd2owiRW4VYrD0PAGvJ9R6n1Ok4ORnjNaxkVf7cS2bFNdyy/pyhU5NAfB5WLf7gKiyI7EPk4yoS5BYQ8R6H6uUClp1t0upJt70Eb6i2xGaUhD/xPRJYZj8MtV8Ttk5joOL8b8utLF0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:3b1c0a81-653b-43d4-ba3e-a974026a6880,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:39a5ff1,CLOUDID:a34a6170-dafa-4a42-b716-cf2cd4845592,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 985f62a9756d4117b93e54d36626e91b-20220920 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2103044696; Tue, 20 Sep 2022 14:38:16 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 20 Sep 2022 14:38:15 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 20 Sep 2022 14:38:13 +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 v6 3/6] iommu/mediatek: Add error path for loop of mm_dts_parse Date: Tue, 20 Sep 2022 14:37:30 +0800 Message-ID: <20220920063733.21770-4-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220920063733.21770-1-yong.wu@mediatek.com> References: <20220920063733.21770-1-yong.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the i+1 larb is parsed fail, we should put_device for the i..0 larbs. There are two places need to comment: 1) The larbid may be not linear mapping, we should loop whole the array in the error path. 2) I move this line position: "data->larb_imu[id].dev =3D &plarbdev->dev;" before "if (!plarbdev->dev.driver)", That means set data->larb_imu[id].dev before the error path. then we don't need "platform_device_put(plarbdev)" again in probe_defer case. All depend on "put_device" of the error path in error cases. Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYP= E") Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 83b279432406..97b721006a47 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1053,8 +1053,10 @@ static int mtk_iommu_mm_dts_parse(struct device *dev= , struct component_match **m u32 id; =20 larbnode =3D of_parse_phandle(dev->of_node, "mediatek,larbs", i); - if (!larbnode) - return -EINVAL; + if (!larbnode) { + ret =3D -EINVAL; + goto err_larbdev_put; + } =20 if (!of_device_is_available(larbnode)) { of_node_put(larbnode); @@ -1067,14 +1069,16 @@ static int mtk_iommu_mm_dts_parse(struct device *de= v, struct component_match **m =20 plarbdev =3D of_find_device_by_node(larbnode); of_node_put(larbnode); - if (!plarbdev) - return -ENODEV; + if (!plarbdev) { + ret =3D -ENODEV; + goto err_larbdev_put; + } + data->larb_imu[id].dev =3D &plarbdev->dev; =20 if (!plarbdev->dev.driver) { - platform_device_put(plarbdev); - return -EPROBE_DEFER; + ret =3D -EPROBE_DEFER; + goto err_larbdev_put; } - data->larb_imu[id].dev =3D &plarbdev->dev; =20 component_match_add(dev, match, component_compare_dev, &plarbdev->dev); platform_device_put(plarbdev); @@ -1109,6 +1113,15 @@ static int mtk_iommu_mm_dts_parse(struct device *dev= , struct component_match **m return -EINVAL; } return 0; + +err_larbdev_put: + /* id may be not linear mapping, loop whole the array */ + for (i =3D MTK_LARB_NR_MAX - 1; i >=3D 0; i++) { + if (!data->larb_imu[i].dev) + continue; + put_device(data->larb_imu[i].dev); + } + return ret; } =20 static int mtk_iommu_probe(struct platform_device *pdev) --=20 2.18.0