From patchwork Wed Jun 14 11:48:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 105494 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp248862qgd; Wed, 14 Jun 2017 04:49:00 -0700 (PDT) X-Received: by 10.84.138.131 with SMTP id 3mr287443plp.24.1497440940332; Wed, 14 Jun 2017 04:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497440940; cv=none; d=google.com; s=arc-20160816; b=qkGL40FBrDxil85YRkSwe0qFSLekPgn3qbhb/befrLQ75mN+MH3khxcfx0vgqDsw+O er2KYs9hDg1i1DfsrtoeTdZMkF1NeWlofBev3L9+i4H+yGs5g3Epe46d2+v2lowSmmz3 8tmyigYw9rfb6QDTimiSkh0uRPGgucIb19hhPhYNwHthP8lqdww1h2uHo4bOZT0lL1xu 1JbTXR98bKiUybsgJ9AxPUB9wm4EP8mfEbep+fhibSzNEvGePKFNoVPuVIVuJS9+pwyZ jqwtwCCcY80p2CuUp7jT6kuoAboRKzOoxsmbAyjJrwYS5n6fLbHdMwTXj4oA6wSMwFpi 9hOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=LjY0omzihpacX3zbSNZCZ7cQ6k4y33Uze/L1EEoPWCU=; b=dE/tM/nLVmhPxxh0a1idhcyfFc8YUoRf+DErtb/DSZclXyjrtbxrAQ0IMLwuSxIAhh QSHU9Vn+pZMDPHjJw1ijJhJbSvi4Dk/RzC3rGJbLsDj7+oFRkpa1HDBuizzEv3gv3H/D z42q723MbSPNnzbouhWYy9x90tEvD1HkfZmfnzYB+3JyfJiKKxgYE6IebTElF12rTrjy ioCED75RrL3qIybhQArCWYERDRpzlRFCcTVpFkZMB5sX0PKr8UjTFKgcmkMb+yaDLbvl h42hjtOq7rw4JaJWNqLuzWZOhsMNS0V40YtqwWJbw9Q2Y83uric/T/cCdr+stcssH17R Z+WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=H/+cE1Aq; 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 r6si534625plj.223.2017.06.14.04.48.59; Wed, 14 Jun 2017 04:49:00 -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=H/+cE1Aq; 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 S1752035AbdFNLs7 (ORCPT + 6 others); Wed, 14 Jun 2017 07:48:59 -0400 Received: from mail-lf0-f47.google.com ([209.85.215.47]:34760 "EHLO mail-lf0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752025AbdFNLs6 (ORCPT ); Wed, 14 Jun 2017 07:48:58 -0400 Received: by mail-lf0-f47.google.com with SMTP id v20so90173101lfa.1 for ; Wed, 14 Jun 2017 04:48:57 -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; bh=UAjurdokRGgvOGMlCgs5spm7q/WjLDMXQ4xrYGq+/Fo=; b=H/+cE1AqFB5mwUmfvNoyAUq2Rip+zDS/KS21FqkuvPOUY3eXoXzBa7ijv0MWMA7Tmd skP9VkCalIEXp3MPMxXAXNfk8TrPXOFTllHYse1DrX0qv6OvZNAVAwC45GHlcDHJHRr6 fectrwwrb8an/bQ3ntjNLnVM/gPAcP+QvBuBM= 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; bh=UAjurdokRGgvOGMlCgs5spm7q/WjLDMXQ4xrYGq+/Fo=; b=W1r1FVX8yLvP1PWK64DBpT2zKJROha2sHS71Wk76Yf2Bc5IVbrFE9E8+7oWwkFzKt6 FZU8AD5sb9xEZS97Yu5oOuI2v1o1vuk4zYcyrG1NGkyN3FijiG2cs0wNG6seFD2/c6Iz TH5FL4xFiyTbB27sFiXJRB/Mi3bWV3hGOih2U2uOtOjEYsfpSlYrU7aYhT9y2zYZBykM naSKm29kycXl2ci15k2KH6GHyVcQH/wCJj8HMelci6niSE6G26YHKQAFo8aJhFHo/S52 NG9NadxgD3c1dQEJSqF7CLqz7TkobtQSV//OcbPbOycTLdZ5Ezesc3t7LuV4m1XO5ZfF +57A== X-Gm-Message-State: AKS2vOzh1TpSOzRARKILmjIEq5hZ+7s7kMI7YV/CE0/BVp6zB/nSFmuq xckVfyDXl0Nh57Spf7cHzQ== X-Received: by 10.25.32.212 with SMTP id g203mr76163lfg.116.1497440936373; Wed, 14 Jun 2017 04:48:56 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x7sm192911ljd.5.2017.06.14.04.48.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jun 2017 04:48:54 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij Subject: [PATCH] mmc: block: Move duplicate check Date: Wed, 14 Jun 2017 13:48:51 +0200 Message-Id: <20170614114851.17146-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org mmc_blk_ioctl() calls either mmc_blk_ioctl_cmd() or mmc_blk_ioctl_multi_cmd() and each of these make the same check. Factor it into the first call and save one chunk of duplicate code. Signed-off-by: Linus Walleij --- drivers/mmc/core/block.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 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 1ce6012ce3c1..c80bee4a9cff 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -566,14 +566,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, int err = 0, ioc_err = 0; struct request *req; - /* - * The caller must have CAP_SYS_RAWIO, and must be calling this on the - * whole block device, not on a partition. This prevents overspray - * between sibling partitions. - */ - if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) - return -EPERM; - idata = mmc_blk_ioctl_copy_from_user(ic_ptr); if (IS_ERR(idata)) return PTR_ERR(idata); @@ -626,14 +618,6 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, __u64 num_of_cmds; struct request *req; - /* - * The caller must have CAP_SYS_RAWIO, and must be calling this on the - * whole block device, not on a partition. This prevents overspray - * between sibling partitions. - */ - if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) - return -EPERM; - if (copy_from_user(&num_of_cmds, &user->num_of_cmds, sizeof(num_of_cmds))) return -EFAULT; @@ -700,6 +684,14 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { + /* + * The caller must have CAP_SYS_RAWIO, and must be calling this on the + * whole block device, not on a partition. This prevents overspray + * between sibling partitions. + */ + if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) + return -EPERM; + switch (cmd) { case MMC_IOC_CMD: return mmc_blk_ioctl_cmd(bdev,