]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/uverbs: Move uncontext check before SRCU read lock
authorLeon Romanovsky <leonro@mellanox.com>
Wed, 21 Feb 2018 16:12:39 +0000 (18:12 +0200)
committerDoug Ledford <dledford@redhat.com>
Fri, 23 Feb 2018 03:29:50 +0000 (22:29 -0500)
There is no need to take SRCU lock before checking
file->ucontext, so move it do it before it.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/uverbs_main.c

index 1f2fd839953f64dacd5e6e4ddaf6217ba205400d..ff70e1ead1badd9d159305bd164a4e78d70bb6bd 100644 (file)
@@ -705,6 +705,10 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
        if (ret)
                return ret;
 
+       if (!file->ucontext &&
+           (command != IB_USER_VERBS_CMD_GET_CONTEXT || extended))
+               return -EINVAL;
+
        if (extended && count < (sizeof(hdr) + sizeof(ex_hdr)))
                return -EINVAL;
 
@@ -721,12 +725,6 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
                goto out;
        }
 
-       if (!file->ucontext &&
-           command != IB_USER_VERBS_CMD_GET_CONTEXT) {
-               ret = -EINVAL;
-               goto out;
-       }
-
        if (!extended) {
                if (hdr.in_words * 4 != count) {
                        ret = -EINVAL;
@@ -742,11 +740,6 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
                struct ib_udata uhw;
                size_t written_count = count;
 
-               if (!file->ucontext) {
-                       ret = -EINVAL;
-                       goto out;
-               }
-
                if (copy_from_user(&ex_hdr, buf + sizeof(hdr), sizeof(ex_hdr))) {
                        ret = -EFAULT;
                        goto out;