From cfe8f3cfc190feac51169a86ed6c35bc7a286576 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 19 Jul 2018 18:00:42 +0000 Subject: [PATCH] scst: Introduce a backport of kmem_cache_create_usercopy() This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7427 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 24 ++++++++++++++++++++++++ scst/src/scst_main.c | 4 ---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 2f65a9061..02372f453 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -671,6 +671,30 @@ static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) } #endif +/* + * See also commit 8eb8284b4129 ("usercopy: Prepare for usercopy + * whitelisting"). + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) +static inline struct kmem_cache *kmem_cache_create_usercopy(const char *name, + unsigned int size, unsigned int align, + slab_flags_t flags, + unsigned int useroffset, unsigned int usersize, + void (*ctor)(void *)) +{ + return kmem_cache_create(name, size, align, flags, ctor, NULL); +} +#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0) +static inline struct kmem_cache *kmem_cache_create_usercopy(const char *name, + unsigned int size, unsigned int align, + slab_flags_t flags, + unsigned int useroffset, unsigned int usersize, + void (*ctor)(void *)) +{ + return kmem_cache_create(name, size, align, flags, ctor); +} +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 2573759e7..0ef90e6ea 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -2583,7 +2583,6 @@ static int __init init_scst(void) * Used for structures with fast path write access accessed from user space. * See also commit 8eb8284b4129 ("usercopy: Prepare for usercopy whitelisting"). */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) #define INIT_CACHEP_ALIGN_USERCOPY(p, s) ({ \ (p) = kmem_cache_create_usercopy(#s, sizeof(struct s), \ __alignof__(struct s), \ @@ -2593,9 +2592,6 @@ static int __init init_scst(void) sizeof(struct s)); \ (p); \ }) -#else -#define INIT_CACHEP_ALIGN_USERCOPY(p, s) INIT_CACHEP_ALIGN(p, s) -#endif res = -ENOMEM; if (!INIT_CACHEP(scst_mgmt_cachep, scst_mgmt_cmd))