From patchwork Sun Feb 14 15:07:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 8302181 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EE82EC02AA for ; Sun, 14 Feb 2016 15:08:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1DA202039E for ; Sun, 14 Feb 2016 15:08:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 118C120398 for ; Sun, 14 Feb 2016 15:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751449AbcBNPIY (ORCPT ); Sun, 14 Feb 2016 10:08:24 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34987 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751250AbcBNPII (ORCPT ); Sun, 14 Feb 2016 10:08:08 -0500 Received: by mail-wm0-f65.google.com with SMTP id g62so11594279wme.2 for ; Sun, 14 Feb 2016 07:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leon-nu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GtGKsabExzYyLgrOXG7JB2gpWTcn6sOsf8TWneuoh5A=; b=UJDu3h6pSqxIuTuCO9bBzxKCuwtsLY1q3fUSKefUCya5UiDtfWOduP3cCOL5e4I8SD nbxEDkGFxvdYSXqnE3XloYMlexFO1M/ob9n/ZEghdlXDGH4k/nKKVhEmYFFgfABBpV3W tE2no9dIPGaeTzW9bm0wWLtI1LycGbEpBlj/3f3o0E/qz0lpKEkVDZhnD0YG/FYb2Fjp tKLm6g2S+re0023OxVyaPq+hfL4NbznO0OJJe9hnZcC3A4sksaDsNzC9qpJ1fcIniBQe OvIyKt8nx/12ZD2XXDl5v0wgmoHJGrpP8bln2ijtBxeddBNiMA7orFT0Y63v4KYjwE1G 8Qkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GtGKsabExzYyLgrOXG7JB2gpWTcn6sOsf8TWneuoh5A=; b=Qs+t4mC68JqRMc7I40DV0X8CBez4+/a2jqXuqutfJlq5chFZjZCTRfVz2YO0qQhBUN ZrDVDcom4rB0ZoUa1ZViXnkgssh8/0tlmQH8rtwRgWKa39c7uneRqqvngKTIH1BO/J/o 7ofqeTyO3k7qk8Wsel/QNdoUXmrI+BefsKGGuAHQG1jB3NGNCnNppt2slxm9/u/oGnDb 8aU/8Y3XUkOSnZFr2BqEbI1Z7AmBtJ6CT6X3Mj9rNr1ZajnQ22JbfF+K3BnFSCqH5/PK GKDyOHN4yXDmmjGVvVxUEc4QvKf2F/xpq6d9Bbq7sj+oIwOWgUeMUtqt+4S8VNUKD1bS fTvw== X-Gm-Message-State: AG10YOR4IOyWNhHJY2f7++bsHV+dT4z/viU+UkHpcFsX2u0z+vfl+PS2Daryw35F1tcrFg== X-Received: by 10.194.78.230 with SMTP id e6mr11074691wjx.179.1455462487464; Sun, 14 Feb 2016 07:08:07 -0800 (PST) Received: from localhost ([213.57.247.249]) by smtp.gmail.com with ESMTPSA id ll9sm21037691wjc.29.2016.02.14.07.08.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Feb 2016 07:08:06 -0800 (PST) From: Leon Romanovsky To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, Eli Cohen , Leon Romanovsky Subject: [PATCH rdma-next 1/3] IB/core: Avoid duplicate code Date: Sun, 14 Feb 2016 17:07:47 +0200 Message-Id: <1455462469-9124-2-git-send-email-leon@leon.nu> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455462469-9124-1-git-send-email-leon@leon.nu> References: <1455462469-9124-1-git-send-email-leon@leon.nu> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eli Cohen Move the check on the validity of the command to a common area. Signed-off-by: Eli Cohen Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/uverbs_main.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 39680ae..08f1a7b 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -689,6 +689,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, struct ib_uverbs_file *file = filp->private_data; struct ib_device *ib_dev; struct ib_uverbs_cmd_hdr hdr; + __u32 command; __u32 flags; int srcu_key; ssize_t ret; @@ -707,20 +708,18 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, goto out; } + if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK | + IB_USER_VERBS_CMD_COMMAND_MASK)) { + ret = -EINVAL; + goto out; + } + + command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK; + flags = (hdr.command & IB_USER_VERBS_CMD_FLAGS_MASK) >> IB_USER_VERBS_CMD_FLAGS_SHIFT; if (!flags) { - __u32 command; - - if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK | - IB_USER_VERBS_CMD_COMMAND_MASK)) { - ret = -EINVAL; - goto out; - } - - command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK; - if (command >= ARRAY_SIZE(uverbs_cmd_table) || !uverbs_cmd_table[command]) { ret = -EINVAL; @@ -749,21 +748,11 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, hdr.out_words * 4); } else if (flags == IB_USER_VERBS_CMD_FLAG_EXTENDED) { - __u32 command; - struct ib_uverbs_ex_cmd_hdr ex_hdr; struct ib_udata ucore; struct ib_udata uhw; size_t written_count = count; - if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK | - IB_USER_VERBS_CMD_COMMAND_MASK)) { - ret = -EINVAL; - goto out; - } - - command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK; - if (command >= ARRAY_SIZE(uverbs_ex_cmd_table) || !uverbs_ex_cmd_table[command]) { ret = -ENOSYS;