Skip to content

Commit 41591b3

Browse files
bootcstorulf
authored andcommitted
mmc: block: avoid multiblock reads for the last sector in SPI mode
On some SD cards over SPI, reading with the multiblock read command the last sector will leave the card in a bad state. Remove last sectors from the multiblock reading cmd. Signed-off-by: Chris Boot <bootc@bootc.net> Signed-off-by: Clément Péron <peron.clem@gmail.com> Cc: stable@vger.kernel.org # v4.10+ Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 0238df6 commit 41591b3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/mmc/core/block.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,16 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
13701370
brq->data.blocks = card->host->max_blk_count;
13711371

13721372
if (brq->data.blocks > 1) {
1373+
/*
1374+
* Some SD cards in SPI mode return a CRC error or even lock up
1375+
* completely when trying to read the last block using a
1376+
* multiblock read command.
1377+
*/
1378+
if (mmc_host_is_spi(card->host) && (rq_data_dir(req) == READ) &&
1379+
(blk_rq_pos(req) + blk_rq_sectors(req) ==
1380+
get_capacity(md->disk)))
1381+
brq->data.blocks--;
1382+
13731383
/*
13741384
* After a read error, we redo the request one sector
13751385
* at a time in order to accurately determine which

0 commit comments

Comments
 (0)