mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-29 01:09:33 -04:00
drm/nouveau: move usercopy helpers to nouveau_drv.h
Move the usercopy helpers to a common driver header file to make it usable for the new API added in subsequent commits. Reviewed-by: Dave Airlie <airlied@redhat.com> Signed-off-by: Danilo Krummrich <dakr@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230804182406.5222-7-dakr@redhat.com
This commit is contained in:
@@ -130,6 +130,32 @@ nouveau_cli(struct drm_file *fpriv)
|
||||
return fpriv ? fpriv->driver_priv : NULL;
|
||||
}
|
||||
|
||||
static inline void
|
||||
u_free(void *addr)
|
||||
{
|
||||
kvfree(addr);
|
||||
}
|
||||
|
||||
static inline void *
|
||||
u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size)
|
||||
{
|
||||
void *mem;
|
||||
void __user *userptr = (void __force __user *)(uintptr_t)user;
|
||||
|
||||
size *= nmemb;
|
||||
|
||||
mem = kvmalloc(size, GFP_KERNEL);
|
||||
if (!mem)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
if (copy_from_user(mem, userptr, size)) {
|
||||
u_free(mem);
|
||||
return ERR_PTR(-EFAULT);
|
||||
}
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
#include <nvif/object.h>
|
||||
#include <nvif/parent.h>
|
||||
|
||||
|
||||
@@ -613,32 +613,6 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
u_free(void *addr)
|
||||
{
|
||||
kvfree(addr);
|
||||
}
|
||||
|
||||
static inline void *
|
||||
u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
|
||||
{
|
||||
void *mem;
|
||||
void __user *userptr = (void __force __user *)(uintptr_t)user;
|
||||
|
||||
size *= nmemb;
|
||||
|
||||
mem = kvmalloc(size, GFP_KERNEL);
|
||||
if (!mem)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
if (copy_from_user(mem, userptr, size)) {
|
||||
u_free(mem);
|
||||
return ERR_PTR(-EFAULT);
|
||||
}
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
|
||||
struct drm_nouveau_gem_pushbuf *req,
|
||||
|
||||
Reference in New Issue
Block a user