Skip to content

Commit b093410

Browse files
grundlerchromiumstorulf
authored andcommitted
mmc: block: copy resp[] data on err for MMC_IOC_MULTI_CMD
MMC_IOC_CMD and MMC_IOC_MULTI_CMD ioctl() code currently bails on any eMMC errors. However, in case there is any resp[] data, we should attempt to copy resp[] back to user space. The user app can then determine which command(s) failed in the MMC_IOC_MULTI_CMD case AND/OR report better diagnostics in both cases. Gwendal Grignou provided the idea and it was previously implemented and tested on v3.18 ChromeOS kernel: https://chromium-review.googlesource.com/#/c/299956 Signed-off-by: Grant Grundler <grundler@chromium.org> Reviewed-by: Hyung Taek Ryoo <hryoo@nvidia.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 85f4505 commit b093410

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

drivers/mmc/card/block.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
595595
struct mmc_blk_ioc_data *idata;
596596
struct mmc_blk_data *md;
597597
struct mmc_card *card;
598-
int err;
598+
int err = 0, ioc_err = 0;
599599

600600
idata = mmc_blk_ioctl_copy_from_user(ic_ptr);
601601
if (IS_ERR(idata))
@@ -615,19 +615,18 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
615615

616616
mmc_get_card(card);
617617

618-
err = __mmc_blk_ioctl_cmd(card, md, idata);
618+
ioc_err = __mmc_blk_ioctl_cmd(card, md, idata);
619619

620620
mmc_put_card(card);
621621

622-
if (!err)
623-
err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata);
622+
err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata);
624623

625624
cmd_done:
626625
mmc_blk_put(md);
627626
cmd_err:
628627
kfree(idata->buf);
629628
kfree(idata);
630-
return err;
629+
return ioc_err ? ioc_err : err;
631630
}
632631

633632
static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
@@ -637,7 +636,7 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
637636
struct mmc_ioc_cmd __user *cmds = user->cmds;
638637
struct mmc_card *card;
639638
struct mmc_blk_data *md;
640-
int i, err = -EFAULT;
639+
int i, err = 0, ioc_err = 0;
641640
__u64 num_of_cmds;
642641

643642
if (copy_from_user(&num_of_cmds, &user->num_of_cmds,
@@ -672,22 +671,14 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
672671

673672
mmc_get_card(card);
674673

675-
for (i = 0; i < num_of_cmds; i++) {
676-
err = __mmc_blk_ioctl_cmd(card, md, idata[i]);
677-
if (err) {
678-
mmc_put_card(card);
679-
goto cmd_done;
680-
}
681-
}
674+
for (i = 0; i < num_of_cmds && !ioc_err; i++)
675+
ioc_err = __mmc_blk_ioctl_cmd(card, md, idata[i]);
682676

683677
mmc_put_card(card);
684678

685679
/* copy to user if data and response */
686-
for (i = 0; i < num_of_cmds; i++) {
680+
for (i = 0; i < num_of_cmds && !err; i++)
687681
err = mmc_blk_ioctl_copy_to_user(&cmds[i], idata[i]);
688-
if (err)
689-
break;
690-
}
691682

692683
cmd_done:
693684
mmc_blk_put(md);
@@ -697,7 +688,7 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
697688
kfree(idata[i]);
698689
}
699690
kfree(idata);
700-
return err;
691+
return ioc_err ? ioc_err : err;
701692
}
702693

703694
static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode,

0 commit comments

Comments
 (0)