drm/amdkfd: fix a potential NULL pointer dereference
Subsystems (3)
PATCH 1/1 drm/amdkfd: fix a potential NULL pointer dereference
alloc_workqueue is not checked for errors and as a result, a potential NULL dereference could occur.
--- drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +5 -0
@@ -62,6 +62,11 @@ int kfd_interrupt_init(struct kfd_dev *kfd) } kfd->ih_wq =alloc_workqueue ("KFD IH" ,WQ_HIGHPRI ,1 ); +if (unlikely (!kfd->ih_wq)) { +fifo_free (&kfd->ih_fifo); +dev_err (kfd_chardev (),"Failed to allocate KFD IH workqueue\n" ); +return kfd->ih_wq; + }spin_lock_init (&kfd->interrupt_lock);INIT_WORK (&kfd->interrupt_work, interrupt_wq);
Signature · 1 line
1.9.1
Kuehling, Felix
maintainerQuoted 13 lines · Allen Pais
alloc_workqueueis not checked for errors and as a result, a potential NULL dereference could occur.Signed-off-by Allen Pais <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c int kfd_interrupt_init(struct kfd_dev *kfd) · line 66
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +2
-0@@ -62,6 +62,11 @@ int kfd_interrupt_init(struct kfd_dev *kfd) } kfd->ih_wq =alloc_workqueue ("KFD IH" ,WQ_HIGHPRI ,1 ); +if (unlikely (!kfd->ih_wq)) { +fifo_free (&kfd->ih_fifo);
This does not compile. I think this should be kfifo_free.
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c int kfd_interrupt_init(struct kfd_dev *kfd) · line 68
Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +2
-0+dev_err (kfd_chardev (),"Failed to allocate KFD IH workqueue\n" ); +return kfd->ih_wq;
This throws a compiler warning "return makes integer from pointer without a cast". What's worse, kfd->ih_wq is NULL here and kfd_interrupt_init returns 0 to mean success, so returning a NULL pointer is definitely not what you want here. This function should return a negative error code on failure. I propose -ENOMEM.
I'm going to apply your patch with those fixes.
Regards,
Felix
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c int kfd_interrupt_init(struct kfd_dev *kfd) · line 72
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +1
-0+ }spin_lock_init (&kfd->interrupt_lock);INIT_WORK (&kfd->interrupt_work, interrupt_wq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel