diff --git a/scst/include/backport.h b/scst/include/backport.h index 8fcd87edc..acad11f28 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -673,6 +673,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 2ec768d1e..be01c4721 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -2578,7 +2578,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), \ @@ -2588,9 +2587,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)) diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index c7c3094ae..c0b8377ff 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -1374,15 +1374,10 @@ static void sgv_pool_init_cache(struct sgv_pool *pool, int cache_num, scnprintf(pool->cache_names[cache_num], sizeof(pool->cache_names[cache_num]), "%s-%uK", pool->name, (pages << PAGE_SHIFT) >> 10); - pool->caches[cache_num] = kmem_cache_create( - pool->cache_names[cache_num], size, - 0, per_cpu ? SCST_SLAB_FLAGS : - (SCST_SLAB_FLAGS|SLAB_HWCACHE_ALIGN), NULL -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)) - , NULL); -#else - ); -#endif + pool->caches[cache_num] = kmem_cache_create_usercopy( + pool->cache_names[cache_num], size, 0/*align*/, per_cpu ? + SCST_SLAB_FLAGS : SCST_SLAB_FLAGS | SLAB_HWCACHE_ALIGN, + 0/*useroffset*/, size/*usersize*/, NULL); return; }