summaryrefslogtreecommitdiff
path: root/drivers/mtd
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2021-05-14 17:27:15 +0300
committerMiquel Raynal <miquel.raynal@bootlin.com>2021-05-26 10:41:43 +0200
commitc3c8c051df3ee5042dd91593593a8b0e008f4c85 (patch)
tree7368d2077ca6acf1befa4f70a0c40b6bb74a8834 /drivers/mtd
parentbc8e157fdb466536557b97b6c0df6d7b46a2b91b (diff)
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: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Michael Walle <michael@walle.cc> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/YJ6Iw3iNvGycAWV6@mwanda
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/mtdcore.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index ffa46ccea0cf..ce514305f8f7 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -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)
{
- struct otp_info *info = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ struct otp_info *info;
ssize_t size = 0;
unsigned int i;
size_t retlen;
int ret;
+ info = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
if (is_user)
ret = mtd_get_user_prot_info(mtd, PAGE_SIZE, &retlen, info);
else