Skip to contentSkip to conversation

Add calls to mutex_destroy in virtio_balloon and virtio_mem

PATCH In review Maurice Hieronymus 2 participants 6 messages Nov 23, 2025 – Nov 24, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add calls to mutex_destroy in virtio_balloon and virtio_mem

In [1] it is pointed out that each mutex_init call should have a corresponding call to mutex_destroy; otherwise, it is considered a bug.

This patch adds the calls to mutex_destroy in virtio_balloon as well as virtio_mem.

Maurice Hieronymus (2):
virtio-balloon: Destroy mutex before freeing virtio_balloon
virtio-mem: Destroy mutex before freeing virtio_mem

 drivers/virtio/virtio_balloon.c | 2 ++
 drivers/virtio/virtio_mem.c     | 2 ++
 2 files changed, 4 insertions(+)

base-commit: d13f3ac64efb868d09cb2726b1e84929afe90235

Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/2 virtio-balloon: Destroy mutex before freeing virtio_balloon

Add a call to mutex_destroy in the error code path as well as in the virtballoon_remove code path.

---
 drivers/virtio/virtio_balloon.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/virtio/virtio_balloon.c +2 -0
index 1b93d8c64361..078b87720a0d 100644
@@ -1094,6 +1094,7 @@ static int virtballoon_probe(struct virtio_device *vdev)
 out_del_vqs:
 	vdev->config->del_vqs(vdev);
 out_free_vb:
+	mutex_destroy(&vb->balloon_lock);
 	kfree(vb);
 out:
 	return err;
@@ -1138,6 +1139,7 @@ static void virtballoon_remove(struct virtio_device *vdev)
 	}
 
 	remove_common(vb);
+	mutex_destroy(&vb->balloon_lock);
 	kfree(vb);
 }
 
Signature · 1 line
2.50.1
#3 lore raw

PATCH 2/2 virtio-mem: Destroy mutex before freeing virtio_mem

In reply to Maurice Hieronymus

Add a call to mutex_destroy in the error code path as well as in the virtio_mem_remove code path.

---
 drivers/virtio/virtio_mem.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/virtio/virtio_mem.c +2 -0
index 1688ecd69a04..8107988dcb05 100644
@@ -2975,6 +2975,7 @@ static int virtio_mem_probe(struct virtio_device *vdev)
 out_del_vq:
 	vdev->config->del_vqs(vdev);
 out_free_vm:
+	mutex_destroy(&vm->hotplug_mutex);
 	kfree(vm);
 	vdev->priv = NULL;
 
@@ -3067,6 +3068,7 @@ static void virtio_mem_remove(struct virtio_device *vdev)
 	virtio_reset_device(vdev);
 	vdev->config->del_vqs(vdev);
 
+	mutex_destroy(&vm->hotplug_mutex);
 	kfree(vm);
 	vdev->priv = NULL;
 }
Signature · 1 line
2.50.1
#5 lore raw
In reply to Maurice Hieronymus
Quoted 2 lines · Maurice Hieronymus

In [1] it is pointed out that each mutex_init call should have a corresponding call to mutex_destroy; otherwise, it is considered a bug.

IIUC, mutex_destroy() only ever does something during with CONFIG_DEBUG_MUTEXES. And there, it performs mostly sanity checks (so it's not some missed memory freeing etc).

I wonder whether we should still ad Fixes tags.

Signature · 3 lines
Cheers

David