From bac0b7ec85539d4d6688eba886a26ca7557bac0a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 4 Nov 2018 19:56:37 +0000 Subject: [PATCH] Merge r7600 from trunk git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/3.3.x@7781 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/scst/include/backport.h b/scst/include/backport.h index c9c381d6b..b5929aed0 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -774,6 +774,39 @@ 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, + unsigned long 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, + unsigned long 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(4, 16, 0) +#define KMEM_CACHE_USERCOPY(__struct, __flags, __field) \ + kmem_cache_create_usercopy(#__struct, \ + sizeof(struct __struct), \ + __alignof__(struct __struct), (__flags), \ + offsetof(struct __struct, __field), \ + sizeof_field(struct __struct, __field), NULL) +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)