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

Message ID 20170831193543.27543-1-u.kleine-koenig@pengutronix.de
State New
Delegated to: Brian Norris
Headers show
Series
  • mtd: mtdchar: handle a block that should be marked bad that already is
Related show

Commit Message

Uwe Kleine-König Aug. 31, 2017, 7:35 p.m.
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@pengutronix.de>
---
 drivers/mtd/mtdchar.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Boris Brezillon Aug. 31, 2017, 8:08 p.m. | #1
On Thu, 31 Aug 2017 21:35:43 +0200
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:

> 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@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;
> +

Just a matter of taste but I prefer to have comments before the
conditional branch and not inside it, especially when the code chunk is
not enclosed into brackets.

>  		return mtd_block_markbad(mtd, offs);
>  		break;

This break statement is redundant. Care to send another patch to fix
that?

>  	}

Patch

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;
 	}