[PATCH 5/6] mtd: maps: pcmciamtd: Add reference counter to set_vpp()
Paul Parsons
lost.distance at yahoo.com
Wed Mar 7 09:13:41 EST 2012
This patch is part of a set which fixes unnecessary flash erase and write errors
resulting from the MTD CFI driver turning off vpp while an erase is in progress.
This patch allows pcmciamtd_set_vpp() calls to be nested by adding a reference
counter.
Signed-off-by: Paul Parsons <lost.distance at yahoo.com>
---
diff -uprN clean-3.3-rc6/drivers/mtd/maps/pcmciamtd.c linux-3.3-rc6/drivers/mtd/maps/pcmciamtd.c
--- clean-3.3-rc6/drivers/mtd/maps/pcmciamtd.c 2012-03-04 01:08:09.000000000 +0000
+++ linux-3.3-rc6/drivers/mtd/maps/pcmciamtd.c 2012-03-06 16:38:29.795134347 +0000
@@ -295,13 +295,24 @@ static void pcmcia_copy_to(struct map_in
}
+static DEFINE_SPINLOCK(pcmcia_vpp_lock);
+static int pcmcia_vpp_refcnt;
static void pcmciamtd_set_vpp(struct map_info *map, int on)
{
struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
struct pcmcia_device *link = dev->p_dev;
+ unsigned long flags;
pr_debug("dev = %p on = %d vpp = %d\n\n", dev, on, dev->vpp);
- pcmcia_fixup_vpp(link, on ? dev->vpp : 0);
+ spin_lock_irqsave(&pcmcia_vpp_lock, flags);
+ if (on) {
+ if (++pcmcia_vpp_refcnt == 1) /* first nested 'on' */
+ pcmcia_fixup_vpp(link, dev->vpp);
+ } else {
+ if (--pcmcia_vpp_refcnt == 0) /* last nested 'off' */
+ pcmcia_fixup_vpp(link, 0);
+ }
+ spin_unlock_irqrestore(&pcmcia_vpp_lock, flags);
}
More information about the linux-mtd
mailing list