mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/mediatek: mtk_drm_drv: switch to use devm_kmemdup_array()
@ 2025-08-19  9:25 zhang.enpei
  2025-11-19  6:57 ` CK Hu (胡俊光)
  0 siblings, 1 reply; 2+ messages in thread
From: zhang.enpei @ 2025-08-19  9:25 UTC (permalink / raw)
  To: chunkuang.hu
  Cc: p.zabel, airlied, simona, matthias.bgg,
	angelogioacchino.delregno, dri-devel, linux-mediatek,
	linux-kernel, linux-arm-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/mediatek: mtk_drm_drv: switch to use devm_kmemdup_array()
  2025-08-19  9:25 [PATCH] drm/mediatek: mtk_drm_drv: switch to use devm_kmemdup_array() zhang.enpei
@ 2025-11-19  6:57 ` CK Hu (胡俊光)
  0 siblings, 0 replies; 2+ messages in thread
From: CK Hu (胡俊光) @ 2025-11-19  6:57 UTC (permalink / raw)
  To: zhang.enpei, chunkuang.hu
  Cc: simona, dri-devel, AngeloGioacchino Del Regno, linux-kernel,
	airlied, linux-arm-kernel, p.zabel, matthias.bgg, linux-mediatek

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-19  6:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-19  9:25 [PATCH] drm/mediatek: mtk_drm_drv: switch to use devm_kmemdup_array() zhang.enpei
2025-11-19  6:57 ` CK Hu (胡俊光)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®