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: 110489 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp521514qge; Sun, 20 Aug 2017 14:39:35 -0700 (PDT) X-Received: by 10.84.128.195 with SMTP id a61mr17122844pla.222.1503265175170; Sun, 20 Aug 2017 14:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503265175; cv=none; d=google.com; s=arc-20160816; b=idueicw2SSNcXR8i+3tVecwsjkjot0eB5EL7oKy2k1zwF66bPEHko4HG1hg68pEhBy odDJItk7FkwcWtDL0ccXBovoS2Tb/TVTNfRElGVmkB7w2hW2Vs48fsGQUDvDFSdqppKS PEcdqeZk7wJZAOgLj4JShfFJSsY/ZVqTgMdJOm32cIaaMFdxrREPg1zah/6Dbjy9pvEf T66GQ7cv5yh9jPvpSMjtTLv4F79cn1REoZ1PmrsrR48OsjSJXkth5U+i9khST4RaZNaz dAmaVHNHMloie3+cbUaP8Lgf479HZ4nFEjvDcq7iAs8SkE7pud2Vgiot8WHX5DQVM+VO K4LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LJqNICfnY39RIfZM7NDak46fZbZCfg6sOUAJ885vVr8=; b=Hm9CGU7oa/oxciNy9Zuvcx7g6bKO5djx0k8gWUaX2uRXDw8XUB2D6alie/MxqN37eD WkB+z1FTUFbfuxH243KEV6btIHz4qx8T9aVN/g3ecaB6HLqVSYNZxXljFliR9UsvzffP mfins4UQmxylRlMII+mpj+ySk1EI+VckV44loHoc0UEDLEddwidnsVZzYJUYRhPEg0uQ DB+aN3oef6Pvuy2zF2SKOyfnIUzr46rRYqK16aOCosQB9oy3GXRvQV3s9OYeoLQ9CORp eZ+VjBEwo9Gs5qeldRum2p57Jqst3hJQDPg7+TDYsLvUH4MPKc92/HsyV65m9HNgd9a2 Z0YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GITl0z7G; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si3544613pgn.611.2017.08.20.14.39.34; Sun, 20 Aug 2017 14:39:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GITl0z7G; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753374AbdHTVje (ORCPT + 6 others); 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 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(-) -- 2.13.5 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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; }