Skip to contentSkip to conversation

kthread: Fix return value on kzalloc() failure in kthread_affine_preferred()

PATCH Applied Yu-Chun Lin 2 participants 2 messages Jan 30, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kthread: Fix return value on kzalloc() failure in kthread_affine_preferred()

kthread_affine_preferred() incorrectly returns 0 instead of -ENOMEM when kzalloc() fails. Return 'ret' to ensure the correct error code is propagated.

Fixes 4d13f4304fa4 ("kthread: Implement preferred affinity")
---
 kernel/kthread.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kthread.c +2 -2
index 4005b13ebd7f..5dc5b0d7238e 100644
@@ -859,7 +859,7 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)
 	struct kthread *kthread = to_kthread(p);
 	cpumask_var_t affinity;
 	unsigned long flags;
-	int ret;
+	int ret = 0;
 
 	if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE) || kthread->started) {
 		WARN_ON(1);
@@ -892,7 +892,7 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)
 out:
 	free_cpumask_var(affinity);
 
-	return 0;
+	return ret;
 }
 
 /*
Signature · 1 line
2.43.0