mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem
@ 2025-11-23 17:57 Maurice Hieronymus
  2025-11-23 17:57 ` [PATCH 1/2] virtio-balloon: Destroy mutex before freeing virtio_balloon Maurice Hieronymus
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Maurice Hieronymus @ 2025-11-23 17:57 UTC (permalink / raw)
  To: david, mst, jasowang; +Cc: virtualization, linux-kernel, 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.

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

Link: https://lists.kernelnewbies.org/pipermail/kernelnewbies/2025-November/023493.html [1]

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
-- 
2.50.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] virtio-balloon: Destroy mutex before freeing virtio_balloon
  2025-11-23 17:57 [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem Maurice Hieronymus
@ 2025-11-23 17:57 ` Maurice Hieronymus
  2025-11-24  9:43   ` David Hildenbrand (Red Hat)
  2025-11-23 17:57 ` [PATCH 2/2] virtio-mem: Destroy mutex before freeing virtio_mem Maurice Hieronymus
  2025-11-24  9:42 ` [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem David Hildenbrand (Red Hat)
  2 siblings, 1 reply; 6+ messages in thread
From: Maurice Hieronymus @ 2025-11-23 17:57 UTC (permalink / raw)
  To: david, mst, jasowang; +Cc: virtualization, linux-kernel, Maurice Hieronymus

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

Signed-off-by: Maurice Hieronymus <mhi@mailbox.org>
---
 drivers/virtio/virtio_balloon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 1b93d8c64361..078b87720a0d 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -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);
 }
 
-- 
2.50.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] virtio-mem: Destroy mutex before freeing virtio_mem
  2025-11-23 17:57 [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem Maurice Hieronymus
  2025-11-23 17:57 ` [PATCH 1/2] virtio-balloon: Destroy mutex before freeing virtio_balloon Maurice Hieronymus
@ 2025-11-23 17:57 ` Maurice Hieronymus
  2025-11-24  9:43   ` David Hildenbrand (Red Hat)
  2025-11-24  9:42 ` [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem David Hildenbrand (Red Hat)
  2 siblings, 1 reply; 6+ messages in thread
From: Maurice Hieronymus @ 2025-11-23 17:57 UTC (permalink / raw)
  To: david, mst, jasowang; +Cc: virtualization, linux-kernel, Maurice Hieronymus

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

Signed-off-by: Maurice Hieronymus <mhi@mailbox.org>
---
 drivers/virtio/virtio_mem.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index 1688ecd69a04..8107988dcb05 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -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;
 }
-- 
2.50.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem
  2025-11-23 17:57 [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem Maurice Hieronymus
  2025-11-23 17:57 ` [PATCH 1/2] virtio-balloon: Destroy mutex before freeing virtio_balloon Maurice Hieronymus
  2025-11-23 17:57 ` [PATCH 2/2] virtio-mem: Destroy mutex before freeing virtio_mem Maurice Hieronymus
@ 2025-11-24  9:42 ` David Hildenbrand (Red Hat)
  2 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Red Hat) @ 2025-11-24  9:42 UTC (permalink / raw)
  To: Maurice Hieronymus, mst, jasowang; +Cc: virtualization, linux-kernel

On 11/23/25 18:57, Maurice Hieronymus wrote:
> 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.

-- 
Cheers

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] virtio-balloon: Destroy mutex before freeing virtio_balloon
  2025-11-23 17:57 ` [PATCH 1/2] virtio-balloon: Destroy mutex before freeing virtio_balloon Maurice Hieronymus
@ 2025-11-24  9:43   ` David Hildenbrand (Red Hat)
  0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Red Hat) @ 2025-11-24  9:43 UTC (permalink / raw)
  To: Maurice Hieronymus, mst, jasowang; +Cc: virtualization, linux-kernel

On 11/23/25 18:57, Maurice Hieronymus wrote:
> Add a call to mutex_destroy in the error code path as well as in the
> virtballoon_remove code path.
> 
> Signed-off-by: Maurice Hieronymus <mhi@mailbox.org>

Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>

-- 
Cheers

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] virtio-mem: Destroy mutex before freeing virtio_mem
  2025-11-23 17:57 ` [PATCH 2/2] virtio-mem: Destroy mutex before freeing virtio_mem Maurice Hieronymus
@ 2025-11-24  9:43   ` David Hildenbrand (Red Hat)
  0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Red Hat) @ 2025-11-24  9:43 UTC (permalink / raw)
  To: Maurice Hieronymus, mst, jasowang; +Cc: virtualization, linux-kernel

On 11/23/25 18:57, Maurice Hieronymus wrote:
> Add a call to mutex_destroy in the error code path as well as in the
> virtio_mem_remove code path.
> 
> Signed-off-by: Maurice Hieronymus <mhi@mailbox.org>
> ---

Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>

-- 
Cheers

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-24  9:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-23 17:57 [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem Maurice Hieronymus
2025-11-23 17:57 ` [PATCH 1/2] virtio-balloon: Destroy mutex before freeing virtio_balloon Maurice Hieronymus
2025-11-24  9:43   ` David Hildenbrand (Red Hat)
2025-11-23 17:57 ` [PATCH 2/2] virtio-mem: Destroy mutex before freeing virtio_mem Maurice Hieronymus
2025-11-24  9:43   ` David Hildenbrand (Red Hat)
2025-11-24  9:42 ` [PATCH 0/2] Add calls to mutex_destroy in virtio_balloon and virtio_mem David Hildenbrand (Red Hat)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®