Skip to contentSkip to conversation

mmc: core: Return correct emmc response in case of ioctl error

PATCH Superseded Nishad Kamdar 1 participant 1 message Aug 5, 2021 MMC, SD and SDIO

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: core: Return correct emmc response in case of ioctl error

When a command is sent via ioctl to the kernel, and the command fails, the actual error response of the emmc is not sent to the user.

I have tried this by sending CMD17 (Single Block Read) from user space via ioctl with and out of range address as an argument.
The response I receive is 0x00000000.
This is because the actual response is copied later in the function __mmc_blk_ioctl_cmd() after the data error is detected. This output is misleading to the user as the actual emmc response is 0x8000900 which clearly shows that is an OUT_OF_RANGE error.

The patch fixes this issue by copying to contents of the response to before issuing the error.
Thus the user will get the correct response and will see the error as well.

---
 drivers/mmc/core/block.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mmc/core/block.c +2 -0
index a9ad9f5fa9491..efa92aa7e2368 100644
@@ -522,11 +522,13 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
 	if (cmd.error) {
 		dev_err(mmc_dev(card->host), "%s: cmd error %d\n",
 						__func__, cmd.error);
+		memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp));
 		return cmd.error;
 	}
 	if (data.error) {
 		dev_err(mmc_dev(card->host), "%s: data error %d\n",
 						__func__, data.error);
+		memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp));
 		return data.error;
 	}
 
Signature · 1 line
2.17.1