All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] drm/amdkfd: Check for potential null return of kmalloc_array()
@ 2022-03-24  8:26 ` QintaoShen
  0 siblings, 0 replies; 3+ messages in thread
From: QintaoShen @ 2022-03-24  8:26 UTC (permalink / raw)
  To: Felix.Kuehling; +Cc: amd-gfx, linux-kernel, QintaoShen

As the kmalloc_array() may return null, the 'event_waiters[i].wait' would lead to null-pointer dereference.
Therefore, it is better to check the return value of kmalloc_array() to avoid this confusion.

Signed-off-by: QintaoShen <unSimple1993@163.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_events.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
index deeccce..64f4a51 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
@@ -749,6 +749,8 @@ static struct kfd_event_waiter *alloc_event_waiters(uint32_t num_events)
 	event_waiters = kmalloc_array(num_events,
 					sizeof(struct kfd_event_waiter),
 					GFP_KERNEL);
+	if (!event_waiters)
+		return NULL;
 
 	for (i = 0; (event_waiters) && (i < num_events) ; i++) {
 		init_wait(&event_waiters[i].wait);
-- 
2.7.4


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

* [PATCH v1] drm/amdkfd: Check for potential null return of kmalloc_array()
@ 2022-03-24  8:26 ` QintaoShen
  0 siblings, 0 replies; 3+ messages in thread
From: QintaoShen @ 2022-03-24  8:26 UTC (permalink / raw)
  To: Felix.Kuehling; +Cc: QintaoShen, linux-kernel, amd-gfx

As the kmalloc_array() may return null, the 'event_waiters[i].wait' would lead to null-pointer dereference.
Therefore, it is better to check the return value of kmalloc_array() to avoid this confusion.

Signed-off-by: QintaoShen <unSimple1993@163.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_events.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
index deeccce..64f4a51 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
@@ -749,6 +749,8 @@ static struct kfd_event_waiter *alloc_event_waiters(uint32_t num_events)
 	event_waiters = kmalloc_array(num_events,
 					sizeof(struct kfd_event_waiter),
 					GFP_KERNEL);
+	if (!event_waiters)
+		return NULL;
 
 	for (i = 0; (event_waiters) && (i < num_events) ; i++) {
 		init_wait(&event_waiters[i].wait);
-- 
2.7.4


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

* Re: [PATCH v1] drm/amdkfd: Check for potential null return of kmalloc_array()
  2022-03-24  8:26 ` QintaoShen
  (?)
@ 2022-03-24 19:51 ` Alex Deucher
  -1 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2022-03-24 19:51 UTC (permalink / raw)
  To: QintaoShen; +Cc: Kuehling, Felix, LKML, amd-gfx list

Applied.  Thanks!

Alex

On Thu, Mar 24, 2022 at 9:46 AM QintaoShen <unSimple1993@163.com> wrote:
>
> As the kmalloc_array() may return null, the 'event_waiters[i].wait' would lead to null-pointer dereference.
> Therefore, it is better to check the return value of kmalloc_array() to avoid this confusion.
>
> Signed-off-by: QintaoShen <unSimple1993@163.com>
> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_events.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> index deeccce..64f4a51 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> @@ -749,6 +749,8 @@ static struct kfd_event_waiter *alloc_event_waiters(uint32_t num_events)
>         event_waiters = kmalloc_array(num_events,
>                                         sizeof(struct kfd_event_waiter),
>                                         GFP_KERNEL);
> +       if (!event_waiters)
> +               return NULL;
>
>         for (i = 0; (event_waiters) && (i < num_events) ; i++) {
>                 init_wait(&event_waiters[i].wait);
> --
> 2.7.4
>

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

end of thread, other threads:[~2022-03-24 19:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  8:26 [PATCH v1] drm/amdkfd: Check for potential null return of kmalloc_array() QintaoShen
2022-03-24  8:26 ` QintaoShen
2022-03-24 19:51 ` Alex Deucher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.