* [PATCH linux-next] drm/amd/display: replace kzalloc and memcpy with kmemdup
@ 2023-12-08 2:44 yang.guang5
2023-12-08 17:45 ` Christophe JAILLET
0 siblings, 1 reply; 2+ messages in thread
From: yang.guang5 @ 2023-12-08 2:44 UTC (permalink / raw)
To: harry.wentland
Cc: jiang.xuexin, chen.haonan2, cgel.zte, sunpeng.li,
rodrigo.siqueira, alexander.deucher, christian.koenig,
xinhui.pan, airlied, daniel, wenjing.liu, jun.lei, qingqing.zhuo,
alvin.lee2, samson.tam, aric.cyr, chiawen.huang, gabe.teeger,
amd-gfx, dri-devel, linux-kernel
From: Yang Guang <yang.guang5@zte.com.cn>
Convert kzalloc/memcpy operations to memdup makes for
cleaner code and avoids memcpy() failures
Signed-off-by: Chen Haonan <chen.haonan2@zte.com.cn>
---
drivers/gpu/drm/amd/display/dc/core/dc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 76b47f178127..867e1a0fdef6 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -2264,12 +2264,10 @@ struct dc_state *dc_copy_state(struct dc_state *src_ctx)
#ifdef CONFIG_DRM_AMD_DC_FP
if (new_ctx->bw_ctx.dml2) {
- dml2 = kzalloc(sizeof(struct dml2_context), GFP_KERNEL);
- if (!dml2)
- return NULL;
-
- memcpy(dml2, src_ctx->bw_ctx.dml2, sizeof(struct dml2_context));
- new_ctx->bw_ctx.dml2 = dml2;
+ dml2 = kmemdup(src_ctx->bw_ctx.dml2, sizeof(struct dml2_context), GFP_KERNEL);
+ if (!dml2)
+ return NULL;
+ new_ctx->bw_ctx.dml2 = dml2;
}
#endif
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH linux-next] drm/amd/display: replace kzalloc and memcpy with kmemdup
2023-12-08 2:44 [PATCH linux-next] drm/amd/display: replace kzalloc and memcpy with kmemdup yang.guang5
@ 2023-12-08 17:45 ` Christophe JAILLET
0 siblings, 0 replies; 2+ messages in thread
From: Christophe JAILLET @ 2023-12-08 17:45 UTC (permalink / raw)
To: yang.guang5, harry.wentland
Cc: jiang.xuexin, chen.haonan2, cgel.zte, sunpeng.li,
rodrigo.siqueira, alexander.deucher, christian.koenig,
xinhui.pan, airlied, daniel, wenjing.liu, jun.lei, qingqing.zhuo,
alvin.lee2, samson.tam, aric.cyr, chiawen.huang, gabe.teeger,
amd-gfx, dri-devel, linux-kernel
Le 08/12/2023 à 03:44, yang.guang5@zte.com.cn a écrit :
> From: Yang Guang <yang.guang5@zte.com.cn>
>
> Convert kzalloc/memcpy operations to memdup makes for
> cleaner code and avoids memcpy() failures
Hi,
usually, function's names are written with () in commit description.
(i.e. kzalloc()/memcpy()).
memdup should be kmemdup().
Finally the proposed change does not avoid memcpy() failures. Should it
fail (what does it mean in this context?), kmemdup() would behave
exactly the same.
>
> Signed-off-by: Chen Haonan <chen.haonan2@zte.com.cn>
> ---
> drivers/gpu/drm/amd/display/dc/core/dc.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c
> index 76b47f178127..867e1a0fdef6 100644
> --- a/drivers/gpu/drm/amd/display/dc/core/dc.c
> +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
> @@ -2264,12 +2264,10 @@ struct dc_state *dc_copy_state(struct dc_state *src_ctx)
>
> #ifdef CONFIG_DRM_AMD_DC_FP
> if (new_ctx->bw_ctx.dml2) {
> - dml2 = kzalloc(sizeof(struct dml2_context), GFP_KERNEL);
> - if (!dml2)
> - return NULL;
> -
> - memcpy(dml2, src_ctx->bw_ctx.dml2, sizeof(struct dml2_context));
> - new_ctx->bw_ctx.dml2 = dml2;
> + dml2 = kmemdup(src_ctx->bw_ctx.dml2, sizeof(struct dml2_context), GFP_KERNEL);
sizeof(struct dml2_context) could be sizeof(*dlm2) to be less verbose.
CJ
> + if (!dml2)
> + return NULL;
> + new_ctx->bw_ctx.dml2 = dml2;
> }
> #endif
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-08 17:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-08 2:44 [PATCH linux-next] drm/amd/display: replace kzalloc and memcpy with kmemdup yang.guang5
2023-12-08 17:45 ` Christophe JAILLET
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®