aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Cohen <eli@mellanox.com>2016-02-14 10:07:47 -0500
committerDoug Ledford <dledford@redhat.com>2016-03-03 10:18:44 -0500
commit74a0b0a5ea6b48f8945e6e900e9c678866aa7520 (patch)
tree1b2d57212e6fb54b13d9f42bc372704849a2cf05
parentbbdfcf18c3b54818d21bf67a3c31779a090887a0 (diff)
IB/core: Avoid duplicate code
Move the check on the validity of the command to a common area. Signed-off-by: Eli Cohen <eli@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/core/uverbs_main.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 39680aed99dd..08f1a7b6d63c 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,
689 struct ib_uverbs_file *file = filp->private_data; 689 struct ib_uverbs_file *file = filp->private_data;
690 struct ib_device *ib_dev; 690 struct ib_device *ib_dev;
691 struct ib_uverbs_cmd_hdr hdr; 691 struct ib_uverbs_cmd_hdr hdr;
692 __u32 command;
692 __u32 flags; 693 __u32 flags;
693 int srcu_key; 694 int srcu_key;
694 ssize_t ret; 695 ssize_t ret;
@@ -707,20 +708,18 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
707 goto out; 708 goto out;
708 } 709 }
709 710
711 if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK |
712 IB_USER_VERBS_CMD_COMMAND_MASK)) {
713 ret = -EINVAL;
714 goto out;
715 }
716
717 command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
718
710 flags = (hdr.command & 719 flags = (hdr.command &
711 IB_USER_VERBS_CMD_FLAGS_MASK) >> IB_USER_VERBS_CMD_FLAGS_SHIFT; 720 IB_USER_VERBS_CMD_FLAGS_MASK) >> IB_USER_VERBS_CMD_FLAGS_SHIFT;
712 721
713 if (!flags) { 722 if (!flags) {
714 __u32 command;
715
716 if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK |
717 IB_USER_VERBS_CMD_COMMAND_MASK)) {
718 ret = -EINVAL;
719 goto out;
720 }
721
722 command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
723
724 if (command >= ARRAY_SIZE(uverbs_cmd_table) || 723 if (command >= ARRAY_SIZE(uverbs_cmd_table) ||
725 !uverbs_cmd_table[command]) { 724 !uverbs_cmd_table[command]) {
726 ret = -EINVAL; 725 ret = -EINVAL;
@@ -749,21 +748,11 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
749 hdr.out_words * 4); 748 hdr.out_words * 4);
750 749
751 } else if (flags == IB_USER_VERBS_CMD_FLAG_EXTENDED) { 750 } else if (flags == IB_USER_VERBS_CMD_FLAG_EXTENDED) {
752 __u32 command;
753
754 struct ib_uverbs_ex_cmd_hdr ex_hdr; 751 struct ib_uverbs_ex_cmd_hdr ex_hdr;
755 struct ib_udata ucore; 752 struct ib_udata ucore;
756 struct ib_udata uhw; 753 struct ib_udata uhw;
757 size_t written_count = count; 754 size_t written_count = count;
758 755
759 if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK |
760 IB_USER_VERBS_CMD_COMMAND_MASK)) {
761 ret = -EINVAL;
762 goto out;
763 }
764
765 command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
766
767 if (command >= ARRAY_SIZE(uverbs_ex_cmd_table) || 756 if (command >= ARRAY_SIZE(uverbs_ex_cmd_table) ||
768 !uverbs_ex_cmd_table[command]) { 757 !uverbs_ex_cmd_table[command]) {
769 ret = -ENOSYS; 758 ret = -ENOSYS;