<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="auto">
<div><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">Am 03.07.2019 18:27 schrieb Fuqian Huang <huangfq.daxian@gmail.com>:<br type="attribution">
<blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><font size="2"><span style="font-size:11pt">
<div>kmemdup is introduced to duplicate a region of memory in a neat way.<br>
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to<br>
write the size twice (sometimes lead to mistakes), kmemdup improves<br>
readability, leads to smaller code and also reduce the chances of mistakes.<br>
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.<br>
<br>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com><br>
Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com><br>
</div>
</span></font></div>
</blockquote>
</div>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">Reviewed-by: Christian König <Christian.Koenig@amd.com></div>
<div dir="auto"><br>
</div>
<div dir="auto">
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><font size="2"><span style="font-size:11pt">
<div>---<br>
Changes in v2:<br>
- Fix a typo in commit message (memset -> memcpy)<br>
<br>
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 5 ++---<br>
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 5 ++---<br>
drivers/gpu/drm/amd/display/dc/core/dc.c | 6 ++----<br>
drivers/gpu/drm/amd/display/dc/core/dc_stream.c | 4 +---<br>
4 files changed, 7 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
index 02955e6e9dd9..48e38479d634 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
@@ -3925,11 +3925,10 @@ static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)<br>
<br>
int list_size;<br>
unsigned int *register_list_format =<br>
- kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);<br>
+ kmemdup(adev->gfx.rlc.register_list_format,<br>
+ adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);<br>
if (!register_list_format)<br>
return -ENOMEM;<br>
- memcpy(register_list_format, adev->gfx.rlc.register_list_format,<br>
- adev->gfx.rlc.reg_list_format_size_bytes);<br>
<br>
gfx_v8_0_parse_ind_reg_list(register_list_format,<br>
RLC_FormatDirectRegListLength,<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
index b610e3b30d95..09d901ef216d 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
@@ -2092,11 +2092,10 @@ static int gfx_v9_1_init_rlc_save_restore_list(struct amdgpu_device *adev)<br>
u32 tmp = 0;<br>
<br>
u32 *register_list_format =<br>
- kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);<br>
+ kmemdup(adev->gfx.rlc.register_list_format,<br>
+ adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);<br>
if (!register_list_format)<br>
return -ENOMEM;<br>
- memcpy(register_list_format, adev->gfx.rlc.register_list_format,<br>
- adev->gfx.rlc.reg_list_format_size_bytes);<br>
<br>
/* setup unique_indirect_regs array and indirect_start_offsets array */<br>
unique_indirect_reg_count = ARRAY_SIZE(unique_indirect_regs);<br>
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c<br>
index 18c775a950cc..6ced3b9cdce2 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c<br>
@@ -1263,14 +1263,12 @@ struct dc_state *dc_create_state(struct dc *dc)<br>
struct dc_state *dc_copy_state(struct dc_state *src_ctx)<br>
{<!-- --><br>
int i, j;<br>
- struct dc_state *new_ctx = kzalloc(sizeof(struct dc_state),<br>
- GFP_KERNEL);<br>
+ struct dc_state *new_ctx = kmemdup(src_ctx,<br>
+ sizeof(struct dc_state), GFP_KERNEL);<br>
<br>
if (!new_ctx)<br>
return NULL;<br>
<br>
- memcpy(new_ctx, src_ctx, sizeof(struct dc_state));<br>
-<br>
for (i = 0; i < MAX_PIPES; i++) {<!-- --><br>
struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];<br>
<br>
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c<br>
index 96e97d25d639..d4b563a2e220 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c<br>
@@ -167,12 +167,10 @@ struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream)<br>
{<!-- --><br>
struct dc_stream_state *new_stream;<br>
<br>
- new_stream = kzalloc(sizeof(struct dc_stream_state), GFP_KERNEL);<br>
+ new_stream = kzalloc(stream, sizeof(struct dc_stream_state), GFP_KERNEL);<br>
if (!new_stream)<br>
return NULL;<br>
<br>
- memcpy(new_stream, stream, sizeof(struct dc_stream_state));<br>
-<br>
if (new_stream->sink)<br>
dc_sink_retain(new_stream->sink);<br>
<br>
-- <br>
2.11.0<br>
<br>
</div>
</span></font></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</body>
</html>