Commit 8ae664184c45def51ff0b61d4bd6c6671db6cb4f

Authored by Stefani Seibold
Committed by David Woodhouse
1 parent b8664b3762

mtd: change struct flchip_shared spinlock locking into mutex

This patch prevent to schedule while atomic by changing the
flchip_shared spinlock into a mutex. This should be save since no atomic
path will use this lock.

It was suggested by Arnd Bergmann and Vasiliy Kulikov.

Signed-off-by: Stefani Seibold <stefani@seibold.net>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

Showing 3 changed files with 21 additions and 21 deletions Side-by-side Diff

drivers/mtd/chips/cfi_cmdset_0001.c
... ... @@ -720,7 +720,7 @@
720 720 chip = &newcfi->chips[0];
721 721 for (i = 0; i < cfi->numchips; i++) {
722 722 shared[i].writing = shared[i].erasing = NULL;
723   - spin_lock_init(&shared[i].lock);
  723 + mutex_init(&shared[i].lock);
724 724 for (j = 0; j < numparts; j++) {
725 725 *chip = cfi->chips[i];
726 726 chip->start += j << partshift;
... ... @@ -889,7 +889,7 @@
889 889 */
890 890 struct flchip_shared *shared = chip->priv;
891 891 struct flchip *contender;
892   - spin_lock(&shared->lock);
  892 + mutex_lock(&shared->lock);
893 893 contender = shared->writing;
894 894 if (contender && contender != chip) {
895 895 /*
... ... @@ -902,7 +902,7 @@
902 902 * get_chip returns success we're clear to go ahead.
903 903 */
904 904 ret = mutex_trylock(&contender->mutex);
905   - spin_unlock(&shared->lock);
  905 + mutex_unlock(&shared->lock);
906 906 if (!ret)
907 907 goto retry;
908 908 mutex_unlock(&chip->mutex);
... ... @@ -917,7 +917,7 @@
917 917 mutex_unlock(&contender->mutex);
918 918 return ret;
919 919 }
920   - spin_lock(&shared->lock);
  920 + mutex_lock(&shared->lock);
921 921  
922 922 /* We should not own chip if it is already
923 923 * in FL_SYNCING state. Put contender and retry. */
... ... @@ -933,7 +933,7 @@
933 933 * on this chip. Sleep. */
934 934 if (mode == FL_ERASING && shared->erasing
935 935 && shared->erasing->oldstate == FL_ERASING) {
936   - spin_unlock(&shared->lock);
  936 + mutex_unlock(&shared->lock);
937 937 set_current_state(TASK_UNINTERRUPTIBLE);
938 938 add_wait_queue(&chip->wq, &wait);
939 939 mutex_unlock(&chip->mutex);
... ... @@ -947,7 +947,7 @@
947 947 shared->writing = chip;
948 948 if (mode == FL_ERASING)
949 949 shared->erasing = chip;
950   - spin_unlock(&shared->lock);
  950 + mutex_unlock(&shared->lock);
951 951 }
952 952 ret = chip_ready(map, chip, adr, mode);
953 953 if (ret == -EAGAIN)
... ... @@ -962,7 +962,7 @@
962 962  
963 963 if (chip->priv) {
964 964 struct flchip_shared *shared = chip->priv;
965   - spin_lock(&shared->lock);
  965 + mutex_lock(&shared->lock);
966 966 if (shared->writing == chip && chip->oldstate == FL_READY) {
967 967 /* We own the ability to write, but we're done */
968 968 shared->writing = shared->erasing;
... ... @@ -970,7 +970,7 @@
970 970 /* give back ownership to who we loaned it from */
971 971 struct flchip *loaner = shared->writing;
972 972 mutex_lock(&loaner->mutex);
973   - spin_unlock(&shared->lock);
  973 + mutex_unlock(&shared->lock);
974 974 mutex_unlock(&chip->mutex);
975 975 put_chip(map, loaner, loaner->start);
976 976 mutex_lock(&chip->mutex);
977 977  
... ... @@ -988,11 +988,11 @@
988 988 * Don't let the switch below mess things up since
989 989 * we don't have ownership to resume anything.
990 990 */
991   - spin_unlock(&shared->lock);
  991 + mutex_unlock(&shared->lock);
992 992 wake_up(&chip->wq);
993 993 return;
994 994 }
995   - spin_unlock(&shared->lock);
  995 + mutex_unlock(&shared->lock);
996 996 }
997 997  
998 998 switch(chip->oldstate) {
drivers/mtd/lpddr/lpddr_cmds.c
... ... @@ -98,7 +98,7 @@
98 98 numchips = lpddr->numchips / lpddr->qinfo->HWPartsNum;
99 99 for (i = 0; i < numchips; i++) {
100 100 shared[i].writing = shared[i].erasing = NULL;
101   - spin_lock_init(&shared[i].lock);
  101 + mutex_init(&shared[i].lock);
102 102 for (j = 0; j < lpddr->qinfo->HWPartsNum; j++) {
103 103 *chip = lpddr->chips[i];
104 104 chip->start += j << lpddr->chipshift;
... ... @@ -217,7 +217,7 @@
217 217 */
218 218 struct flchip_shared *shared = chip->priv;
219 219 struct flchip *contender;
220   - spin_lock(&shared->lock);
  220 + mutex_lock(&shared->lock);
221 221 contender = shared->writing;
222 222 if (contender && contender != chip) {
223 223 /*
... ... @@ -230,7 +230,7 @@
230 230 * get_chip returns success we're clear to go ahead.
231 231 */
232 232 ret = mutex_trylock(&contender->mutex);
233   - spin_unlock(&shared->lock);
  233 + mutex_unlock(&shared->lock);
234 234 if (!ret)
235 235 goto retry;
236 236 mutex_unlock(&chip->mutex);
... ... @@ -245,7 +245,7 @@
245 245 mutex_unlock(&contender->mutex);
246 246 return ret;
247 247 }
248   - spin_lock(&shared->lock);
  248 + mutex_lock(&shared->lock);
249 249  
250 250 /* We should not own chip if it is already in FL_SYNCING
251 251 * state. Put contender and retry. */
... ... @@ -261,7 +261,7 @@
261 261 Must sleep in such a case. */
262 262 if (mode == FL_ERASING && shared->erasing
263 263 && shared->erasing->oldstate == FL_ERASING) {
264   - spin_unlock(&shared->lock);
  264 + mutex_unlock(&shared->lock);
265 265 set_current_state(TASK_UNINTERRUPTIBLE);
266 266 add_wait_queue(&chip->wq, &wait);
267 267 mutex_unlock(&chip->mutex);
... ... @@ -275,7 +275,7 @@
275 275 shared->writing = chip;
276 276 if (mode == FL_ERASING)
277 277 shared->erasing = chip;
278   - spin_unlock(&shared->lock);
  278 + mutex_unlock(&shared->lock);
279 279 }
280 280  
281 281 ret = chip_ready(map, chip, mode);
... ... @@ -348,7 +348,7 @@
348 348 {
349 349 if (chip->priv) {
350 350 struct flchip_shared *shared = chip->priv;
351   - spin_lock(&shared->lock);
  351 + mutex_lock(&shared->lock);
352 352 if (shared->writing == chip && chip->oldstate == FL_READY) {
353 353 /* We own the ability to write, but we're done */
354 354 shared->writing = shared->erasing;
... ... @@ -356,7 +356,7 @@
356 356 /* give back the ownership */
357 357 struct flchip *loaner = shared->writing;
358 358 mutex_lock(&loaner->mutex);
359   - spin_unlock(&shared->lock);
  359 + mutex_unlock(&shared->lock);
360 360 mutex_unlock(&chip->mutex);
361 361 put_chip(map, loaner);
362 362 mutex_lock(&chip->mutex);
363 363  
... ... @@ -374,11 +374,11 @@
374 374 * Don't let the switch below mess things up since
375 375 * we don't have ownership to resume anything.
376 376 */
377   - spin_unlock(&shared->lock);
  377 + mutex_unlock(&shared->lock);
378 378 wake_up(&chip->wq);
379 379 return;
380 380 }
381   - spin_unlock(&shared->lock);
  381 + mutex_unlock(&shared->lock);
382 382 }
383 383  
384 384 switch (chip->oldstate) {
include/linux/mtd/flashchip.h
... ... @@ -92,7 +92,7 @@
92 92 /* This is used to handle contention on write/erase operations
93 93 between partitions of the same physical chip. */
94 94 struct flchip_shared {
95   - spinlock_t lock;
  95 + struct mutex lock;
96 96 struct flchip *writing;
97 97 struct flchip *erasing;
98 98 };