Skip to contentSkip to conversation

drm/amd/display: replace kzalloc and memcpy with kmemdup

PATCH In review [email protected] 2 participants 2 messages Dec 8, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: replace kzalloc and memcpy with kmemdup

From: Yang Guang <[email protected]>

Convert kzalloc/memcpy operations to memdup makes for cleaner code and avoids memcpy() failures

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +4 -6
index 76b47f178127..867e1a0fdef6 100644
@@ -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
 
Signature · 1 line
2.25.1
#1 lore raw

Le 08/12/2023 à 03:44, [email protected] a écrit :

Quoted 4 lines

From: Yang Guang <[email protected]>

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.

Quoted 11 lines
---
  drivers/gpu/drm/amd/display/dc/core/dc.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +0 -0
index 76b47f178127..867e1a0fdef6 100644

drivers/gpu/drm/amd/display/dc/core/dc.c struct dc_state *dc_copy_state(struct dc_state *src_ctx) · line 2267

Quoted 10 lines
drivers/gpu/drm/amd/display/dc/core/dc.c +1 -6
@@ -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

Quoted 6 lines
drivers/gpu/drm/amd/display/dc/core/dc.c +3 -0
+		if (!dml2)
+			return NULL;
+		new_ctx->bw_ctx.dml2 = dml2;
  	}
  #endif