]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mtd: core: Potential NULL dereference in mtd_otp_size()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 14 May 2021 14:27:15 +0000 (17:27 +0300)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Wed, 26 May 2021 08:41:43 +0000 (10:41 +0200)
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
drivers/mtd/mtdcore.c

index ffa46ccea0cf0f92682597d92e2e94187e524be4..ce514305f8f756e6e763b3cde8f4f57e4d4726ef 100644 (file)
@@ -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