diff mbox

libnvdimm, btt: check memory allocation failure

Message ID 20170827063034.4802-1-christophe.jaillet@wanadoo.fr (mailing list archive)
State New, archived
Headers show

Commit Message

Christophe JAILLET Aug. 27, 2017, 6:30 a.m. UTC
Check memory allocation failures and return -ENOMEM in such cases, as
already done few lines below for another memory allocation.

This avoids NULL pointers dereference.

Fixes: 14e494542636 ("libnvdimm, btt: BTT updates for UEFI 2.7 format")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/nvdimm/btt.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Vishal Verma Aug. 29, 2017, 10:50 p.m. UTC | #1
On 08/27, Christophe JAILLET wrote:
> Check memory allocation failures and return -ENOMEM in such cases, as
> already done few lines below for another memory allocation.
> 
> This avoids NULL pointers dereference.
> 
> Fixes: 14e494542636 ("libnvdimm, btt: BTT updates for UEFI 2.7 format")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/nvdimm/btt.c | 2 ++
>  1 file changed, 2 insertions(+)

Looks good, thank you.
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>

> 
> diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
> index 60491641a8d6..607184ebcfbf 100644
> --- a/drivers/nvdimm/btt.c
> +++ b/drivers/nvdimm/btt.c
> @@ -1431,6 +1431,8 @@ int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns)
>  	}
>  
>  	btt_sb = devm_kzalloc(&nd_btt->dev, sizeof(*btt_sb), GFP_KERNEL);
> +	if (!btt_sb)
> +		return -ENOMEM;
>  
>  	/*
>  	 * If this returns < 0, that is ok as it just means there wasn't
> -- 
> 2.11.0
>
diff mbox

Patch

diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index 60491641a8d6..607184ebcfbf 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -1431,6 +1431,8 @@  int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns)
 	}
 
 	btt_sb = devm_kzalloc(&nd_btt->dev, sizeof(*btt_sb), GFP_KERNEL);
+	if (!btt_sb)
+		return -ENOMEM;
 
 	/*
 	 * If this returns < 0, that is ok as it just means there wasn't