From: Leon Romanovsky <leonro@mellanox.com>
Date: Wed, 21 Feb 2018 18:12:39 +0200
Subject: RDMA/uverbs: Move uncontext check before SRCU read lock
Patch-mainline: v4.17-rc1
Git-commit: 491d5c6a3023e303cc693b91d9b3a4d54471c944
References: bsc#1103992 FATE#326009
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>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
drivers/infiniband/core/uverbs_main.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -705,6 +705,10 @@ static ssize_t ib_uverbs_write(struct fi
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 fi
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 fi
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;