1 From 2ccd3ea4bd9e62a348023bbf98988d01b6b5d7db Mon Sep 17 00:00:00 2001
2 From: Stefani Seibold <stefani@seibold.net>
3 Date: Thu, 5 Aug 2010 09:19:26 +0200
4 Subject: [PATCH 2/2] mtd: change struct flchip_shared spinlock locking into mutex
6 This patch prevent to schedule while atomic by changing the
7 flchip_shared spinlock into a mutex. This should be save since no atomic
8 path will use this lock.
10 It was suggested by Arnd Bergmann and Vasiliy Kulikov.
12 Signed-off-by: Stefani Seibold <stefani@seibold.net>
13 Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
16 drivers/mtd/chips/cfi_cmdset_0001.c | 20 ++++++++++----------
17 include/linux/mtd/flashchip.h | 2 +-
18 2 files changed, 11 insertions(+), 11 deletions(-)
20 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
21 index c9c3517..892a862 100644
22 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
23 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
24 @@ -687,7 +687,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
25 chip = &newcfi->chips[0];
26 for (i = 0; i < cfi->numchips; i++) {
27 shared[i].writing = shared[i].erasing = NULL;
28 - spin_lock_init(&shared[i].lock);
29 + mutex_init(&shared[i].lock);
30 for (j = 0; j < numparts; j++) {
31 *chip = cfi->chips[i];
32 chip->start += j << partshift;
33 @@ -856,7 +856,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
35 struct flchip_shared *shared = chip->priv;
36 struct flchip *contender;
37 - spin_lock(&shared->lock);
38 + mutex_lock(&shared->lock);
39 contender = shared->writing;
40 if (contender && contender != chip) {
42 @@ -869,7 +869,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
43 * get_chip returns success we're clear to go ahead.
45 ret = mutex_trylock(&contender->mutex);
46 - spin_unlock(&shared->lock);
47 + mutex_unlock(&shared->lock);
50 mutex_unlock(&chip->mutex);
51 @@ -884,7 +884,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
52 mutex_unlock(&contender->mutex);
55 - spin_lock(&shared->lock);
56 + mutex_lock(&shared->lock);
58 /* We should not own chip if it is already
59 * in FL_SYNCING state. Put contender and retry. */
60 @@ -900,7 +900,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
61 * on this chip. Sleep. */
62 if (mode == FL_ERASING && shared->erasing
63 && shared->erasing->oldstate == FL_ERASING) {
64 - spin_unlock(&shared->lock);
65 + mutex_unlock(&shared->lock);
66 set_current_state(TASK_UNINTERRUPTIBLE);
67 add_wait_queue(&chip->wq, &wait);
68 mutex_unlock(&chip->mutex);
69 @@ -914,7 +914,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
70 shared->writing = chip;
71 if (mode == FL_ERASING)
72 shared->erasing = chip;
73 - spin_unlock(&shared->lock);
74 + mutex_unlock(&shared->lock);
76 ret = chip_ready(map, chip, adr, mode);
78 @@ -929,7 +929,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
81 struct flchip_shared *shared = chip->priv;
82 - spin_lock(&shared->lock);
83 + mutex_lock(&shared->lock);
84 if (shared->writing == chip && chip->oldstate == FL_READY) {
85 /* We own the ability to write, but we're done */
86 shared->writing = shared->erasing;
87 @@ -937,7 +937,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
88 /* give back ownership to who we loaned it from */
89 struct flchip *loaner = shared->writing;
90 mutex_lock(&loaner->mutex);
91 - spin_unlock(&shared->lock);
92 + mutex_unlock(&shared->lock);
93 mutex_unlock(&chip->mutex);
94 put_chip(map, loaner, loaner->start);
95 mutex_lock(&chip->mutex);
96 @@ -955,11 +955,11 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
97 * Don't let the switch below mess things up since
98 * we don't have ownership to resume anything.
100 - spin_unlock(&shared->lock);
101 + mutex_unlock(&shared->lock);
105 - spin_unlock(&shared->lock);
106 + mutex_unlock(&shared->lock);
109 switch(chip->oldstate) {
110 diff --git a/include/linux/mtd/flashchip.h b/include/linux/mtd/flashchip.h
111 index bfc2f1a..fa6db00 100644
112 --- a/include/linux/mtd/flashchip.h
113 +++ b/include/linux/mtd/flashchip.h
114 @@ -83,7 +83,7 @@ struct flchip {
115 /* This is used to handle contention on write/erase operations
116 between partitions of the same physical chip. */
117 struct flchip_shared {
120 struct flchip *writing;
121 struct flchip *erasing;