Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: otp: clean up on error in mtd_otp_nvmem_add()

Smatch complains that these error paths are missing cleanup:

drivers/mtd/mtdcore.c:983 mtd_otp_nvmem_add()
warn: missing unwind goto?

This needs to call nvmem_unregister(mtd->otp_user_nvmem) before
returning.

Fixes: 3b270fac8443 ("mtd: otp: Put factory OTP/NVRAM into the entropy pool")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/fe7ef901-9571-4c6e-a40e-449046efe2c6@moroto.mountain

authored by

Dan Carpenter and committed by
Miquel Raynal
cefa1aaa a5e393c1

+5 -3
+5 -3
drivers/mtd/mtdcore.c
··· 975 975 void *otp; 976 976 977 977 otp = kmalloc(size, GFP_KERNEL); 978 - if (!otp) 979 - return -ENOMEM; 978 + if (!otp) { 979 + err = -ENOMEM; 980 + goto err; 981 + } 980 982 err = mtd_nvmem_fact_otp_reg_read(mtd, 0, otp, size); 981 983 if (err < 0) { 982 984 kfree(otp); 983 - return err; 985 + goto err; 984 986 } 985 987 add_device_randomness(otp, err); 986 988 kfree(otp);