]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu/mediatek: Check return value after calling platform_get_resource()
authorYang Yingliang <yangyingliang@huawei.com>
Sat, 29 Oct 2022 10:35:50 +0000 (18:35 +0800)
committerJoerg Roedel <jroedel@suse.de>
Sat, 19 Nov 2022 09:08:49 +0000 (10:08 +0100)
platform_get_resource() may return NULL pointer, we need check its
return value to avoid null-ptr-deref in resource_size().

Fixes: 42d57fc58aeb ("iommu/mediatek: Initialise/Remove for multi bank dev")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
Link: https://lore.kernel.org/r/20221029103550.3774365-1-yangyingliang@huawei.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/mtk_iommu.c

index 2ab2ecfe01f80260ef6c835127ee385249926df3..2d14dc846b8392894892e26bc5b0c3a5d2f53756 100644 (file)
@@ -1173,6 +1173,8 @@ static int mtk_iommu_probe(struct platform_device *pdev)
 
        banks_num = data->plat_data->banks_num;
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res)
+               return -EINVAL;
        if (resource_size(res) < banks_num * MTK_IOMMU_BANK_SZ) {
                dev_err(dev, "banknr %d. res %pR is not enough.\n", banks_num, res);
                return -EINVAL;