Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2279197rwb; Mon, 19 Sep 2022 02:38:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7b/Kg5wYwRyu1MTGb5t/LruFy71zZQ+kk4XAwq+AH8EzNkUQmu5fyR0ayk/BMnC0LsTqtA X-Received: by 2002:a05:6402:11d1:b0:451:964:3af3 with SMTP id j17-20020a05640211d100b0045109643af3mr15148133edw.225.1663580280250; Mon, 19 Sep 2022 02:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663580280; cv=none; d=google.com; s=arc-20160816; b=WWxsSpEaT1eiDN3TEQNLPf/V+HRspsL2L91HLKQjS4ovG+ahnd/KmJdYU8mYPgKdzC gVYlIBg/6lnF8KNhUxeGoBT1O8w2ni1XTlug6Au3rLQ4MSi0znHNyH6C1QKkfCcfk+Bl vDqZmhpwhmLE+wQy4qnkPbhq21BzjdIm+G2HByVpu0qMFDyZfFCuI1U4xeR1FEi/SPUy t1o5FFpD5Ebll5aGbmO7+KtB6YvERgJ0N7f9zLf0eX87Nk40Qw0xmNBFUC8f8kw+Womj BcqL0AC/4sBEQF50A/5UZ3yd0goUpL+HbG4WncHlLeNJa3x2/0ASiOBM3FknruFTqsVS SsrA== 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=900vz5qr65ndkLF0SOk5KwGKEz4Cus5BCuRbNd9HW7I=; b=PSK2hBCQXmhf+fKObw0yXWcF3P/Dp7Rb/jgMDibYHQjf1ZfXcPTeHC1zI+fl5EkkAL CUk5Rr0Z1uUih+puC+JI6BWJMwTsDRB9eozi3z1yJB3sFwpZzbiSDvv7wAVb5yeNqfro kwogJSPQ1pUy1o1/mUwDBm3rvj0mDCZsHVJz0nFWYLmssxE+nfYAZmZcq66PccCgDG5v cnH6RS+14Qd5IEsMxKsgrvB9Zrw45JCvCicjpcO+faFyOK4O1+435BV/xqoPePG3L/Uw R5fUKb8WeOJS7sbmSldsNh9ukGStO7XzFusKguDdat7ey3hm6XBi00k9nv9RBB0vY0Vg MRDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=qN6TRa7H; 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 b11-20020a170906660b00b00773e2e6f605si21790546ejp.930.2022.09.19.02.37.34; Mon, 19 Sep 2022 02:38:00 -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=qN6TRa7H; 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 S229808AbiISJZH (ORCPT + 99 others); Mon, 19 Sep 2022 05:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbiISJYp (ORCPT ); Mon, 19 Sep 2022 05:24:45 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12004BC83 for ; Mon, 19 Sep 2022 02:24:42 -0700 (PDT) X-UUID: 2c1d1d5342ac46a6b10972e7632fa75c-20220919 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=900vz5qr65ndkLF0SOk5KwGKEz4Cus5BCuRbNd9HW7I=; b=qN6TRa7HmbB7Xvkjc5gYvUMe/PkF04BS0+bGYQ302Qjv02vHMb8ZN3YiSExf2OnJ5Ok/CZeDwZBp/gEOXoHBvNlzMcIgO+57IU5DKddQT3+GCoR4BZpX/jueDfmZiqTDfQgWSJXZDMWEVS1IbmMRAJmhQg3spn5re1yD7yNq2NA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:cc54cbcb-6d63-47ef-abc0-b4b2b63d74b4,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:3acee2f6-6e85-48d9-afd8-0504bbfe04cb,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: 2c1d1d5342ac46a6b10972e7632fa75c-20220919 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1354522134; Mon, 19 Sep 2022 17:24:39 +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; Mon, 19 Sep 2022 17:24:37 +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; Mon, 19 Sep 2022 17:24:36 +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 v5 3/6] iommu/mediatek: Add error path for loop of mm_dts_parse Date: Mon, 19 Sep 2022 17:24:02 +0800 Message-ID: <20220919092405.8256-4-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220919092405.8256-1-yong.wu@mediatek.com> References: <20220919092405.8256-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,UNPARSEABLE_RELAY 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 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 0..i 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 = &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 TYPE") Signed-off-by: Yong Wu --- 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; larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i); - if (!larbnode) - return -EINVAL; + if (!larbnode) { + ret = -EINVAL; + goto err_larbdev_put; + } if (!of_device_is_available(larbnode)) { of_node_put(larbnode); @@ -1067,14 +1069,16 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m plarbdev = of_find_device_by_node(larbnode); of_node_put(larbnode); - if (!plarbdev) - return -ENODEV; + if (!plarbdev) { + ret = -ENODEV; + goto err_larbdev_put; + } + data->larb_imu[id].dev = &plarbdev->dev; if (!plarbdev->dev.driver) { - platform_device_put(plarbdev); - return -EPROBE_DEFER; + ret = -EPROBE_DEFER; + goto err_larbdev_put; } - data->larb_imu[id].dev = &plarbdev->dev; 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 = MTK_LARB_NR_MAX - 1; i >= 0; i++) { + if (!data->larb_imu[i].dev) + continue; + put_device(data->larb_imu[i].dev); + } + return ret; } static int mtk_iommu_probe(struct platform_device *pdev) -- 2.18.0