If 'chip->state == FL_SYNCING', we will 'goto retry' with the mutex '&shared->lock' already taken. In such a case, the 'mutex_lock' at line 927 can never succeed. In order to avoid a deadlock, move the 'mutex_lock(&shared->lock)' at the very end of the block. This has been spotted with the following coccinelle script: @find@ expression x, t; @@ mutex_lock(x); ... when != mutex_unlock(x) mutex_lock(t); @@ expression find.t; expression find.x; @@ * mutex_lock(t); ... when != mutex_unlock(t) * mutex_lock(x); Fixes: c68264711ca6 ("[MTD] LPDDR Command set driver") Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx> --- Review carefuly, untested. --- drivers/mtd/lpddr/lpddr_cmds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c index 018c75faadb3..830dd0855ab3 100644 --- a/drivers/mtd/lpddr/lpddr_cmds.c +++ b/drivers/mtd/lpddr/lpddr_cmds.c @@ -237,7 +237,6 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode) mutex_unlock(&contender->mutex); return ret; } - mutex_lock(&shared->lock); /* We should not own chip if it is already in FL_SYNCING * state. Put contender and retry. */ @@ -247,6 +246,8 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode) goto retry; } mutex_unlock(&contender->mutex); + + mutex_lock(&shared->lock); } /* Check if we have suspended erase on this chip. -- 2.14.1 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html