drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
From: Zhang Enpei <zhang.enpei@zte.com.cn>
Use devm_kmemdup_array() to avoid multiplication or possible overflows.
Signed-off-by: Zhang Enpei <zhang.enpei@zte.com.cn>
---
drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index d5e6bab36414..e700c0f0a3a2 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -1003,7 +1003,8 @@ static int mtk_drm_of_ddp_path_build_one(struct device *dev, enum mtk_crtc_path
return -EINVAL;
}
- final_ddp_path = devm_kmemdup(dev, temp_path, idx * sizeof(temp_path[0]), GFP_KERNEL);
+ final_ddp_path = devm_kmemdup_array(dev, temp_path, idx,
+ sizeof(*temp_path), GFP_KERNEL);
if (!final_ddp_path)
return -ENOMEM;
--
2.25.1
On Tue, 2025-08-19 at 17:25 +0800, zhang.enpei@zte.com.cn wrote: > External email : Please do not click links or open attachments until you have verified the sender or the content. > > > From: Zhang Enpei <zhang.enpei@zte.com.cn> > > Use devm_kmemdup_array() to avoid multiplication or possible overflows. > > Signed-off-by: Zhang Enpei <zhang.enpei@zte.com.cn> > --- > drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > index d5e6bab36414..e700c0f0a3a2 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > @@ -1003,7 +1003,8 @@ static int mtk_drm_of_ddp_path_build_one(struct device *dev, enum mtk_crtc_path > return -EINVAL; > } > > - final_ddp_path = devm_kmemdup(dev, temp_path, idx * sizeof(temp_path[0]), GFP_KERNEL); > + final_ddp_path = devm_kmemdup_array(dev, temp_path, idx, > + sizeof(*temp_path), GFP_KERNEL); idx and sizeof(*temp_path) are so small, it's not necessary to worry overflow. devm_kmemdup_array() would use built-in multiply, it's also a multiplication. Regards, CK > if (!final_ddp_path) > return -ENOMEM; > > -- > 2.25.1
© 2016 - 2026 Red Hat, Inc.