Re: [PATCH] nvmem: brcm_nvram: Add check for kzalloc

From: Srinivas Kandagatla
Date: Mon Dec 12 2022 - 05:40:28 EST




On 12/12/2022 03:39, Jiasheng Jiang wrote:
Add the check for the return value of kzalloc in order to avoid
NULL pointer dereference.

Fixes: 6e977eaa8280 ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
Signed-off-by: Jiasheng Jiang <jiasheng@xxxxxxxxxxx>

Applied thanks,

--srini
---
drivers/nvmem/brcm_nvram.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
index 4441daa20965..7bd65fc2942e 100644
--- a/drivers/nvmem/brcm_nvram.c
+++ b/drivers/nvmem/brcm_nvram.c
@@ -97,6 +97,9 @@ static int brcm_nvram_parse(struct brcm_nvram *priv)
len = le32_to_cpu(header.len);
data = kzalloc(len, GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
memcpy_fromio(data, priv->base, len);
data[len - 1] = '\0';