Commit d12c2022 authored by Fuqian Huang's avatar Fuqian Huang Committed by Alex Deucher

drm/amdgpu: Use kmemdup rather than duplicating its implementation

kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.
Reviewed-by: default avatarChristian König <Christian.Koenig@amd.com>
Reviewed-by: default avatarEmil Velikov <emil.velikov@collabora.com>
Signed-off-by: default avatarFuqian Huang <huangfq.daxian@gmail.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent a5b16155
...@@ -3925,11 +3925,10 @@ static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev) ...@@ -3925,11 +3925,10 @@ static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
int list_size; int list_size;
unsigned int *register_list_format = unsigned int *register_list_format =
kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL); kmemdup(adev->gfx.rlc.register_list_format,
adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
if (!register_list_format) if (!register_list_format)
return -ENOMEM; return -ENOMEM;
memcpy(register_list_format, adev->gfx.rlc.register_list_format,
adev->gfx.rlc.reg_list_format_size_bytes);
gfx_v8_0_parse_ind_reg_list(register_list_format, gfx_v8_0_parse_ind_reg_list(register_list_format,
RLC_FormatDirectRegListLength, RLC_FormatDirectRegListLength,
......
...@@ -2074,11 +2074,10 @@ static int gfx_v9_1_init_rlc_save_restore_list(struct amdgpu_device *adev) ...@@ -2074,11 +2074,10 @@ static int gfx_v9_1_init_rlc_save_restore_list(struct amdgpu_device *adev)
u32 tmp = 0; u32 tmp = 0;
u32 *register_list_format = u32 *register_list_format =
kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL); kmemdup(adev->gfx.rlc.register_list_format,
adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
if (!register_list_format) if (!register_list_format)
return -ENOMEM; return -ENOMEM;
memcpy(register_list_format, adev->gfx.rlc.register_list_format,
adev->gfx.rlc.reg_list_format_size_bytes);
/* setup unique_indirect_regs array and indirect_start_offsets array */ /* setup unique_indirect_regs array and indirect_start_offsets array */
unique_indirect_reg_count = ARRAY_SIZE(unique_indirect_regs); unique_indirect_reg_count = ARRAY_SIZE(unique_indirect_regs);
......
...@@ -1190,14 +1190,12 @@ struct dc_state *dc_create_state(struct dc *dc) ...@@ -1190,14 +1190,12 @@ struct dc_state *dc_create_state(struct dc *dc)
struct dc_state *dc_copy_state(struct dc_state *src_ctx) struct dc_state *dc_copy_state(struct dc_state *src_ctx)
{ {
int i, j; int i, j;
struct dc_state *new_ctx = kzalloc(sizeof(struct dc_state), struct dc_state *new_ctx = kmemdup(src_ctx,
GFP_KERNEL); sizeof(struct dc_state), GFP_KERNEL);
if (!new_ctx) if (!new_ctx)
return NULL; return NULL;
memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
for (i = 0; i < MAX_PIPES; i++) { for (i = 0; i < MAX_PIPES; i++) {
struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i]; struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];
......
...@@ -181,12 +181,10 @@ struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream) ...@@ -181,12 +181,10 @@ struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream)
{ {
struct dc_stream_state *new_stream; struct dc_stream_state *new_stream;
new_stream = kzalloc(sizeof(struct dc_stream_state), GFP_KERNEL); new_stream = kmemdup(stream, sizeof(struct dc_stream_state), GFP_KERNEL);
if (!new_stream) if (!new_stream)
return NULL; return NULL;
memcpy(new_stream, stream, sizeof(struct dc_stream_state));
if (new_stream->sink) if (new_stream->sink)
dc_sink_retain(new_stream->sink); dc_sink_retain(new_stream->sink);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment