[patch V2 05/17] posix-timers: Remove SLAB_PANIC from kmem cache

Thomas Gleixner posted 17 patches 9 months, 3 weeks ago
There is a newer version of this series
[patch V2 05/17] posix-timers: Remove SLAB_PANIC from kmem cache
Posted by Thomas Gleixner 9 months, 3 weeks ago
There is no need to panic when the posix-timer kmem_cache can't be
created. timer_create() will fail with -ENOMEM and that's it.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V2: New patch
---
 kernel/time/posix-timers.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -243,9 +243,8 @@ static int posix_get_hrtimer_res(clockid
 
 static __init int init_posix_timers(void)
 {
-	posix_timers_cache = kmem_cache_create("posix_timers_cache",
-					sizeof(struct k_itimer), 0,
-					SLAB_PANIC | SLAB_ACCOUNT, NULL);
+	posix_timers_cache = kmem_cache_create("posix_timers_cache", sizeof(struct k_itimer), 0,
+					       SLAB_ACCOUNT, NULL);
 	return 0;
 }
 __initcall(init_posix_timers);
@@ -371,8 +370,12 @@ static struct pid *good_sigevent(sigeven
 
 static struct k_itimer *alloc_posix_timer(void)
 {
-	struct k_itimer *tmr = kmem_cache_zalloc(posix_timers_cache, GFP_KERNEL);
+	struct k_itimer *tmr;
 
+	if (unlikely(!posix_timers_cache))
+		return NULL;
+
+	tmr = kmem_cache_zalloc(posix_timers_cache, GFP_KERNEL);
 	if (!tmr)
 		return tmr;
Re: [patch V2 05/17] posix-timers: Remove SLAB_PANIC from kmem cache
Posted by Frederic Weisbecker 9 months, 2 weeks ago
Le Sun, Mar 02, 2025 at 08:36:51PM +0100, Thomas Gleixner a écrit :
> There is no need to panic when the posix-timer kmem_cache can't be
> created. timer_create() will fail with -ENOMEM and that's it.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>