Skip to content

Commit fbc0ced

Browse files
committed
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
1 parent a7f7d13 commit fbc0ced

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

drivers/gpu/drm/nouveau/nouveau_drv.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,32 @@ nouveau_cli(struct drm_file *fpriv)
130130
return fpriv ? fpriv->driver_priv : NULL;
131131
}
132132

133+
static inline void
134+
u_free(void *addr)
135+
{
136+
kvfree(addr);
137+
}
138+
139+
static inline void *
140+
u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size)
141+
{
142+
void *mem;
143+
void __user *userptr = (void __force __user *)(uintptr_t)user;
144+
145+
size *= nmemb;
146+
147+
mem = kvmalloc(size, GFP_KERNEL);
148+
if (!mem)
149+
return ERR_PTR(-ENOMEM);
150+
151+
if (copy_from_user(mem, userptr, size)) {
152+
u_free(mem);
153+
return ERR_PTR(-EFAULT);
154+
}
155+
156+
return mem;
157+
}
158+
133159
#include <nvif/object.h>
134160
#include <nvif/parent.h>
135161

drivers/gpu/drm/nouveau/nouveau_gem.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -613,32 +613,6 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
613613
return 0;
614614
}
615615

616-
static inline void
617-
u_free(void *addr)
618-
{
619-
kvfree(addr);
620-
}
621-
622-
static inline void *
623-
u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
624-
{
625-
void *mem;
626-
void __user *userptr = (void __force __user *)(uintptr_t)user;
627-
628-
size *= nmemb;
629-
630-
mem = kvmalloc(size, GFP_KERNEL);
631-
if (!mem)
632-
return ERR_PTR(-ENOMEM);
633-
634-
if (copy_from_user(mem, userptr, size)) {
635-
u_free(mem);
636-
return ERR_PTR(-EFAULT);
637-
}
638-
639-
return mem;
640-
}
641-
642616
static int
643617
nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
644618
struct drm_nouveau_gem_pushbuf *req,

0 commit comments

Comments
 (0)