Skip to contentSkip to conversation

nvmem: check for allocation failure

PATCH Superseded Dan Carpenter 4 participants 5 messages Mar 1, 2022 – Apr 29, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: check for allocation failure

Check for if the kcalloc() fails.

Fixes 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
---
 drivers/nvmem/brcm_nvram.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvmem/brcm_nvram.c +2 -0
index 439f00b9eef6..c80af8a31eba 100644
@@ -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';
 
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

Check for if the kcalloc() fails.

Fixes 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")

Thank you!

Quoted 16 lines
---
 drivers/nvmem/brcm_nvram.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvmem/brcm_nvram.c +2 -0
index 439f00b9eef6..c80af8a31eba 100644
@@ -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 lore raw
In reply to Dan Carpenter

Le 01/03/2022 à 09:11, Dan Carpenter a écrit :

Quoted 13 lines

Check for if the kcalloc() fails.

Fixes 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
---
  drivers/nvmem/brcm_nvram.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/nvmem/brcm_nvram.c +0 -0
index 439f00b9eef6..c80af8a31eba 100644

drivers/nvmem/brcm_nvram.c static int brcm_nvram_parse(struct brcm_nvram *priv) · line 97

Quoted 3 lines
drivers/nvmem/brcm_nvram.c +0 -0
@@ -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

Quoted 5 lines
drivers/nvmem/brcm_nvram.c +2 -0
+	if (!data)
+		return -ENOMEM;
  	memcpy_fromio(data, priv->base, len);
  	data[len - 1] = '\0';
 
#3 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

Check for if the kcalloc() fails.

Fixes 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")

---

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

--srini

Quoted 16 lines
  drivers/nvmem/brcm_nvram.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/nvmem/brcm_nvram.c +2 -0
index 439f00b9eef6..c80af8a31eba 100644
@@ -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';
 
#4 lore raw
Quoted 5 lines · Srinivas Kandagatla
Quoted 2 lines · Dan Carpenter

Check for if the kcalloc() fails.

Quoted 8 lines
Quoted 3 lines
Fixes 299dc152721f ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")

---

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