All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eli Cohen <eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
To: dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org,
	ydroneaud-RlY5vtjFyJ3QT0dZR+AlfA@public.gmane.org
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	eranbe-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	matanbe-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	Eli Cohen <eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: [PATCH ib-next 1/3] IB/core: Avoid duplicate code
Date: Thu,  5 Nov 2015 19:40:06 +0200	[thread overview]
Message-ID: <1446745208-17733-2-git-send-email-eli@mellanox.com> (raw)
In-Reply-To: <1446745208-17733-1-git-send-email-eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>

Move the check on the validity of the command to a common area.

Signed-off-by: Eli Cohen <eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
 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 e3ef28861be6..e93ba9125198 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -678,6 +678,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;
@@ -696,20 +697,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;
@@ -738,21 +737,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;
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-11-05 17:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 17:40 [PATCH ib-next 0/3] IB core uverbs support for leagacy commands Eli Cohen
     [not found] ` <1446745208-17733-1-git-send-email-eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-11-05 17:40   ` Eli Cohen [this message]
2015-11-05 17:40   ` [PATCH ib-next 2/3] IB/core: IB/core: Allow legacy verbs through extended interfaces Eli Cohen
     [not found]     ` <1446745208-17733-3-git-send-email-eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-11-08 15:04       ` Matan Barak
     [not found]         ` <CAAKD3BDq_o+J3yM1qAKg_x35Dps5Ne_ffaD_Mz55a272pwQcJg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-11-09  6:48           ` Haggai Eran
     [not found]             ` <564041C4.1090303-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-11-09 22:35               ` Jason Gunthorpe
     [not found]                 ` <20151109223531.GB1305-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-11-09 23:05                   ` Eli Cohen
     [not found]                     ` <20151109230531.GF20103-lgQlq6cFzJSjLWYaRI30zHI+JuX82XLG@public.gmane.org>
2015-11-09 23:15                       ` Jason Gunthorpe
     [not found]                         ` <20151109231542.GA20707-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-11-09 23:24                           ` Eli Cohen
     [not found]                             ` <20151109232431.GA114170-lgQlq6cFzJSjLWYaRI30zHI+JuX82XLG@public.gmane.org>
2015-11-09 23:30                               ` Jason Gunthorpe
     [not found]                                 ` <20151109233059.GA21475-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-11-10 15:23                                   ` Eli Cohen
     [not found]                                     ` <20151110152310.GB114170-lgQlq6cFzJSjLWYaRI30zHI+JuX82XLG@public.gmane.org>
2015-11-10 15:40                                       ` Eli Cohen
     [not found]                                         ` <20151110154026.GC114170-lgQlq6cFzJSjLWYaRI30zHI+JuX82XLG@public.gmane.org>
2015-11-10 17:28                                           ` Jason Gunthorpe
2015-11-10 19:23                                           ` Bart Van Assche
     [not found]                                             ` <56424437.9090908-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-10 20:02                                               ` Eli Cohen
     [not found]                                                 ` <20151110200226.GB21849-lgQlq6cFzJSjLWYaRI30zHI+JuX82XLG@public.gmane.org>
2015-11-10 20:10                                                   ` Jason Gunthorpe
2015-11-10 10:25                           ` Matan Barak
     [not found]                             ` <CAAKD3BAkJiYV8mHUUqAwPZwCsyRR7579+jUC4idGy6snM6rbHA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-11-10 17:39                               ` Jason Gunthorpe
2015-11-09 15:55           ` Eli Cohen
     [not found]             ` <20151109155539.GA116821-lgQlq6cFzJSjLWYaRI30zHI+JuX82XLG@public.gmane.org>
2015-11-09 16:11               ` Matan Barak
     [not found]                 ` <CAAKD3BAJi0XSU1VW10jogaHL7wYT6fcDSw=q1Zpu+4+Mf760nQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-11-09 16:25                   ` Eli Cohen
     [not found]                     ` <20151109162513.GB116821-lgQlq6cFzJSjLWYaRI30zHI+JuX82XLG@public.gmane.org>
2015-11-09 16:29                       ` Matan Barak
2015-11-05 17:40   ` [PATCH ib-next 3/3] IB/core: Modify conditional on ucontext existence Eli Cohen
2015-11-19 21:56   ` [PATCH ib-next 0/3] IB core uverbs support for leagacy commands Eli Cohen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446745208-17733-2-git-send-email-eli@mellanox.com \
    --to=eli-vpraknaxozvwk0htik3j/w@public.gmane.org \
    --cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=eranbe-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=matanbe-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=ydroneaud-RlY5vtjFyJ3QT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.