[PATCH v2 6/8] MTD: xway: fix nand locking

Boris Brezillon boris.brezillon at free-electrons.com
Sun Jun 19 06:04:24 PDT 2016


On Sun, 19 Jun 2016 14:56:03 +0200
Hauke Mehrtens <hauke at hauke-m.de> wrote:

> On 06/19/2016 02:53 PM, Richard Weinberger wrote:
> > Am 19.06.2016 um 14:41 schrieb Boris Brezillon:  
> >> On Sat, 18 Jun 2016 21:14:10 +0200
> >> Hauke Mehrtens <hauke at hauke-m.de> wrote:
> >>  
> >>> From: John Crispin <john at phrozen.org>
> >>>
> >>> The external Bus Unit (EBU) can control different flash devices, but
> >>> these NAND flash commands have to be atomic and should not be
> >>> interrupted in between. Lock the EBU from the beginning of the command
> >>> till the end by moving the lock to the chip select.
> >>>
> >>> Signed-off-by: John Crispin <john at phrozen.org>
> >>> Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
> >>> ---
> >>>  drivers/mtd/nand/xway_nand.c | 20 ++++----------------
> >>>  1 file changed, 4 insertions(+), 16 deletions(-)
> >>>
> >>> diff --git a/drivers/mtd/nand/xway_nand.c b/drivers/mtd/nand/xway_nand.c
> >>> index 1511bdb..064ee41 100644
> >>> --- a/drivers/mtd/nand/xway_nand.c
> >>> +++ b/drivers/mtd/nand/xway_nand.c
> >>> @@ -94,13 +94,16 @@ static void xway_reset_chip(struct nand_chip *chip)
> >>>  
> >>>  static void xway_select_chip(struct mtd_info *mtd, int chip)
> >>>  {
> >>> +	static unsigned long csflags;  
> > 
> > Why is csflags static? AFAICT this is racy then...  
> 
> Because the lock is taken when the chip is selected and it is unlocked
> when the chip select is deactivated again. This should be part of the
> private driver struct.

static here means that you have a single instance for all callers. This
is working fine because you have a lock at the NAND core level, and you
only have a single controller, but you definitely don't want to rely on
that in the long run.

In any case, using a static variable to save irqflags sounds like a
bad idea. This should always be saved on the stack to limit the time
spent in spin_lock_irqsave()/spin_unlock_irqrestored() critical
sections.
Which bring us back to my first question: are you sure you want to
disable irqs for such a long/unbounded time?



More information about the linux-mtd mailing list