[v2,08/35] drm/i915: Use kmemdup rather than duplicating its implementation

Submitted by Fuqian Huang on July 3, 2019, 4:27 p.m.


Message ID 20190703162728.32230-1-huangfq.daxian@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Intel GVT devel

Not browsing as part of any series.

Commit Message

Fuqian Huang July 3, 2019, 4:27 p.m.
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.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/gpu/drm/i915/gvt/dmabuf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 41c8ebc60c63..fe6fa979f22a 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -411,14 +411,13 @@  int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void *args)
 		goto out;
-	dmabuf_obj->info = kmalloc(sizeof(struct intel_vgpu_fb_info),
+	dmabuf_obj->info = kmemdup(&fb_info, sizeof(struct intel_vgpu_fb_info),
 	if (unlikely(!dmabuf_obj->info)) {
 		gvt_vgpu_err("allocate intel vgpu fb info failed\n");
 		ret = -ENOMEM;
 		goto out_free_dmabuf;
-	memcpy(dmabuf_obj->info, &fb_info, sizeof(struct intel_vgpu_fb_info));
 	((struct intel_vgpu_fb_info *)dmabuf_obj->info)->obj = dmabuf_obj;