Message ID | 20221029103550.3774365-1-yangyingliang@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | iommu/mediatek: check return value after calling platform_get_resource() | expand |
On 29/10/2022 12:35, Yang Yingliang wrote: > 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> > --- > drivers/iommu/mtk_iommu.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index 2ab2ecfe01f8..2d14dc846b83 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -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 <matthias.bgg@gmail.com> > 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;
On Sat, Oct 29, 2022 at 06:35:50PM +0800, Yang Yingliang wrote: > 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> > --- > drivers/iommu/mtk_iommu.c | 2 ++ > 1 file changed, 2 insertions(+) Applied, thanks.
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 2ab2ecfe01f8..2d14dc846b83 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -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;
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> --- drivers/iommu/mtk_iommu.c | 2 ++ 1 file changed, 2 insertions(+)