[PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page

Ahmad Fatoum ahmad at a3f.at
Sun Feb 28 14:07:05 EST 2021


Until this is fixed, add a comment and have the driver return with an
error instead of crashing on null pointer dereference if it's mapped to
zero.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
Cc: Rouven Czerwinski <r.czerwinski at pengutronix.de>
---
 drivers/mtd/nor/cfi_flash.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mtd/nor/cfi_flash.c b/drivers/mtd/nor/cfi_flash.c
index 225b03ec3d23..ba0bd1b4ebdd 100644
--- a/drivers/mtd/nor/cfi_flash.c
+++ b/drivers/mtd/nor/cfi_flash.c
@@ -969,6 +969,10 @@ static int cfi_probe_one(struct flash_info *info, int num)
 		return PTR_ERR(iores);
 	info->base = IOMEM(iores->start);
 
+	/* TODO: either remap memory region or disable NULL pointer page */
+	if (IS_ENABLED(CONFIG_MMU) && iores->start == 0)
+		return -EPERM;
+
 	ret = flash_detect_size(info);
 	if (ret) {
 		dev_warn(info->dev, "## Unknown FLASH on Bank at 0x%p - Size = 0x%08lx = %ld MB\n",
-- 
2.30.0




More information about the barebox mailing list