Skip to contentSkip to conversation

vhost: return error instead of NULL on create

RFC In review Keith Busch 1 participant 1 message Feb 26, 2025

Subsystems (5)
x86 KVM virtio core KVM x86 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

RFC 1/2 vhost: return error instead of NULL on create

From: Keith Busch <[email protected]>

Let callers distinguish why the vhost create failed.

---
 arch/x86/kvm/mmu/mmu.c | 2 +-
 drivers/vhost/vhost.c  | 2 +-
 kernel/vhost_task.c    | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu/mmu.c +1 -1
index d4ac4a1f8b81b..18ca1ea6dc240 100644
@@ -7471,7 +7471,7 @@ static void kvm_mmu_start_lpage_recovery(struct once *once)
 				      kvm_nx_huge_page_recovery_worker_kill,
 				      kvm, "kvm-nx-lpage-recovery");
 
-	if (!nx_thread)
+	if (IS_ERR(nx_thread))
 		return;
 
 	vhost_task_start(nx_thread);
drivers/vhost/vhost.c +1 -1
index 9ac25d08f473e..61dd19c7f99f1 100644
@@ -666,7 +666,7 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev)
 
 	vtsk = vhost_task_create(vhost_run_work_list, vhost_worker_killed,
 				 worker, name);
-	if (!vtsk)
+	if (!IS_ERR(vtsk))
 		goto free_worker;
 
 	mutex_init(&worker->mutex);
kernel/vhost_task.c +2 -2
index 8800f5acc0071..2ef2e1b800916 100644
@@ -133,7 +133,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),
 
 	vtsk = kzalloc(sizeof(*vtsk), GFP_KERNEL);
 	if (!vtsk)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	init_completion(&vtsk->exited);
 	mutex_init(&vtsk->exit_mutex);
 	vtsk->data = arg;
@@ -145,7 +145,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),
 	tsk = copy_process(NULL, 0, NUMA_NO_NODE, &args);
 	if (IS_ERR(tsk)) {
 		kfree(vtsk);
-		return NULL;
+		return ERR_PTR(PTR_ERR(tsk));
 	}
 
 	vtsk->task = tsk;
Signature · 1 line
2.43.5