accel/amdxdna: Guard management mailbox channel cleanup against NULL pointer
Lizhi Hou
maintainerPATCH 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.
--- drivers/accel/amdxdna/amdxdna_mailbox.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/accel/amdxdna/amdxdna_mailbox.c +6 -0
@@ -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
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_channhas already been destroyed.
Quoted 8 lines
Add NULL checks to
xdna_mailbox_free_channel()andxdna_mailbox_stop_channel()so the cleanup path safely returns instead of dereferencing a NULL mailbox channel pointer.Fixes b87f920b9344 ("accel/amdxdna: Support hardware mailbox")Signed-off-by Max Zhen <[email protected]>Signed-off-by Lizhi Hou <[email protected]>---
Quoted 27 lines
drivers/accel/amdxdna/amdxdna_mailbox.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/accel/amdxdna/amdxdna_mailbox.c +6
-0@@ -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);
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_channhas already been destroyed.Quoted 8 lines
Add NULL checks to
xdna_mailbox_free_channel()andxdna_mailbox_stop_channel()so the cleanup path safely returns instead of dereferencing a NULL mailbox channel pointer.Fixes b87f920b9344 ("accel/amdxdna: Support hardware mailbox")Signed-off-by Max Zhen <[email protected]>Signed-off-by Lizhi Hou <[email protected]>---
Reviewed-by Mario Limonciello (AMD) <[email protected]>Quoted 26 lines
drivers/accel/amdxdna/amdxdna_mailbox.c| 6 ++++++1 file changed, 6 insertions(+)drivers/accel/amdxdna/amdxdna_mailbox.c +5
-0@@ -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);