From b011fdf316549f3db963f3bca972dd34bb45f5cc Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 4 Apr 2019 00:37:15 +0000 Subject: [PATCH] scst/include/backport.h: Add a kmem_cache_destroy() backport This patch makes it safe to call kmem_cache_destroy(NULL) on kernel v4.2 and before. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8149 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scst/include/backport.h b/scst/include/backport.h index 014ab9b31..6e9b92cd9 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -1302,6 +1302,20 @@ static inline void sg_unmark_end(struct scatterlist *sg) (__flags), NULL, NULL) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) +/* + * See also commit 3942d2991852 ("mm/slab_common: allow NULL cache pointer in + * kmem_cache_destroy()") # v4.3. + */ +static inline void kmem_cache_destroy_backport(struct kmem_cache *s) +{ + if (s) + kmem_cache_destroy(s); +} + +#define kmem_cache_destroy kmem_cache_destroy_backport +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) && \ !(LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 52) && \ LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)) && \