From patchwork Thu Jun 15 12:12:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 105645 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp772170qgd; Thu, 15 Jun 2017 05:13:17 -0700 (PDT) X-Received: by 10.99.64.199 with SMTP id n190mr5080723pga.281.1497528797422; Thu, 15 Jun 2017 05:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497528797; cv=none; d=google.com; s=arc-20160816; b=nnWwcdTvKSRwkn7BiVTYKtDYAm2AdypMWb/oTRRc5RzoF6SNi2Dd8G2Pn1llTY22RM D9X66PTOaq63yZkeSmnD8IvuBSbGmRMziL+9MEFy5F0GRs6wqSHHUGneCZBZRv8SHDD5 Ctfs7qGkzY/cSkO3bMMHiniEorjzHM6PC3Y+9U1vhQSbLSD4AijYqu3CpiNSleK4ycb7 3IbqiUXfDtoLQ94azpV1365WgqZcVCFx0GPZfslm5OIsHLW9LwSdL5wn53p5npqMf/at MoGtB9brH0YJsIzpw10SODQMgyi2Iw/V9DqqN78g6u5w8ULANzBavIqC78KKauLGfx8h Noxw== 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=N4u3lCNoqSUfdQTU/FCtXImwoZQ60VMNDEWrIrno8+E=; b=AmAMdzi3EF4E4tYCinfY71aPt1iDS0sBzIVW2MMn7YcSZn4iYKANY0to9ElfvVIpmQ bCD9OAp3otjeXZNzFpYB/N/V/ok+WhTfHugK3MsO+pygUap2PbfjLxgfhrZR0h+vzQPU qIdY9vUWe/sy4L3RfR/Yz62IND4SjQBcnkArPWYqu9MoLsKpxV4r5RVqvyYexb/0R+Na 73WBo0boKLwXbB8FFKdYAZaRBeaE8TTtcS3RhZxHY2jlubIWRLGoB2yuKFgbuzAp8nVw kkn3h1jRchgZPCkbGcxkBqWXMQ7U62W0AaGjDIZUXw7FwKvfQ+xO4NWGRqB/v0/NSlVX IfXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=R+PoxeMy; 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 y92si2162397plb.230.2017.06.15.05.13.17; Thu, 15 Jun 2017 05:13:17 -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.b=R+PoxeMy; 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 S1752393AbdFOMNQ (ORCPT + 6 others); Thu, 15 Jun 2017 08:13:16 -0400 Received: from mail-lf0-f45.google.com ([209.85.215.45]:34937 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752409AbdFOMNP (ORCPT ); Thu, 15 Jun 2017 08:13:15 -0400 Received: by mail-lf0-f45.google.com with SMTP id p189so7957265lfe.2 for ; Thu, 15 Jun 2017 05:13:14 -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=IX/yk2insXLJGd9W+DztI3NvuJFrctf+aXL99tzEFRM=; b=R+PoxeMyohpDpMkQpYhCQR1CtdqwTHAYcOAsc8UsrvS8lT0r7bUvdFWL3tOZfZO9xC KB4djdjXoXlFSK1c7IA2ZhFDsmdvzSQ+YPqqAuFtAYVgaw7sIOP1NNQaa1A+ahPAlN9B HjZtbDgm7RMxVEY074uazPEwq+ZzPGe2cUqYA= 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=IX/yk2insXLJGd9W+DztI3NvuJFrctf+aXL99tzEFRM=; b=RpjJBAzhT9hlR24h3i2PiTPRTCTOfdZbhmP+HjIS37F6km4ZDdPHxxUv6KpcnF0Gy8 HNnQoc40rgCV64OtUqxmyjrzovSXP1h8H1Sx8Jj+Q88FHObCPJRpkqFAlXNFEDQ5/ndr 8MFgmS+U323VNkQ4AYh2k9/6qGSKshCvqxeNRp+uylWcBJMtiL4OFRcBxQdl/sba3Tvt 5FD7vMsbSuFoQxjPFaa3ZMKhCFzOLnFnjkwgQzNMoBNoyTpREXbe0wDLriJjm3IE3y7B DJMGySp1UiGh4xngoxM5xoUoZkligfnVzMVbXmB7qduLDmdyjEko97wRDeHgWMQUFsrI gWBA== X-Gm-Message-State: AKS2vOwlsNaqNsdiHzmO67WL2jU5d4iqVvbNC89Xart50SYL4vg1lDe7 ID7FJW5LWm8oc9GvwOXFmA== X-Received: by 10.25.99.201 with SMTP id v70mr1454759lfi.63.1497528793496; Thu, 15 Jun 2017 05:13:13 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v1sm597574lja.18.2017.06.15.05.13.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 05:13:12 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Avri Altman , Adrian Hunter , Linus Walleij Subject: [PATCH 3/5] mmc: block: Reparametrize mmc_blk_ioctl_[multi]_cmd() Date: Thu, 15 Jun 2017 14:12:57 +0200 Message-Id: <20170615121259.8281-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615121259.8281-1-linus.walleij@linaro.org> References: <20170615121259.8281-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 --- drivers/mmc/core/block.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) -- 2.9.4 -- 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 94b97f97be1a..b8c71fdb6ed4 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -555,12 +555,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; @@ -570,12 +569,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); @@ -599,20 +592,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; @@ -638,16 +628,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; } @@ -670,8 +654,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); @@ -696,6 +678,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) { @@ -703,14 +686,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; }