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: 9786137 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 DCD30602C9 for ; Wed, 14 Jun 2017 11:49:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8C0B285A8 for ; Wed, 14 Jun 2017 11:49:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD82C285EE; Wed, 14 Jun 2017 11:49:01 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 CCDD8285A8 for ; Wed, 14 Jun 2017 11:48:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752035AbdFNLs7 (ORCPT ); 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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,