]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
iommu/msm: Fix an incorrect NULL check on list iterator
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Sun, 1 May 2022 13:28:23 +0000 (21:28 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jun 2022 14:59:29 +0000 (16:59 +0200)
commitd2090daa76ecded88372481b970312298826eed3
tree95fa820e747f4871489279e0ade66a60f2e7d855
parent3549ab4b962cf619e8c55484a0d870a34b3f845f
iommu/msm: Fix an incorrect NULL check on list iterator

commit 8b9ad480bd1dd25f4ff4854af5685fa334a2f57a 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: f78ebca8ff3d6 ("iommu/msm: Add support for generic master bindings")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Link: https://lore.kernel.org/r/20220501132823.12714-1-xiam0nd.tong@gmail.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iommu/msm_iommu.c