mmc: block: do not query the sd card if a fault is injected

When the fault injection framework introduces an error to the data
block, the current code queries the SD card to find the number of
blocks actually programmed. This value would be as requested by the
generic block layer. So the entire request would be completed.

Say, request 0 is pulled from queue and submitted. When this is being
processed, request 1 is pulled from queue and prepared. Request 0
though is successful, fault-injection framework injects an error
and modifies the bytes_xferred variable to a random value less than
requested transfer. Request 1 is not processed and during the handling
of error, the SD card is queried for the actual bytes programmed. This
would be the correct value. Thus blk_end_request would complete
this request and the control would return to fetch request 2. In this
process, request 1 is not processed at all and the application waits
indefinitely for request 1 to be processed. No further requests are
issued to the queue.

This patch identifies, if the fault injection-framework has inserted an
error to this request and doesn't query the card and uses
bytes_xferred to complete the request.

Change-Id: I496802e244745bc7550402027a594d967cf7b756
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[xiaonian@codeaurora.org: fix trivial merge conflict]
Signed-off-by: Xiaonian Wang <xiaonian@codeaurora.org>
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 60d435d..5706053 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -1773,6 +1773,7 @@
 	brq->stop.arg = 0;
 	brq->data.blocks = blk_rq_sectors(req);
 
+	brq->data.fault_injected = false;
 	/*
 	 * The block layer doesn't support all sector count
 	 * restrictions, so we need to be prepared for too big
@@ -2103,6 +2104,7 @@
 	brq->data.blksz = 512;
 	brq->data.blocks = packed->blocks + hdr_blocks;
 	brq->data.flags = MMC_DATA_WRITE;
+	brq->data.fault_injected = false;
 
 	brq->stop.opcode = MMC_STOP_TRANSMISSION;
 	brq->stop.arg = 0;
@@ -2136,11 +2138,12 @@
 	 */
 	if (mmc_card_sd(card)) {
 		u32 blocks;
-
-		blocks = mmc_sd_num_wr_blocks(card);
-		if (blocks != (u32)-1) {
-			ret = blk_end_request(req, 0, blocks << 9);
-		}
+		if (!brq->data.fault_injected) {
+			blocks = mmc_sd_num_wr_blocks(card);
+			if (blocks != (u32)-1)
+				ret = blk_end_request(req, 0, blocks << 9);
+		} else
+			ret = blk_end_request(req, 0, brq->data.bytes_xfered);
 	} else {
 		if (!mmc_packed_cmd(mq_rq->cmd_type))
 			ret = blk_end_request(req, 0, brq->data.bytes_xfered);