From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/infiniband/core/uverbs_cmd.c

Change-Id: I074f44ebe16a0222d717f2d1f00b59c3e5c5ade0
---
 drivers/infiniband/core/uverbs_cmd.c | 30 +++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -217,6 +217,10 @@ int ib_alloc_ucontext(struct uverbs_attr
 	ucontext = rdma_zalloc_drv_obj(ib_dev, ib_ucontext);
 	if (!ucontext)
 		return -ENOMEM;
+#ifndef HAVE_MMU_NOTIFIER_OPS_HAS_FREE_NOTIFIER
+	mutex_init(&ucontext->per_mm_list_lock);
+	INIT_LIST_HEAD(&ucontext->per_mm_list);
+#endif
 
 	ucontext->device = ib_dev;
 	ucontext->ufile = ufile;
@@ -572,7 +576,11 @@ static int ib_uverbs_open_xrcd(struct uv
 	struct inode                   *inode = NULL;
 	int				new_xrcd = 0;
 	struct ib_device *ib_dev;
+#if defined(HAVE_FD_FILE)
+	struct fd f = EMPTY_FD;
+#else
 	struct fd f = {};
+#endif
 	int ret;
 
 	ret = uverbs_request(attrs, &cmd, sizeof(cmd));
@@ -584,12 +592,20 @@ static int ib_uverbs_open_xrcd(struct uv
 	if (cmd.fd != -1) {
 		/* search for file descriptor */
 		f = fdget(cmd.fd);
+#if defined(HAVE_FD_FILE)
+		if (!fd_file(f)) {
+#else
 		if (!f.file) {
+#endif
 			ret = -EBADF;
 			goto err_tree_mutex_unlock;
 		}
 
+#if defined(HAVE_FD_FILE)
+		inode = file_inode(fd_file(f));
+#else
 		inode = file_inode(f.file);
+#endif
 		xrcd = find_xrcd(ibudev, inode);
 		if (!xrcd && !(cmd.oflags & O_CREAT)) {
 			/* no file descriptor. Need CREATE flag */
@@ -632,7 +648,11 @@ static int ib_uverbs_open_xrcd(struct uv
 		atomic_inc(&xrcd->usecnt);
 	}
 
+#if defined(HAVE_FD_FILE)
+	if (fd_file(f))
+#else
 	if (f.file)
+#endif
 		fdput(f);
 
 	mutex_unlock(&ibudev->xrcd_tree_mutex);
@@ -648,7 +668,11 @@ err:
 	uobj_alloc_abort(&obj->uobject, attrs);
 
 err_tree_mutex_unlock:
+#if defined(HAVE_FD_FILE)
+	if (fd_file(f))
+#else
 	if (f.file)
+#endif
 		fdput(f);
 
 	mutex_unlock(&ibudev->xrcd_tree_mutex);
@@ -3366,7 +3390,11 @@ static int __uverbs_create_xsrq(struct u
 	struct ib_srq                   *srq;
 	struct ib_srq_init_attr          attr;
 	int ret;
-	struct ib_uobject *xrcd_uobj;
+#ifndef uninitialized_var
+	struct ib_uobject               *xrcd_uobj;
+#else
+	struct ib_uobject               *uninitialized_var(xrcd_uobj);
+#endif
 	struct ib_device *ib_dev;
 
 	obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, attrs,
