All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Bigler <stefan.bigler@keymile.com>
To: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Cc: linux-mtd@lists.infradead.org, Michael Cashwell <mboards@prograde.net>
Subject: Re: [PATCH] mtd: fix race in cfi_cmdset_0001 driver
Date: Mon, 07 Feb 2011 17:41:26 +0100	[thread overview]
Message-ID: <4D5020B6.8010903@keymile.com> (raw)
In-Reply-To: <1297094831-10330-1-git-send-email-Joakim.Tjernlund@transmode.se>

Am 02/07/2011 05:07 PM, schrieb Joakim Tjernlund:
> As inval_cache_and_wait_for_operation() drop and reclaim the lock
> to invalidate the cache, some other thread may suspend the operation
> before reaching the for(;;) loop. Therefore the loop must start with
> checking the chip->state before reading status from the chip.
>
> Signed-off-by: Joakim Tjernlund<Joakim.Tjernlund@transmode.se>
> ---
>
>   David, I think this should go to Linus asap.
>   Stefan and Michael, would be great if you could
>   reply with a Acked-By: too.
>
>   drivers/mtd/chips/cfi_cmdset_0001.c |   43 ++++++++++++++++++-----------------
>   1 files changed, 22 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
> index e89f2d0..9772a62 100644
> --- a/drivers/mtd/chips/cfi_cmdset_0001.c
> +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
> @@ -1245,10 +1245,32 @@ static int inval_cache_and_wait_for_operation(
>   	sleep_time = chip_op_time / 2;
>
>   	for (;;) {
> +		if (chip->state != chip_state) {
> +			/* Someone's suspended the operation: sleep */
> +			DECLARE_WAITQUEUE(wait, current);
> +			set_current_state(TASK_UNINTERRUPTIBLE);
> +			add_wait_queue(&chip->wq,&wait);
> +			mutex_unlock(&chip->mutex);
> +			schedule();
> +			remove_wait_queue(&chip->wq,&wait);
> +			mutex_lock(&chip->mutex);
> +			continue;
> +		}
> +
>   		status = map_read(map, cmd_adr);
>   		if (map_word_andequal(map, status, status_OK, status_OK))
>   			break;
>
> +		if (chip->erase_suspended&&  chip_state == FL_ERASING)  {
> +			/* Erase suspend occured while sleep: reset timeout */
> +			timeo = reset_timeo;
> +			chip->erase_suspended = 0;
> +		}
> +		if (chip->write_suspended&&  chip_state == FL_WRITING)  {
> +			/* Write suspend occured while sleep: reset timeout */
> +			timeo = reset_timeo;
> +			chip->write_suspended = 0;
> +		}
>   		if (!timeo) {
>   			map_write(map, CMD(0x70), cmd_adr);
>   			chip->state = FL_STATUS;
> @@ -1272,27 +1294,6 @@ static int inval_cache_and_wait_for_operation(
>   			timeo--;
>   		}
>   		mutex_lock(&chip->mutex);
> -
> -		while (chip->state != chip_state) {
> -			/* Someone's suspended the operation: sleep */
> -			DECLARE_WAITQUEUE(wait, current);
> -			set_current_state(TASK_UNINTERRUPTIBLE);
> -			add_wait_queue(&chip->wq,&wait);
> -			mutex_unlock(&chip->mutex);
> -			schedule();
> -			remove_wait_queue(&chip->wq,&wait);
> -			mutex_lock(&chip->mutex);
> -		}
> -		if (chip->erase_suspended&&  chip_state == FL_ERASING)  {
> -			/* Erase suspend occured while sleep: reset timeout */
> -			timeo = reset_timeo;
> -			chip->erase_suspended = 0;
> -		}
> -		if (chip->write_suspended&&  chip_state == FL_WRITING)  {
> -			/* Write suspend occured while sleep: reset timeout */
> -			timeo = reset_timeo;
> -			chip->write_suspended = 0;
> -		}
>   	}
>
>   	/* Done and happy. */

Acked-by: Stefan Bigler<stefan.bigler@keymile.com>

Thanks!

Stefan

  reply	other threads:[~2011-02-07 16:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-07 16:07 [PATCH] mtd: fix race in cfi_cmdset_0001 driver Joakim Tjernlund
2011-02-07 16:41 ` Stefan Bigler [this message]
2011-02-07 17:20 ` Michael Cashwell
2011-02-11 14:02 ` Artem Bityutskiy
2011-02-11 14:46   ` Joakim Tjernlund
2011-02-11 14:50     ` Artem Bityutskiy
2011-02-11 14:54       ` Joakim Tjernlund
2011-02-11 14:55 ` Artem Bityutskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D5020B6.8010903@keymile.com \
    --to=stefan.bigler@keymile.com \
    --cc=Joakim.Tjernlund@transmode.se \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mboards@prograde.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.