Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2105987pxb; Wed, 30 Mar 2022 16:47:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfJNqhDr1NOwmKc2BwXtWfbE4sdEgj2lIsyryrSGfFs3NJG5i7lNi93AhK1L6zGabaGhr1 X-Received: by 2002:a17:907:1c0a:b0:6da:7ac4:5349 with SMTP id nc10-20020a1709071c0a00b006da7ac45349mr2272292ejc.596.1648684023439; Wed, 30 Mar 2022 16:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648684023; cv=none; d=google.com; s=arc-20160816; b=vN8AdemZb+VKkg0o4iacWLbRvK4HrSUT19Hrg2GNWiOhXaWIiSX8oG7U6Krjmb+k6Z qzrZ7KUXlHN1tv6CcTBElLp00N4QTbz8JkMJXz1bw14UUqd1JVBqEcGDZ8quoGCAhKeL 557kJf39cakNmYT6ceKCh2+cYTJGs5fEP5TCM4MXckg2dDtfMAJ2anGwIwlJPu5IgrW9 9hvcK8KPSB87e1noeSd8hannPpzcsdTElncHxNatzAOdVqZh2b680Haj1ArJWiaIglwe ZZitgHhFl8Oy44oWSJgd1lwAjvdqkpIoKw/QcNRmqfE5Mx5mqD6UoZLE29HI9WdkJeFj PXuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=27dmX9c/4Jr5xomDRpvuDJPopqAgnXBUtwTi5gUd1L0=; b=awHFnPYoTJHZTKmXxhXubcKxjRvWW8X8+OSNOQVBWvuXIYh+bdaGSamaGebl6iUZqt HzW1QdTeLdJxmYZcj0Z7gSTlmaNN4ynYMlS57WPjoiMtolTrP4rVY2sL7R59gMeeZpIU 2sPZueH3SCCE0y3chgb65k95SBzEHT4Ji28wmpDZ1gMG2XXzYQfr0Nkr5qgZj3RC3E+f GAt0oBABn6CUd6DdLrDggxVIcEXxp8ZsOVTkOtmq5sgiwwTNuB0/tkHn75p2wDsJZmEA G0lQ+3QyNMncZckLwFZzoqbI4l65+fN9yjcDRqJkzyc6KWhdfU7hSgGgyJS2Dwb0yLun b8fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jS/AzIAt"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb17-20020a170906b89100b006df84b138c8si23253052ejb.363.2022.03.30.16.46.13; Wed, 30 Mar 2022 16:47:03 -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=@kernel.org header.s=k20201202 header.b="jS/AzIAt"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345166AbiC3MIJ (ORCPT + 99 others); Wed, 30 Mar 2022 08:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344499AbiC3LxN (ORCPT ); Wed, 30 Mar 2022 07:53:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2423C262428; Wed, 30 Mar 2022 04:48:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9F80FB81C36; Wed, 30 Mar 2022 11:48:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6BE3C36AE2; Wed, 30 Mar 2022 11:48:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648640930; bh=or7vMsAJ5qPVBHGYQ8AZJOSb3BRjqMrEX/v6pBzhP1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jS/AzIAt8uZVMw/JSjOYzrxQIk074ZtSYTVr1qHd2g06qb1vdRenqbdSHofy3zahD DK0ly6txaxNd/6ymfu+f4QVMm9t8BeydDEY3td8VVGjJSwu6U1M8sMCB5Ju8y0eO3A TF3msroFpTLLgVniJUjP4h6W2Mx0r8VGgEF7uLElXDIZQJh/DnIvbF3E3AXzDavEfE Ah/3O2m52PEcsloOgVbPfjMf/ywpZsCF+uGN8wJ0kgpfJ2yxvqDi5yUlkPZAat3Lnl rEzKvjiYwUBtlP/ANJhuedQKu+inVVx5Hl8y/TWEq8mbEqhHqZFaThZaY+6S0yBmCB Ui1EnrPQsTYuQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yong Wu , Frank Wunderlich , Joerg Roedel , AngeloGioacchino Del Regno , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , joro@8bytes.org, matthias.bgg@gmail.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 5.16 11/59] media: iommu/mediatek-v1: Free the existed fwspec if the master dev already has Date: Wed, 30 Mar 2022 07:47:43 -0400 Message-Id: <20220330114831.1670235-11-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: Yong Wu [ Upstream commit 822a2ed8c606caf6a11b1a180b8e46292bd77d71 ] When the iommu master device enters of_iommu_xlate, the ops may be NULL(iommu dev is defered), then it will initialize the fwspec here: [] (dev_iommu_fwspec_set) from [] (iommu_fwspec_init+0xbc/0xd4) [] (iommu_fwspec_init) from [] (of_iommu_xlate+0x7c/0x12c) [] (of_iommu_xlate) from [] (of_iommu_configure+0x144/0x1e8) BUT the mtk_iommu_v1.c only supports arm32, the probing flow still is a bit weird. We always expect create the fwspec internally. otherwise it will enter here and return fail. static int mtk_iommu_create_mapping(struct device *dev, struct of_phandle_args *args) { ... if (!fwspec) { .... } else if (dev_iommu_fwspec_get(dev)->ops != &mtk_iommu_ops) { >>>>>>>>>>Enter here. return fail.<<<<<<<<<<<< return -EINVAL; } ... } Thus, Free the existed fwspec if the master device already has fwspec. This issue is reported at: https://lore.kernel.org/linux-mediatek/trinity-7d9ebdc9-4849-4d93-bfb5-429dcb4ee449-1626253158870@3c-app-gmx-bs01/ Reported-by: Frank Wunderlich Tested-by: Frank Wunderlich # BPI-R2/MT7623 Signed-off-by: Yong Wu Acked-by: Joerg Roedel Acked-by: AngeloGioacchino Del Regno Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/iommu/mtk_iommu_v1.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index be22fcf988ce..1467ba1e4417 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -425,6 +425,15 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev) struct mtk_iommu_data *data; int err, idx = 0; + /* + * In the deferred case, free the existed fwspec. + * Always initialize the fwspec internally. + */ + if (fwspec) { + iommu_fwspec_free(dev); + fwspec = dev_iommu_fwspec_get(dev); + } + while (!of_parse_phandle_with_args(dev->of_node, "iommus", "#iommu-cells", idx, &iommu_spec)) { -- 2.34.1