Skip to content

Commit 8ae6641

Browse files
sstefaniDavid Woodhouse
authored andcommitted
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>
1 parent b8664b3 commit 8ae6641

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

drivers/mtd/chips/cfi_cmdset_0001.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
720720
chip = &newcfi->chips[0];
721721
for (i = 0; i < cfi->numchips; i++) {
722722
shared[i].writing = shared[i].erasing = NULL;
723-
spin_lock_init(&shared[i].lock);
723+
mutex_init(&shared[i].lock);
724724
for (j = 0; j < numparts; j++) {
725725
*chip = cfi->chips[i];
726726
chip->start += j << partshift;
@@ -889,7 +889,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
889889
*/
890890
struct flchip_shared *shared = chip->priv;
891891
struct flchip *contender;
892-
spin_lock(&shared->lock);
892+
mutex_lock(&shared->lock);
893893
contender = shared->writing;
894894
if (contender && contender != chip) {
895895
/*
@@ -902,7 +902,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
902902
* get_chip returns success we're clear to go ahead.
903903
*/
904904
ret = mutex_trylock(&contender->mutex);
905-
spin_unlock(&shared->lock);
905+
mutex_unlock(&shared->lock);
906906
if (!ret)
907907
goto retry;
908908
mutex_unlock(&chip->mutex);
@@ -917,7 +917,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
917917
mutex_unlock(&contender->mutex);
918918
return ret;
919919
}
920-
spin_lock(&shared->lock);
920+
mutex_lock(&shared->lock);
921921

922922
/* We should not own chip if it is already
923923
* in FL_SYNCING state. Put contender and retry. */
@@ -933,7 +933,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
933933
* on this chip. Sleep. */
934934
if (mode == FL_ERASING && shared->erasing
935935
&& shared->erasing->oldstate == FL_ERASING) {
936-
spin_unlock(&shared->lock);
936+
mutex_unlock(&shared->lock);
937937
set_current_state(TASK_UNINTERRUPTIBLE);
938938
add_wait_queue(&chip->wq, &wait);
939939
mutex_unlock(&chip->mutex);
@@ -947,7 +947,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
947947
shared->writing = chip;
948948
if (mode == FL_ERASING)
949949
shared->erasing = chip;
950-
spin_unlock(&shared->lock);
950+
mutex_unlock(&shared->lock);
951951
}
952952
ret = chip_ready(map, chip, adr, mode);
953953
if (ret == -EAGAIN)
@@ -962,15 +962,15 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
962962

963963
if (chip->priv) {
964964
struct flchip_shared *shared = chip->priv;
965-
spin_lock(&shared->lock);
965+
mutex_lock(&shared->lock);
966966
if (shared->writing == chip && chip->oldstate == FL_READY) {
967967
/* We own the ability to write, but we're done */
968968
shared->writing = shared->erasing;
969969
if (shared->writing && shared->writing != chip) {
970970
/* give back ownership to who we loaned it from */
971971
struct flchip *loaner = shared->writing;
972972
mutex_lock(&loaner->mutex);
973-
spin_unlock(&shared->lock);
973+
mutex_unlock(&shared->lock);
974974
mutex_unlock(&chip->mutex);
975975
put_chip(map, loaner, loaner->start);
976976
mutex_lock(&chip->mutex);
@@ -988,11 +988,11 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
988988
* Don't let the switch below mess things up since
989989
* we don't have ownership to resume anything.
990990
*/
991-
spin_unlock(&shared->lock);
991+
mutex_unlock(&shared->lock);
992992
wake_up(&chip->wq);
993993
return;
994994
}
995-
spin_unlock(&shared->lock);
995+
mutex_unlock(&shared->lock);
996996
}
997997

998998
switch(chip->oldstate) {

drivers/mtd/lpddr/lpddr_cmds.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
9898
numchips = lpddr->numchips / lpddr->qinfo->HWPartsNum;
9999
for (i = 0; i < numchips; i++) {
100100
shared[i].writing = shared[i].erasing = NULL;
101-
spin_lock_init(&shared[i].lock);
101+
mutex_init(&shared[i].lock);
102102
for (j = 0; j < lpddr->qinfo->HWPartsNum; j++) {
103103
*chip = lpddr->chips[i];
104104
chip->start += j << lpddr->chipshift;
@@ -217,7 +217,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
217217
*/
218218
struct flchip_shared *shared = chip->priv;
219219
struct flchip *contender;
220-
spin_lock(&shared->lock);
220+
mutex_lock(&shared->lock);
221221
contender = shared->writing;
222222
if (contender && contender != chip) {
223223
/*
@@ -230,7 +230,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
230230
* get_chip returns success we're clear to go ahead.
231231
*/
232232
ret = mutex_trylock(&contender->mutex);
233-
spin_unlock(&shared->lock);
233+
mutex_unlock(&shared->lock);
234234
if (!ret)
235235
goto retry;
236236
mutex_unlock(&chip->mutex);
@@ -245,7 +245,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
245245
mutex_unlock(&contender->mutex);
246246
return ret;
247247
}
248-
spin_lock(&shared->lock);
248+
mutex_lock(&shared->lock);
249249

250250
/* We should not own chip if it is already in FL_SYNCING
251251
* state. Put contender and retry. */
@@ -261,7 +261,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
261261
Must sleep in such a case. */
262262
if (mode == FL_ERASING && shared->erasing
263263
&& shared->erasing->oldstate == FL_ERASING) {
264-
spin_unlock(&shared->lock);
264+
mutex_unlock(&shared->lock);
265265
set_current_state(TASK_UNINTERRUPTIBLE);
266266
add_wait_queue(&chip->wq, &wait);
267267
mutex_unlock(&chip->mutex);
@@ -275,7 +275,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
275275
shared->writing = chip;
276276
if (mode == FL_ERASING)
277277
shared->erasing = chip;
278-
spin_unlock(&shared->lock);
278+
mutex_unlock(&shared->lock);
279279
}
280280

281281
ret = chip_ready(map, chip, mode);
@@ -348,15 +348,15 @@ static void put_chip(struct map_info *map, struct flchip *chip)
348348
{
349349
if (chip->priv) {
350350
struct flchip_shared *shared = chip->priv;
351-
spin_lock(&shared->lock);
351+
mutex_lock(&shared->lock);
352352
if (shared->writing == chip && chip->oldstate == FL_READY) {
353353
/* We own the ability to write, but we're done */
354354
shared->writing = shared->erasing;
355355
if (shared->writing && shared->writing != chip) {
356356
/* give back the ownership */
357357
struct flchip *loaner = shared->writing;
358358
mutex_lock(&loaner->mutex);
359-
spin_unlock(&shared->lock);
359+
mutex_unlock(&shared->lock);
360360
mutex_unlock(&chip->mutex);
361361
put_chip(map, loaner);
362362
mutex_lock(&chip->mutex);
@@ -374,11 +374,11 @@ static void put_chip(struct map_info *map, struct flchip *chip)
374374
* Don't let the switch below mess things up since
375375
* we don't have ownership to resume anything.
376376
*/
377-
spin_unlock(&shared->lock);
377+
mutex_unlock(&shared->lock);
378378
wake_up(&chip->wq);
379379
return;
380380
}
381-
spin_unlock(&shared->lock);
381+
mutex_unlock(&shared->lock);
382382
}
383383

384384
switch (chip->oldstate) {

include/linux/mtd/flashchip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct flchip {
9292
/* This is used to handle contention on write/erase operations
9393
between partitions of the same physical chip. */
9494
struct flchip_shared {
95-
spinlock_t lock;
95+
struct mutex lock;
9696
struct flchip *writing;
9797
struct flchip *erasing;
9898
};

0 commit comments

Comments
 (0)