iommu/mediatek: check return value after calling platform_get_resource()
Subsystems (3)
PATCH 1/1 iommu/mediatek: check return value after calling platform_get_resource()
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 <[email protected]>
--- drivers/iommu/mtk_iommu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iommu/mtk_iommu.c +2 -0
@@ -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 ;
Signature · 1 line
2.25.1
Quoted 14 lines · Yang Yingliang
platform_get_resource()may return NULL pointer, we need check its return value to avoid null-ptr-deref inresource_size().Fixes 42d57fc58aeb ("iommu/mediatek: Initialise/Remove for multi bank dev")Signed-off-by Yang Yingliang <[email protected]>--- drivers/iommu/mtk_iommu.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iommu/mtk_iommu.c +0
-0
drivers/iommu/mtk_iommu.c static int mtk_iommu_probe(struct platform_device *pdev) · line 1177
Quoted 5 lines
drivers/iommu/mtk_iommu.c +2
-0@@ -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 ;
That would be the case if the DT passed to the kernel isn't correct, but anyway:
Reviewed-by Matthias Brugger <[email protected]>
Quoted 3 lines
drivers/iommu/mtk_iommu.c +0
-0if (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 ;
Quoted 8 lines · Yang Yingliang
platform_get_resource()may return NULL pointer, we need check its return value to avoid null-ptr-deref inresource_size().Fixes 42d57fc58aeb ("iommu/mediatek: Initialise/Remove for multi bank dev")Signed-off-by Yang Yingliang <[email protected]>--- drivers/iommu/mtk_iommu.c | 2 ++ 1 file changed, 2 insertions(+)
Applied, thanks.