2022-03-01 10:03:32

by Dan Carpenter

[permalink] [raw]
Subject: [PATCH] nvmem: check for allocation failure

Check for if the kcalloc() fails.

Fixes: 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
Signed-off-by: Dan Carpenter <[email protected]>
---
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


2022-03-01 10:57:02

by Rafał Miłecki

[permalink] [raw]
Subject: Re: [PATCH] nvmem: check for allocation failure

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 <[email protected]>

Thank you!

Acked-by: Rafał Miłecki <[email protected]>

> ---
> 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';

2022-03-01 18:44:53

by Christophe JAILLET

[permalink] [raw]
Subject: Re: [PATCH] nvmem: check for allocation failure

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 <[email protected]>
> ---
> 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';
>

2022-04-29 12:21:06

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH] nvmem: check for allocation failure



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 <[email protected]>
> ---


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';
>

2022-05-02 16:19:55

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] nvmem: check for allocation failure

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 <[email protected]>
> > ---
>
>
> 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