Commit c3c8c051 authored by Dan Carpenter's avatar Dan Carpenter Committed by Miquel Raynal

mtd: core: Potential NULL dereference in mtd_otp_size()

If kmalloc() fails then it could lead to a NULL dereference.  Check and
return -ENOMEM on error.

Fixes: 4b361cfa ("mtd: core: add OTP nvmem provider support")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarMichael Walle <michael@walle.cc>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/YJ6Iw3iNvGycAWV6@mwanda
parent bc8e157f
...@@ -779,12 +779,16 @@ static void mtd_set_dev_defaults(struct mtd_info *mtd) ...@@ -779,12 +779,16 @@ static void mtd_set_dev_defaults(struct mtd_info *mtd)
static ssize_t mtd_otp_size(struct mtd_info *mtd, bool is_user) static ssize_t mtd_otp_size(struct mtd_info *mtd, bool is_user)
{ {
struct otp_info *info = kmalloc(PAGE_SIZE, GFP_KERNEL); struct otp_info *info;
ssize_t size = 0; ssize_t size = 0;
unsigned int i; unsigned int i;
size_t retlen; size_t retlen;
int ret; int ret;
info = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!info)
return -ENOMEM;
if (is_user) if (is_user)
ret = mtd_get_user_prot_info(mtd, PAGE_SIZE, &retlen, info); ret = mtd_get_user_prot_info(mtd, PAGE_SIZE, &retlen, info);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment