Skip to content

Commit 406e148

Browse files
cloehlestorulf
authored andcommitted
mmc: block: Remove error check of hw_reset on reset
Before switching back to the right partition in mmc_blk_reset there used to be a check if hw_reset was even supported. This return value was removed, so there is no reason to check. Furthermore ensure part_curr is not falsely set to a valid value on reset or partition switch error. As part of this change the code paths of mmc_blk_reset calls were checked to ensure no commands are issued after a failed mmc_blk_reset directly without going through the block layer. Fixes: fefdd3c ("mmc: core: Drop superfluous validations in mmc_hw|sw_reset()") Cc: [email protected] Signed-off-by: Christian Loehle <[email protected]> Reviewed-by: Adrian Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 9abf231 commit 406e148

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

drivers/mmc/core/block.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct mmc_blk_data {
134134
* track of the current selected device partition.
135135
*/
136136
unsigned int part_curr;
137+
#define MMC_BLK_PART_INVALID UINT_MAX /* Unknown partition active */
137138
int area_type;
138139

139140
/* debugfs files (only in main mmc_blk_data) */
@@ -987,33 +988,39 @@ static unsigned int mmc_blk_data_timeout_ms(struct mmc_host *host,
987988
return ms;
988989
}
989990

991+
/*
992+
* Attempts to reset the card and get back to the requested partition.
993+
* Therefore any error here must result in cancelling the block layer
994+
* request, it must not be reattempted without going through the mmc_blk
995+
* partition sanity checks.
996+
*/
990997
static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
991998
int type)
992999
{
9931000
int err;
1001+
struct mmc_blk_data *main_md = dev_get_drvdata(&host->card->dev);
9941002

9951003
if (md->reset_done & type)
9961004
return -EEXIST;
9971005

9981006
md->reset_done |= type;
9991007
err = mmc_hw_reset(host->card);
1008+
/*
1009+
* A successful reset will leave the card in the main partition, but
1010+
* upon failure it might not be, so set it to MMC_BLK_PART_INVALID
1011+
* in that case.
1012+
*/
1013+
main_md->part_curr = err ? MMC_BLK_PART_INVALID : main_md->part_type;
1014+
if (err)
1015+
return err;
10001016
/* Ensure we switch back to the correct partition */
1001-
if (err) {
1002-
struct mmc_blk_data *main_md =
1003-
dev_get_drvdata(&host->card->dev);
1004-
int part_err;
1005-
1006-
main_md->part_curr = main_md->part_type;
1007-
part_err = mmc_blk_part_switch(host->card, md->part_type);
1008-
if (part_err) {
1009-
/*
1010-
* We have failed to get back into the correct
1011-
* partition, so we need to abort the whole request.
1012-
*/
1013-
return -ENODEV;
1014-
}
1015-
}
1016-
return err;
1017+
if (mmc_blk_part_switch(host->card, md->part_type))
1018+
/*
1019+
* We have failed to get back into the correct
1020+
* partition, so we need to abort the whole request.
1021+
*/
1022+
return -ENODEV;
1023+
return 0;
10171024
}
10181025

10191026
static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
@@ -1871,8 +1878,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue *mq, struct request *req)
18711878
return;
18721879

18731880
/* Reset before last retry */
1874-
if (mqrq->retries + 1 == MMC_MAX_RETRIES)
1875-
mmc_blk_reset(md, card->host, type);
1881+
if (mqrq->retries + 1 == MMC_MAX_RETRIES &&
1882+
mmc_blk_reset(md, card->host, type))
1883+
return;
18761884

18771885
/* Command errors fail fast, so use all MMC_MAX_RETRIES */
18781886
if (brq->sbc.error || brq->cmd.error)

0 commit comments

Comments
 (0)