提交 4cb5625d 编写于 作者: X Xiaomeng Tong 提交者: Zheng Zengkai

iommu/msm: Fix an incorrect NULL check on list iterator

stable inclusion
from stable-v5.10.121
commit e9514bce2fb78edac76db738f5eca66dd1165c19
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6CQ

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=e9514bce2fb78edac76db738f5eca66dd1165c19

--------------------------------

commit 8b9ad480 upstream.

The bug is here:
	if (!iommu || iommu->dev->of_node != spec->np) {

The list iterator value 'iommu' will *always* be set and non-NULL by
list_for_each_entry(), so it is incorrect to assume that the iterator
value will be NULL if the list is empty or no element is found (in fact,
it will point to a invalid structure object containing HEAD).

To fix the bug, use a new value 'iter' as the list iterator, while use
the old value 'iommu' as a dedicated variable to point to the found one,
and remove the unneeded check for 'iommu->dev->of_node != spec->np'
outside the loop.

Cc: stable@vger.kernel.org
Fixes: f78ebca8 ("iommu/msm: Add support for generic master bindings")
Signed-off-by: NXiaomeng Tong <xiam0nd.tong@gmail.com>
Link: https://lore.kernel.org/r/20220501132823.12714-1-xiam0nd.tong@gmail.comSigned-off-by: NJoerg Roedel <jroedel@suse.de>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 d4a2da04
...@@ -609,16 +609,19 @@ static void insert_iommu_master(struct device *dev, ...@@ -609,16 +609,19 @@ static void insert_iommu_master(struct device *dev,
static int qcom_iommu_of_xlate(struct device *dev, static int qcom_iommu_of_xlate(struct device *dev,
struct of_phandle_args *spec) struct of_phandle_args *spec)
{ {
struct msm_iommu_dev *iommu; struct msm_iommu_dev *iommu = NULL, *iter;
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;
spin_lock_irqsave(&msm_iommu_lock, flags); spin_lock_irqsave(&msm_iommu_lock, flags);
list_for_each_entry(iommu, &qcom_iommu_devices, dev_node) list_for_each_entry(iter, &qcom_iommu_devices, dev_node) {
if (iommu->dev->of_node == spec->np) if (iter->dev->of_node == spec->np) {
iommu = iter;
break; break;
}
}
if (!iommu || iommu->dev->of_node != spec->np) { if (!iommu) {
ret = -ENODEV; ret = -ENODEV;
goto fail; goto fail;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册