From: Miles Chen via iommu <iommu@lists.linux-foundation.org>
To: <yong.wu@mediatek.com>
Cc: miles.chen@mediatek.com, jroedel@suse.de, will@kernel.org,
linux-kernel@vger.kernel.org, matthias.bgg@gmail.com,
iommu@lists.linux-foundation.org,
linux-mediatek@lists.infradead.org, hverkuil-cisco@xs4all.nl,
mchehab@kernel.org, robin.murphy@arm.com,
linux-arm-kernel@lists.infradead.org,
angelogioacchino.delregno@collabora.com
Subject: Re: [PATCH v2] iommu/mediatek: fix NULL pointer dereference when printing dev_name
Date: Wed, 27 Apr 2022 10:13:21 +0800 [thread overview]
Message-ID: <20220427021321.22899-1-miles.chen@mediatek.com> (raw)
In-Reply-To: <4ff4246cd5d567a3fa8124800f5d75be0034621c.camel@mediatek.com>
Hi Yong,
>On Mon, 2022-04-25 at 11:03 +0100, Robin Murphy wrote:
>> On 2022-04-25 09:24, Miles Chen via iommu wrote:
>> > When larbdev is NULL (in the case I hit, the node is incorrectly
>> > set
>> > iommus = <&iommu NUM>), it will cause device_link_add() fail and
>>
>> Until the MT8195 infra MMU support lands, is there ever a case where
>> it's actually valid for larbdev to be NULL? If not, I think it would
>> be
>> a lot clearer to explicitly fail the probe here, rather than
>> silently
>> continue and risk fatal errors, hangs, or other weird behaviour if
>> there's no guarantee that the correct LARB is powered up (plus then
>> the
>> release callbacks wouldn't need to worry about it either).
>
>Yes. It should return fail for this case. This issue only happens when
>the dts parameters doesn't respect the definition from the binding[1].
>
>Locally Miles tested with a internal definition that have not send
>upstream to get this KE. In this case, I'm not sure if we should
>request the user use the right ID in dts. Anyway I have no objection to
>modifying this, then something like this: (Avoid invalid input from
>dtb)
>
>@@ -790,6 +790,8 @@ static struct iommu_device
>*mtk_iommu_probe_device(struct device *dev)
> * All the ports in each a device should be in the same larbs.
> */
> larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);
>+ if (larbid >= MTK_LARB_NR_MAX)
>+ return ERR_PTR(-EINVAL);
> for (i = 1; i < fwspec->num_ids; i++) {
> larbidx = MTK_M4U_TO_LARB(fwspec->ids[i]);
> if (larbid != larbidx) {
>@@ -799,6 +801,8 @@ static struct iommu_device
>*mtk_iommu_probe_device(struct device *dev)
> }
> }
> larbdev = data->larb_imu[larbid].dev;
>+ if (!larbdev)
>+ return ERR_PTR(-EINVAL);
> link = device_link_add(dev, larbdev,
> DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
> if (!link)
Thanks for guilding me, I will put this in patch v2.
Thanks,
Miles
>
>
>[1]
>https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml#L116
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2022-04-27 2:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 8:24 [PATCH v2] iommu/mediatek: fix NULL pointer dereference when printing dev_name Miles Chen via iommu
2022-04-25 10:03 ` Robin Murphy
2022-04-26 5:52 ` Yong Wu via iommu
2022-04-27 2:13 ` Miles Chen via iommu [this message]
2022-04-27 2:13 ` Miles Chen via iommu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220427021321.22899-1-miles.chen@mediatek.com \
--to=iommu@lists.linux-foundation.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jroedel@suse.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mchehab@kernel.org \
--cc=miles.chen@mediatek.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
--cc=yong.wu@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox