sgi-gru: fix null pointer dereference on failed kzalloc
diff mbox series

Message ID 1431505186-22628-1-git-send-email-colin.king@canonical.com
State New, archived
Headers show
Series
  • sgi-gru: fix null pointer dereference on failed kzalloc
Related show

Commit Message

Colin King May 13, 2015, 8:19 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

static analysis from smatch found a potential null dereference:

drivers/misc/sgi-gru/grutlbpurge.c:320 gru_register_mmu_notifier() error:
  potential null dereference 'gms'.  (kzalloc returns null)

bail out with -ENOMEM rather than falling through and printing a debug
message that trips a null dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/misc/sgi-gru/grutlbpurge.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Dimitri Sivanich May 21, 2015, 1:51 a.m. UTC | #1
Acked-by: Dimitri Sivanich <sivanich@sgi.com>

On Wed, May 13, 2015 at 09:19:46AM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> static analysis from smatch found a potential null dereference:
> 
> drivers/misc/sgi-gru/grutlbpurge.c:320 gru_register_mmu_notifier() error:
>   potential null dereference 'gms'.  (kzalloc returns null)
> 
> bail out with -ENOMEM rather than falling through and printing a debug
> message that trips a null dereference.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/misc/sgi-gru/grutlbpurge.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/misc/sgi-gru/grutlbpurge.c b/drivers/misc/sgi-gru/grutlbpurge.c
> index 2129274..1239800 100644
> --- a/drivers/misc/sgi-gru/grutlbpurge.c
> +++ b/drivers/misc/sgi-gru/grutlbpurge.c
> @@ -315,6 +315,8 @@ struct gru_mm_struct *gru_register_mmu_notifier(void)
>  			err = __mmu_notifier_register(&gms->ms_notifier, current->mm);
>  			if (err)
>  				goto error;
> +		} else {
> +			return ERR_PTR(-ENOMEM);
>  		}
>  	}
>  	gru_dbg(grudev, "gms %p, refcnt %d\n", gms,
> -- 
> 2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

diff --git a/drivers/misc/sgi-gru/grutlbpurge.c b/drivers/misc/sgi-gru/grutlbpurge.c
index 2129274..1239800 100644
--- a/drivers/misc/sgi-gru/grutlbpurge.c
+++ b/drivers/misc/sgi-gru/grutlbpurge.c
@@ -315,6 +315,8 @@  struct gru_mm_struct *gru_register_mmu_notifier(void)
 			err = __mmu_notifier_register(&gms->ms_notifier, current->mm);
 			if (err)
 				goto error;
+		} else {
+			return ERR_PTR(-ENOMEM);
 		}
 	}
 	gru_dbg(grudev, "gms %p, refcnt %d\n", gms,