Skip to content

Commit 8b9ad48

Browse files
Xiaomeng Tongjoergroedel
authored andcommitted
iommu/msm: Fix an incorrect NULL check on list iterator
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: [email protected] Fixes: f78ebca ("iommu/msm: Add support for generic master bindings") Signed-off-by: Xiaomeng Tong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent bb5bdc5 commit 8b9ad48

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/iommu/msm_iommu.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,16 +615,19 @@ static int insert_iommu_master(struct device *dev,
615615
static int qcom_iommu_of_xlate(struct device *dev,
616616
struct of_phandle_args *spec)
617617
{
618-
struct msm_iommu_dev *iommu;
618+
struct msm_iommu_dev *iommu = NULL, *iter;
619619
unsigned long flags;
620620
int ret = 0;
621621

622622
spin_lock_irqsave(&msm_iommu_lock, flags);
623-
list_for_each_entry(iommu, &qcom_iommu_devices, dev_node)
624-
if (iommu->dev->of_node == spec->np)
623+
list_for_each_entry(iter, &qcom_iommu_devices, dev_node) {
624+
if (iter->dev->of_node == spec->np) {
625+
iommu = iter;
625626
break;
627+
}
628+
}
626629

627-
if (!iommu || iommu->dev->of_node != spec->np) {
630+
if (!iommu) {
628631
ret = -ENODEV;
629632
goto fail;
630633
}

0 commit comments

Comments
 (0)