From patchwork Sun Aug 20 21:39:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9911457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4BF7E601D4 for ; Sun, 20 Aug 2017 21:39:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43445286B6 for ; Sun, 20 Aug 2017 21:39:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3861E286C5; Sun, 20 Aug 2017 21:39:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB247286BB for ; Sun, 20 Aug 2017 21:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753374AbdHTVje (ORCPT ); Sun, 20 Aug 2017 17:39:34 -0400 Received: from mail-lf0-f41.google.com ([209.85.215.41]:38474 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753351AbdHTVjd (ORCPT ); Sun, 20 Aug 2017 17:39:33 -0400 Received: by mail-lf0-f41.google.com with SMTP id y15so59683459lfd.5 for ; Sun, 20 Aug 2017 14:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nQPpw6drvvkJc3O5wTjaFNpU2DDYzJaBZsb2RWWlEgU=; b=GITl0z7Gc7MS9oH3UAekpF0wWm8qE/mSPwUqJURBklwdcHtGG1tvM/FaDYR/WXnMo3 IjIV8ObPwG1HfU+qfLIoFgJnddvh7G2Z/OphzmL25ZUjZbLpxSLY2lvQJyYeNnUa4/CJ 0b0+6FHGBV1Jd/VwbMgw6uuM5kCegRXeGn0Tk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nQPpw6drvvkJc3O5wTjaFNpU2DDYzJaBZsb2RWWlEgU=; b=Y+JsJndzq/j791q8QK5LgyoOP0XBFRGZeA2I8KP5AzwMTVDXjdnDFvjKUcy6w+2iDu SiBl2vHHz4Lc5vt2aXJiRvKu688C6JGCVNrVyUZAktez/oyY1ZuheWcmCp0Ag16umdKU kYxR1cwYjKDeoybbcRc9SqwmfiV+CPRzi12hC+yF7VgxS4qBHEb2PhoXSEsa/vTnNXlz BFGDeI7tQEIyjemoRBva3l130gNAAu2foFLc7XilGcqwTlg8lsZ+VmaZriAytjIy9VOI prdN2WxbBOiNsFwOp7rAeo49HhLfDG+LV7mq+lqKnFYKoxN/ZtHRuweEG6vkW/3tBizf wQ0A== X-Gm-Message-State: AHYfb5jefnlZIHjcedoR0gntE1CqAo0mjwn3KEd2MQio2gOmX7vCZazL L1vsj1q+mReChFCZAzAhcg== X-Received: by 10.25.228.85 with SMTP id b82mr5465065lfh.148.1503265171950; Sun, 20 Aug 2017 14:39:31 -0700 (PDT) Received: from genomnajs.bredbandsbolaget.se (c-097b71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.123.9]) by smtp.gmail.com with ESMTPSA id f136sm2381830lff.34.2017.08.20.14.39.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Aug 2017 14:39:31 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij Subject: [PATCH 6/8 v5] mmc: block: Reparametrize mmc_blk_ioctl_[multi]_cmd() Date: Sun, 20 Aug 2017 23:39:11 +0200 Message-Id: <20170820213913.9737-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170820213913.9737-1-linus.walleij@linaro.org> References: <20170820213913.9737-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- ChangeLog v1->v5: - Rebase. - Renumber v5 to keep together with the rest of the series. --- drivers/mmc/core/block.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 3abdbab401ad..502068b155b9 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -553,12 +553,11 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, return err; } -static int mmc_blk_ioctl_cmd(struct block_device *bdev, +static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, struct mmc_ioc_cmd __user *ic_ptr) { struct mmc_blk_ioc_data *idata; struct mmc_blk_ioc_data *idatas[1]; - struct mmc_blk_data *md; struct mmc_queue *mq; struct mmc_card *card; int err = 0, ioc_err = 0; @@ -568,12 +567,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, if (IS_ERR(idata)) return PTR_ERR(idata); - md = mmc_blk_get(bdev->bd_disk); - if (!md) { - err = -EINVAL; - goto cmd_err; - } - card = md->queue.card; if (IS_ERR(card)) { err = PTR_ERR(card); @@ -597,20 +590,17 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, blk_put_request(req); cmd_done: - mmc_blk_put(md); -cmd_err: kfree(idata->buf); kfree(idata); return ioc_err ? ioc_err : err; } -static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, +static int mmc_blk_ioctl_multi_cmd(struct mmc_blk_data *md, struct mmc_ioc_multi_cmd __user *user) { struct mmc_blk_ioc_data **idata = NULL; struct mmc_ioc_cmd __user *cmds = user->cmds; struct mmc_card *card; - struct mmc_blk_data *md; struct mmc_queue *mq; int i, err = 0, ioc_err = 0; __u64 num_of_cmds; @@ -639,16 +629,10 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, } } - md = mmc_blk_get(bdev->bd_disk); - if (!md) { - err = -EINVAL; - goto cmd_err; - } - card = md->queue.card; if (IS_ERR(card)) { err = PTR_ERR(card); - goto cmd_done; + goto cmd_err; } @@ -671,8 +655,6 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, blk_put_request(req); -cmd_done: - mmc_blk_put(md); cmd_err: for (i = 0; i < num_of_cmds; i++) { kfree(idata[i]->buf); @@ -697,6 +679,7 @@ static int mmc_blk_check_blkdev(struct block_device *bdev) static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { + struct mmc_blk_data *md; int ret; switch (cmd) { @@ -704,14 +687,24 @@ static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, ret = mmc_blk_check_blkdev(bdev); if (ret) return ret; - return mmc_blk_ioctl_cmd(bdev, - (struct mmc_ioc_cmd __user *)arg); + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return -EINVAL; + ret = mmc_blk_ioctl_cmd(md, + (struct mmc_ioc_cmd __user *)arg); + mmc_blk_put(md); + return ret; case MMC_IOC_MULTI_CMD: ret = mmc_blk_check_blkdev(bdev); if (ret) return ret; - return mmc_blk_ioctl_multi_cmd(bdev, - (struct mmc_ioc_multi_cmd __user *)arg); + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return -EINVAL; + ret = mmc_blk_ioctl_multi_cmd(md, + (struct mmc_ioc_multi_cmd __user *)arg); + mmc_blk_put(md); + return ret; default: return -EINVAL; }