diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2023-06-06 16:29:31 +0200 |
---|---|---|
committer | Miquel Raynal <miquel.raynal@bootlin.com> | 2023-06-09 17:27:16 +0200 |
commit | 3b270fac84439cbd036c98e189d17f2bc3c85494 (patch) | |
tree | 6fb481a0c389f65bd66745929bb91936028dd446 /drivers/mtd/mtdcore.c | |
parent | mtd: mtdpart: Drop useless LIST_HEAD (diff) | |
download | linux-3b270fac84439cbd036c98e189d17f2bc3c85494.tar.xz linux-3b270fac84439cbd036c98e189d17f2bc3c85494.zip |
mtd: otp: Put factory OTP/NVRAM into the entropy pool
The factory OTP, if supported, contains factory-programmed
information such as typically the serial number or production
week for the chip.
As this is device-unique information, submit it into the
system entropy pool.
This does not count as improvement of the entropy as such
but in practice it makes it a bit more random to mix in these
numbers.
Cc: Michael Walle <michael@walle.cc>
Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230606142931.3721374-1-linus.walleij@linaro.org
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r-- | drivers/mtd/mtdcore.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 60670b2f70b9..abf4cb58a8ab 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -23,6 +23,7 @@ #include <linux/idr.h> #include <linux/backing-dev.h> #include <linux/gfp.h> +#include <linux/random.h> #include <linux/slab.h> #include <linux/reboot.h> #include <linux/leds.h> @@ -966,6 +967,24 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd) } if (size > 0) { + /* + * The factory OTP contains thing such as a unique serial + * number and is small, so let's read it out and put it + * into the entropy pool. + */ + void *otp; + + otp = kmalloc(size, GFP_KERNEL); + if (!otp) + return -ENOMEM; + err = mtd_nvmem_fact_otp_reg_read(mtd, 0, otp, size); + if (err < 0) { + kfree(otp); + return err; + } + add_device_randomness(otp, err); + kfree(otp); + nvmem = mtd_otp_nvmem_register(mtd, "factory-otp", size, mtd_nvmem_fact_otp_reg_read); if (IS_ERR(nvmem)) { |