Skip to content

Commit 2fe20ba

Browse files
Linus Walleijstorulf
authored andcommitted
mmc: block: Reparametrize mmc_blk_ioctl_[multi]_cmd()
Instead of passing a block device to mmc_blk_ioctl[_multi]_cmd(), let's pass struct mmc_blk_data() so we operate ioctl()s on the MMC block device representation rather than the vanilla block device. This saves a little duplicated code and makes it possible to issue ioctl()s not targeted for a specific block device but rather for a specific partition/area. Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Ulf Hansson <[email protected]>
1 parent 1f797ed commit 2fe20ba

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

drivers/mmc/core/block.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -553,12 +553,11 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
553553
return err;
554554
}
555555

556-
static int mmc_blk_ioctl_cmd(struct block_device *bdev,
556+
static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md,
557557
struct mmc_ioc_cmd __user *ic_ptr)
558558
{
559559
struct mmc_blk_ioc_data *idata;
560560
struct mmc_blk_ioc_data *idatas[1];
561-
struct mmc_blk_data *md;
562561
struct mmc_queue *mq;
563562
struct mmc_card *card;
564563
int err = 0, ioc_err = 0;
@@ -568,12 +567,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
568567
if (IS_ERR(idata))
569568
return PTR_ERR(idata);
570569

571-
md = mmc_blk_get(bdev->bd_disk);
572-
if (!md) {
573-
err = -EINVAL;
574-
goto cmd_err;
575-
}
576-
577570
card = md->queue.card;
578571
if (IS_ERR(card)) {
579572
err = PTR_ERR(card);
@@ -597,20 +590,17 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
597590
blk_put_request(req);
598591

599592
cmd_done:
600-
mmc_blk_put(md);
601-
cmd_err:
602593
kfree(idata->buf);
603594
kfree(idata);
604595
return ioc_err ? ioc_err : err;
605596
}
606597

607-
static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
598+
static int mmc_blk_ioctl_multi_cmd(struct mmc_blk_data *md,
608599
struct mmc_ioc_multi_cmd __user *user)
609600
{
610601
struct mmc_blk_ioc_data **idata = NULL;
611602
struct mmc_ioc_cmd __user *cmds = user->cmds;
612603
struct mmc_card *card;
613-
struct mmc_blk_data *md;
614604
struct mmc_queue *mq;
615605
int i, err = 0, ioc_err = 0;
616606
__u64 num_of_cmds;
@@ -639,16 +629,10 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
639629
}
640630
}
641631

642-
md = mmc_blk_get(bdev->bd_disk);
643-
if (!md) {
644-
err = -EINVAL;
645-
goto cmd_err;
646-
}
647-
648632
card = md->queue.card;
649633
if (IS_ERR(card)) {
650634
err = PTR_ERR(card);
651-
goto cmd_done;
635+
goto cmd_err;
652636
}
653637

654638

@@ -671,8 +655,6 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
671655

672656
blk_put_request(req);
673657

674-
cmd_done:
675-
mmc_blk_put(md);
676658
cmd_err:
677659
for (i = 0; i < num_of_cmds; i++) {
678660
kfree(idata[i]->buf);
@@ -697,21 +679,32 @@ static int mmc_blk_check_blkdev(struct block_device *bdev)
697679
static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode,
698680
unsigned int cmd, unsigned long arg)
699681
{
682+
struct mmc_blk_data *md;
700683
int ret;
701684

702685
switch (cmd) {
703686
case MMC_IOC_CMD:
704687
ret = mmc_blk_check_blkdev(bdev);
705688
if (ret)
706689
return ret;
707-
return mmc_blk_ioctl_cmd(bdev,
708-
(struct mmc_ioc_cmd __user *)arg);
690+
md = mmc_blk_get(bdev->bd_disk);
691+
if (!md)
692+
return -EINVAL;
693+
ret = mmc_blk_ioctl_cmd(md,
694+
(struct mmc_ioc_cmd __user *)arg);
695+
mmc_blk_put(md);
696+
return ret;
709697
case MMC_IOC_MULTI_CMD:
710698
ret = mmc_blk_check_blkdev(bdev);
711699
if (ret)
712700
return ret;
713-
return mmc_blk_ioctl_multi_cmd(bdev,
714-
(struct mmc_ioc_multi_cmd __user *)arg);
701+
md = mmc_blk_get(bdev->bd_disk);
702+
if (!md)
703+
return -EINVAL;
704+
ret = mmc_blk_ioctl_multi_cmd(md,
705+
(struct mmc_ioc_multi_cmd __user *)arg);
706+
mmc_blk_put(md);
707+
return ret;
715708
default:
716709
return -EINVAL;
717710
}

0 commit comments

Comments
 (0)