linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmem: check for allocation failure
@ 2022-03-01  8:11 Dan Carpenter
  2022-03-01  9:18 ` Rafał Miłecki
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-03-01  8:11 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Rafał Miłecki, linux-kernel, kernel-janitors

Check for if the kcalloc() fails.

Fixes: 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/nvmem/brcm_nvram.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
index 439f00b9eef6..c80af8a31eba 100644
--- a/drivers/nvmem/brcm_nvram.c
+++ b/drivers/nvmem/brcm_nvram.c
@@ -95,6 +95,8 @@ static int brcm_nvram_parse(struct brcm_nvram *priv)
 	len = le32_to_cpu(header.len);
 
 	data = kcalloc(1, len, GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
 	memcpy_fromio(data, priv->base, len);
 	data[len - 1] = '\0';
 
-- 
2.20.1


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

* Re: [PATCH] nvmem: check for allocation failure
  2022-03-01  8:11 [PATCH] nvmem: check for allocation failure Dan Carpenter
@ 2022-03-01  9:18 ` Rafał Miłecki
  2022-03-01 18:10 ` Christophe JAILLET
  2022-04-29  9:33 ` Srinivas Kandagatla
  2 siblings, 0 replies; 5+ messages in thread
From: Rafał Miłecki @ 2022-03-01  9:18 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Srinivas Kandagatla, linux-kernel, kernel-janitors

On 2022-03-01 09:11, Dan Carpenter wrote:
> Check for if the kcalloc() fails.
> 
> Fixes: 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM 
> cells")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thank you!

Acked-by: Rafał Miłecki <rafal@milecki.pl>

> ---
>  drivers/nvmem/brcm_nvram.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
> index 439f00b9eef6..c80af8a31eba 100644
> --- a/drivers/nvmem/brcm_nvram.c
> +++ b/drivers/nvmem/brcm_nvram.c
> @@ -95,6 +95,8 @@ static int brcm_nvram_parse(struct brcm_nvram *priv)
>  	len = le32_to_cpu(header.len);
> 
>  	data = kcalloc(1, len, GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
>  	memcpy_fromio(data, priv->base, len);
>  	data[len - 1] = '\0';

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

* Re: [PATCH] nvmem: check for allocation failure
  2022-03-01  8:11 [PATCH] nvmem: check for allocation failure Dan Carpenter
  2022-03-01  9:18 ` Rafał Miłecki
@ 2022-03-01 18:10 ` Christophe JAILLET
  2022-04-29  9:33 ` Srinivas Kandagatla
  2 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2022-03-01 18:10 UTC (permalink / raw)
  To: Dan Carpenter, Srinivas Kandagatla
  Cc: Rafał Miłecki, linux-kernel, kernel-janitors

Le 01/03/2022 à 09:11, Dan Carpenter a écrit :
> Check for if the kcalloc() fails.
> 
> Fixes: 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>   drivers/nvmem/brcm_nvram.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
> index 439f00b9eef6..c80af8a31eba 100644
> --- a/drivers/nvmem/brcm_nvram.c
> +++ b/drivers/nvmem/brcm_nvram.c
> @@ -95,6 +95,8 @@ static int brcm_nvram_parse(struct brcm_nvram *priv)
>   	len = le32_to_cpu(header.len);
>   
>   	data = kcalloc(1, len, GFP_KERNEL);

Hi,

just for my understanding, why
   - kcalloc(1, len) and not kzalloc(len)?
   - kcalloc and not kmalloc_array, since data is fully filled just the 
line below by memcpy_fromio()?

CJ

> +	if (!data)
> +		return -ENOMEM;
>   	memcpy_fromio(data, priv->base, len);
>   	data[len - 1] = '\0';
>   


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

* Re: [PATCH] nvmem: check for allocation failure
  2022-03-01  8:11 [PATCH] nvmem: check for allocation failure Dan Carpenter
  2022-03-01  9:18 ` Rafał Miłecki
  2022-03-01 18:10 ` Christophe JAILLET
@ 2022-04-29  9:33 ` Srinivas Kandagatla
  2022-04-29  9:50   ` Dan Carpenter
  2 siblings, 1 reply; 5+ messages in thread
From: Srinivas Kandagatla @ 2022-04-29  9:33 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Rafał Miłecki, linux-kernel, kernel-janitors



On 01/03/2022 08:11, Dan Carpenter wrote:
> Check for if the kcalloc() fails.
> 
> Fixes: 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---


Applied after changing subject line to "nvmem: brcm_nvram: check for 
allocation failure"


--srini
>   drivers/nvmem/brcm_nvram.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
> index 439f00b9eef6..c80af8a31eba 100644
> --- a/drivers/nvmem/brcm_nvram.c
> +++ b/drivers/nvmem/brcm_nvram.c
> @@ -95,6 +95,8 @@ static int brcm_nvram_parse(struct brcm_nvram *priv)
>   	len = le32_to_cpu(header.len);
>   
>   	data = kcalloc(1, len, GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
>   	memcpy_fromio(data, priv->base, len);
>   	data[len - 1] = '\0';
>   

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

* Re: [PATCH] nvmem: check for allocation failure
  2022-04-29  9:33 ` Srinivas Kandagatla
@ 2022-04-29  9:50   ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-04-29  9:50 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Rafał Miłecki, linux-kernel, kernel-janitors

On Fri, Apr 29, 2022 at 10:33:44AM +0100, Srinivas Kandagatla wrote:
> 
> 
> On 01/03/2022 08:11, Dan Carpenter wrote:
> > Check for if the kcalloc() fails.
> > 
> > Fixes: 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> 
> 
> Applied after changing subject line to "nvmem: brcm_nvram: check for
> allocation failure"
> 

Thanks.  Not sure why I didn't copy and paste the whole prefix.

regards,
dan carpenter


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

end of thread, other threads:[~2022-04-29  9:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01  8:11 [PATCH] nvmem: check for allocation failure Dan Carpenter
2022-03-01  9:18 ` Rafał Miłecki
2022-03-01 18:10 ` Christophe JAILLET
2022-04-29  9:33 ` Srinivas Kandagatla
2022-04-29  9:50   ` Dan Carpenter

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).