Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5334825rwi; Mon, 17 Oct 2022 19:52:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5TqEO4uTbuPOxX1sDi7mbSilnU8Wsbcnbdzj+pxVsB+kZUj0RZXDFEnQ/WiZPeqN1pXwSQ X-Received: by 2002:a17:907:3e96:b0:78d:f399:57e3 with SMTP id hs22-20020a1709073e9600b0078df39957e3mr538093ejc.699.1666061521986; Mon, 17 Oct 2022 19:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666061521; cv=none; d=google.com; s=arc-20160816; b=x6363xnrwd2o1vfe5lel/NkTj+BkM3ShA5j0oCPLHc/UTew8vbiV5DZVHYB+rfBGRM H6KYLrdBoI1wH5Ul8JwB2Dwvf056zVjyA2r52ulMJi96fsXu5DSWpTn3MnZdpmIu0zzW 0fy7bqrNUgOfFrWXY5cUuU6TKscnjNuRswU9ke7ZS2dNVnQx1X8MqUsxS9mK2JKttNIn u7t85ZK+/beRSvBErMk1vR9ohjaRJsqs6nWcXWGbkgpg6Umzm178lPS7KPjMs7OiPaE8 zRI0t+ZtUbSiXynrIOeFblu8z6pka52pgrOFOIFN2JuwJSO5nclxx8KJjlqMcrdTXPaG Tlaw== 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=jwVUbslhKg59sz0HgwmYe44pWQN1yyoqiDnapSp3f4k=; b=maW9dFwK6Nfpzgn8GHB8prLi1CjfcJJTQMXeQUs1IQ3yBDHvFigMYjJ51IUXa2Yiz9 qpJSvn0jUpxZuFrTKO4WbmJMJnwIAW2RsiBorly0xp2E8Z4RX2G0t5Vsfhtdto5OKuNj cHJemk1+DTH41c7JRZY+od3i8Zn4iFP+U2pPRoWzdg1bjLgsNNHv9JIAcjD2kjNC66UK NvxMKrVbX+msrom6n2BCeDYbfv9FiyDG0QW2XILs5DAQsrg5Hsij6pykjFOsR6kFssfu lH2JuNEP7v96mk6Hkg5JhoM9tobyCxi5z1rAIVKcp4RjLMo2L/FxAOf8YphabpwTfnp5 ORig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=PFokEMHn; 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 en6-20020a056402528600b004534c6c4bd7si9277690edb.433.2022.10.17.19.51.35; Mon, 17 Oct 2022 19:52:01 -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=PFokEMHn; 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 S229785AbiJRCne (ORCPT + 99 others); Mon, 17 Oct 2022 22:43:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbiJRCn3 (ORCPT ); Mon, 17 Oct 2022 22:43:29 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F4995E7A for ; Mon, 17 Oct 2022 19:43:25 -0700 (PDT) X-UUID: d5acd4af86e84a64b4566d7f4736bd2e-20221018 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=jwVUbslhKg59sz0HgwmYe44pWQN1yyoqiDnapSp3f4k=; b=PFokEMHnC6tUfI1eOa8Y6KCVTMaq0CR9yZupS+32a8yfZ/9eOZn8ZXOpsjMSc1VRYnkgCn/eQ4aIqqUyvE5yq39UJtEPWBEfhm34Zu6DMtg++Vk9/ZBXCJVseYHpxkyTQWnOhVZNi1C0y07oPQ6yKFQtsl7TxyPEKmBLvr7nbYs=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:c2be3c29-36ed-43c1-888b-32c1e7752fad,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:90 X-CID-INFO: VERSION:1.1.11,REQID:c2be3c29-36ed-43c1-888b-32c1e7752fad,IP:0,URL :0,TC:0,Content:-5,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTIO N:quarantine,TS:90 X-CID-META: VersionHash:39a5ff1,CLOUDID:596e93ee-314c-4293-acb8-ca4299dd021f,B ulkID:221018104320P1ZWC64K,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: d5acd4af86e84a64b4566d7f4736bd2e-20221018 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1574200757; Tue, 18 Oct 2022 10:43:18 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.186) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Tue, 18 Oct 2022 10:43:17 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Tue, 18 Oct 2022 10:43:16 +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 v7 1/6] iommu/mediatek: Add platform_device_put for recovering the device refcnt Date: Tue, 18 Oct 2022 10:42:53 +0800 Message-ID: <20221018024258.19073-2-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20221018024258.19073-1-yong.wu@mediatek.com> References: <20221018024258.19073-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 Add platform_device_put to match with of_find_device_by_node. Meanwhile, I add a new variable "pcommdev" which is for smi common device. Otherwise, "platform_device_put(plarbdev)" for smi-common dev may be not readable. And add a checking for whether pcommdev is NULL. Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 5a4e00e4bbbc..3189b585725f 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1043,7 +1043,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m struct mtk_iommu_data *data) { struct device_node *larbnode, *smicomm_node, *smi_subcomm_node; - struct platform_device *plarbdev; + struct platform_device *plarbdev, *pcommdev; struct device_link *link; int i, larb_nr, ret; @@ -1074,12 +1074,14 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m } if (!plarbdev->dev.driver) { of_node_put(larbnode); + platform_device_put(plarbdev); return -EPROBE_DEFER; } data->larb_imu[id].dev = &plarbdev->dev; component_match_add_release(dev, match, component_release_of, component_compare_of, larbnode); + platform_device_put(plarbdev); } /* Get smi-(sub)-common dev from the last larb. */ @@ -1097,12 +1099,15 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m else smicomm_node = smi_subcomm_node; - plarbdev = of_find_device_by_node(smicomm_node); + pcommdev = of_find_device_by_node(smicomm_node); of_node_put(smicomm_node); - data->smicomm_dev = &plarbdev->dev; + if (!pcommdev) + return -ENODEV; + data->smicomm_dev = &pcommdev->dev; link = device_link_add(data->smicomm_dev, dev, DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); + platform_device_put(pcommdev); if (!link) { dev_err(dev, "Unable to link %s.\n", dev_name(data->smicomm_dev)); return -EINVAL; -- 2.18.0