[PATCH] mtd: mtdchar: handle a block that should be marked bad that already is

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Thu Aug 31 12:35:43 PDT 2017


Otherwise at least /sys/class/mtd/mtdX/bad_blocks is increased each time
the same block is remarked as bad.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
 drivers/mtd/mtdchar.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 3568294d4854..049496a1d7a5 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -916,6 +916,11 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
 
 		if (copy_from_user(&offs, argp, sizeof(loff_t)))
 			return -EFAULT;
+
+		if (mtd_block_isbad(mtd, offs))
+			/* already done */
+			return 0;
+
 		return mtd_block_markbad(mtd, offs);
 		break;
 	}
-- 
2.11.0




More information about the linux-mtd mailing list