From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5BB4BC43334 for ; Thu, 16 Jun 2022 09:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XVVw5hZJEJKBE1J3Kg5p+rRbl7dE64f2W3zO6x7Pr9s=; b=ODd7xCw12ajWAnzPjPIFcaz9Io s7E+Be/C0fLFlwYL+eYv30i2UyehHIIt+8avlzGKOWM00rxufCMn5DEav1Sa8hwlcqILcjzdVXWXm d/NsgX7vQ7UHqttmd07ye4uSGfcZxiwND+V0QA0iNT9gM2NIJ3q+oJZYMEFA1SDjybYD3jV9mdSqo 93l/MoZ88gsRlP+W0tlSmxfszRdRvhU39qpUb8DZHsnbjd7BWU/8f3oy2L/LInURZgxOrjvXVBASG A9wueHz1ROkJ/hiMjChUi2bzTYt5ChqBZWF2gjpUJ86raqPY4A3pzmFc8EeP2rj9JQzAKBYAMBVAe M1ZzF+Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1lMT-001WLV-Ab; Thu, 16 Jun 2022 09:00:21 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1lMG-001WGI-7d; Thu, 16 Jun 2022 09:00:09 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 509B512FC; Thu, 16 Jun 2022 02:00:02 -0700 (PDT) Received: from [10.57.82.209] (unknown [10.57.82.209]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E8203F7F5; Thu, 16 Jun 2022 01:59:59 -0700 (PDT) Message-ID: Date: Thu, 16 Jun 2022 09:59:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse Content-Language: en-GB To: Yong Wu , Joerg Roedel , Matthias Brugger , Will Deacon Cc: iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno , mingyuan.ma@mediatek.com, yf.wang@mediatek.com, libo.kang@mediatek.com, chengci.xu@mediatek.com, youlin.pei@mediatek.com, anan.sun@mediatek.com, xueqi.zhang@mediatek.com, Guenter Roeck , Dan Carpenter References: <20220616054203.11365-1-yong.wu@mediatek.com> <20220616054203.11365-3-yong.wu@mediatek.com> From: Robin Murphy In-Reply-To: <20220616054203.11365-3-yong.wu@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220616_020008_375228_E93EF65A X-CRM114-Status: GOOD ( 19.87 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On 2022-06-16 06:42, Yong Wu wrote: > The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the i+1 > larb is parsed fail(return -EINVAL), we should of_node_put for the 0..i > larbs. In the fail path, one of_node_put matches with of_parse_phandle in > it. > > Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") > Signed-off-by: Yong Wu > --- > drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index 3b2489e8a6dd..ab24078938bf 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -1071,12 +1071,12 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m > > plarbdev = of_find_device_by_node(larbnode); > if (!plarbdev) { > - of_node_put(larbnode); > - return -ENODEV; > + ret = -ENODEV; > + goto err_larbnode_put; > } > if (!plarbdev->dev.driver) { > - of_node_put(larbnode); > - return -EPROBE_DEFER; > + ret = -EPROBE_DEFER; > + goto err_larbnode_put; > } > data->larb_imu[id].dev = &plarbdev->dev; > > @@ -1107,9 +1107,20 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m > DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); > if (!link) { > dev_err(dev, "Unable to link %s.\n", dev_name(data->smicomm_dev)); > - return -EINVAL; > + ret = -EINVAL; > + goto err_larbnode_put; > } > return 0; > + > +err_larbnode_put: > + while (i--) { > + larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i); > + if (larbnode && of_device_is_available(larbnode)) { > + of_node_put(larbnode); > + of_node_put(larbnode); > + } This looks a bit awkward - could we not just iterate through data->larb_imu and put dev->of_node for each valid dev? Also, of_find_device_by_node() takes a reference on the struct device itself, so strictly we should be doing put_device() on those as well if we're bailing out. Robin. > + } > + return ret; > } > > static int mtk_iommu_probe(struct platform_device *pdev)