linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amdkfd: fix a potential NULL pointer dereference
@ 2019-09-18 16:30 Allen Pais
  2019-09-19 20:38 ` Kuehling, Felix
  0 siblings, 1 reply; 2+ messages in thread
From: Allen Pais @ 2019-09-18 16:30 UTC (permalink / raw)
  To: dri-devel; +Cc: airlied, linux-kernel, amd-gfx, daniel

alloc_workqueue is not checked for errors and as a result,
a potential NULL dereference could occur.

Signed-off-by: Allen Pais <allen.pais@oracle.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c b/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
index c56ac47..caa82a8 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
@@ -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);
-- 
1.9.1


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

* Re: [PATCH] drm/amdkfd: fix a potential NULL pointer dereference
  2019-09-18 16:30 [PATCH] drm/amdkfd: fix a potential NULL pointer dereference Allen Pais
@ 2019-09-19 20:38 ` Kuehling, Felix
  0 siblings, 0 replies; 2+ messages in thread
From: Kuehling, Felix @ 2019-09-19 20:38 UTC (permalink / raw)
  To: Allen Pais, dri-devel; +Cc: airlied, daniel, linux-kernel, amd-gfx

On 2019-09-18 12:30 p.m., Allen Pais wrote:
> alloc_workqueue is not checked for errors and as a result,
> a potential NULL dereference could occur.
>
> Signed-off-by: Allen Pais <allen.pais@oracle.com>
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c b/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
> index c56ac47..caa82a8 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
> @@ -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.

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


> +	}
>   	spin_lock_init(&kfd->interrupt_lock);
>   
>   	INIT_WORK(&kfd->interrupt_work, interrupt_wq);

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

end of thread, other threads:[~2019-09-19 20:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-18 16:30 [PATCH] drm/amdkfd: fix a potential NULL pointer dereference Allen Pais
2019-09-19 20:38 ` Kuehling, Felix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).