From: Jiasheng Jiang Date: Fri, 27 Jan 2023 10:40:06 +0000 (+0000) Subject: nvmem: brcm_nvram: Add check for kzalloc X-Git-Tag: baikal/aarch64/sdk6.1~62 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=d01eeebc742cc19999816ec7b6bedc7d075b9820;p=kernel.git nvmem: brcm_nvram: Add check for kzalloc commit b0576ade3aaf24b376ea1a4406ae138e2a22b0c0 upstream. Add the check for the return value of kzalloc in order to avoid NULL pointer dereference. Fixes: f45130fa14f0 ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells") Cc: stable@vger.kernel.org Signed-off-by: Jiasheng Jiang Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20230127104015.23839-2-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c index 4441daa209651..7bd65fc2942e2 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';