[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20240831102648.92714-1-ruanjinjie@huawei.com>
Date: Sat, 31 Aug 2024 18:26:48 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <jani.nikula@...ux.intel.com>, <joonas.lahtinen@...ux.intel.com>,
<rodrigo.vivi@...el.com>, <tursulin@...ulin.net>, <airlied@...il.com>,
<daniel@...ll.ch>, <chentao@...inos.cn>, <ivan.briano@...el.com>,
<ruanjinjie@...wei.com>, <vinay.belgaumkar@...el.com>,
<intel-gfx@...ts.freedesktop.org>, <dri-devel@...ts.freedesktop.org>,
<linux-kernel@...r.kernel.org>
Subject: [PATCH -next] drm/i915: Use memdup_user() helper
Switching to memdup_user(), which combines kmalloc() and copy_from_user(),
and it can simplfy code.
Signed-off-by: Jinjie Ruan <ruanjinjie@...wei.com>
---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index c0543c35cd6a..c1cc41e90502 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -2159,18 +2159,12 @@ static int set_context_image(struct i915_gem_context *ctx,
goto out_ce;
}
- state = kmalloc(ce->engine->context_size, GFP_KERNEL);
- if (!state) {
- ret = -ENOMEM;
+ state = memdup_user(u64_to_user_ptr(user.image), ce->engine->context_size);
+ if (IS_ERR(state)) {
+ ret = PTR_ERR(state);
goto out_ce;
}
- if (copy_from_user(state, u64_to_user_ptr(user.image),
- ce->engine->context_size)) {
- ret = -EFAULT;
- goto out_state;
- }
-
shmem_state = shmem_create_from_data(ce->engine->name,
state, ce->engine->context_size);
if (IS_ERR(shmem_state)) {
--
2.34.1
Powered by blists - more mailing lists