public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: mtdchar: handle a block that should be marked bad that already is
@ 2017-08-31 19:35 Uwe Kleine-König
  2017-08-31 20:08 ` Boris Brezillon
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2017-08-31 19:35 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen
  Cc: kernel, linux-mtd

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;
+
 		return mtd_block_markbad(mtd, offs);
 		break;
 	}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: mtdchar: handle a block that should be marked bad that already is
  2017-08-31 19:35 [PATCH] mtd: mtdchar: handle a block that should be marked bad that already is Uwe Kleine-König
@ 2017-08-31 20:08 ` Boris Brezillon
  0 siblings, 0 replies; 2+ messages in thread
From: Boris Brezillon @ 2017-08-31 20:08 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	Cyrille Pitchen, kernel, linux-mtd

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?

>  	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-31 20:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-31 19:35 [PATCH] mtd: mtdchar: handle a block that should be marked bad that already is Uwe Kleine-König
2017-08-31 20:08 ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox