Skip to contentSkip to conversation

accel/amdxdna: Guard management mailbox channel cleanup against NULL pointer

PATCH In review Lizhi Hou 2 participants 3 messages Apr 16 – Apr 17

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: Guard management mailbox channel cleanup against NULL pointer

From: Max Zhen <[email protected]>

The management mailbox channel cleanup helpers can be called from error handling paths when mgmt_chann has already been destroyed.

Add NULL checks to xdna_mailbox_free_channel() and xdna_mailbox_stop_channel() so the cleanup path safely returns instead of dereferencing a NULL mailbox channel pointer.

Fixes b87f920b9344 ("accel/amdxdna: Support hardware mailbox")
---
 drivers/accel/amdxdna/amdxdna_mailbox.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/accel/amdxdna/amdxdna_mailbox.c +6 -0
index 336e5e77f18a..37771bdb24a1 100644
@@ -496,6 +496,9 @@ struct mailbox_channel *xdna_mailbox_alloc_channel(struct mailbox *mb)
 
 void xdna_mailbox_free_channel(struct mailbox_channel *mb_chann)
 {
+	if (!mb_chann)
+		return;
+
 	destroy_workqueue(mb_chann->work_q);
 	kfree(mb_chann);
 }
@@ -542,6 +545,9 @@ void xdna_mailbox_stop_channel(struct mailbox_channel *mb_chann)
 	struct mailbox_msg *mb_msg;
 	unsigned long msg_id;
 
+	if (!mb_chann)
+		return;
+
 	/* Disable an irq and wait. This might sleep. */
 	free_irq(mb_chann->msix_irq, mb_chann);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Lizhi Hou

From: Max Zhen <[email protected]>

The management mailbox channel cleanup helpers can be called from error handling paths when mgmt_chann has already been destroyed.

Quoted 8 lines

Add NULL checks to xdna_mailbox_free_channel() and xdna_mailbox_stop_channel() so the cleanup path safely returns instead of dereferencing a NULL mailbox channel pointer.

Fixes b87f920b9344 ("accel/amdxdna: Support hardware mailbox")

---

Quoted 27 lines
  drivers/accel/amdxdna/amdxdna_mailbox.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/accel/amdxdna/amdxdna_mailbox.c +6 -0
index 336e5e77f18a..37771bdb24a1 100644
@@ -496,6 +496,9 @@ struct mailbox_channel *xdna_mailbox_alloc_channel(struct mailbox *mb)
 
  void xdna_mailbox_free_channel(struct mailbox_channel *mb_chann)
  {
+	if (!mb_chann)
+		return;
+
  	destroy_workqueue(mb_chann->work_q);
  	kfree(mb_chann);
  }
@@ -542,6 +545,9 @@ void xdna_mailbox_stop_channel(struct mailbox_channel *mb_chann)
  	struct mailbox_msg *mb_msg;
  	unsigned long msg_id;
 
+	if (!mb_chann)
+		return;
+
  	/* Disable an irq and wait. This might sleep. */
  	free_irq(mb_chann->msix_irq, mb_chann);
 
author maintainer Applied
#2 lore raw

Applied to drm-misc-next

Quoted 44 lines · Mario Limonciello
Quoted 5 lines · Lizhi Hou

From: Max Zhen <[email protected]>

The management mailbox channel cleanup helpers can be called from error handling paths when mgmt_chann has already been destroyed.

Quoted 8 lines

Add NULL checks to xdna_mailbox_free_channel() and xdna_mailbox_stop_channel() so the cleanup path safely returns instead of dereferencing a NULL mailbox channel pointer.

Fixes b87f920b9344 ("accel/amdxdna: Support hardware mailbox")

---

Quoted 26 lines

  drivers/accel/amdxdna/amdxdna_mailbox.c | 6 ++++++

  1 file changed, 6 insertions(+)
drivers/accel/amdxdna/amdxdna_mailbox.c +5 -0
index 336e5e77f18a..37771bdb24a1 100644
@@ -496,6 +496,9 @@ struct mailbox_channel 
 *xdna_mailbox_alloc_channel(struct mailbox *mb)
     void xdna_mailbox_free_channel(struct mailbox_channel *mb_chann)
   {
+    if (!mb_chann)
+        return;
+
       destroy_workqueue(mb_chann->work_q);
       kfree(mb_chann);
   }
@@ -542,6 +545,9 @@ void xdna_mailbox_stop_channel(struct 
 mailbox_channel *mb_chann)
       struct mailbox_msg *mb_msg;
       unsigned long msg_id;
   +    if (!mb_chann)
+        return;
+
       /* Disable an irq and wait. This might sleep. */
       free_irq(mb_chann->msix_irq, mb_chann);