]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nvmem: brcm_nvram: Add check for kzalloc
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Fri, 27 Jan 2023 10:40:06 +0000 (10:40 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Feb 2023 10:28:19 +0000 (11:28 +0100)
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 <jiasheng@iscas.ac.cn>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230127104015.23839-2-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/brcm_nvram.c

index 4441daa2096517a6d2bb421871e1ef0eb1250057..7bd65fc2942e2934bbdf1b50ff48fe87c9ce70c3 100644 (file)
@@ -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';