Commit 015f0212d51d85bd281a831639a769b4a1a3307a

Authored by Jeff Layton
Committed by Trond Myklebust
1 parent 568a810d7e

nfs: handle lock context allocation failures in nfs_create_request

nfs_get_lock_context can return NULL on an allocation failure.
Regression introduced by commit f11ac8db.

Reported-by: Steve Dickson <steved@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Cc: stable@kernel.org
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

Showing 1 changed file with 7 additions and 1 deletions Side-by-side Diff

... ... @@ -65,6 +65,13 @@
65 65 if (req == NULL)
66 66 return ERR_PTR(-ENOMEM);
67 67  
  68 + /* get lock context early so we can deal with alloc failures */
  69 + req->wb_lock_context = nfs_get_lock_context(ctx);
  70 + if (req->wb_lock_context == NULL) {
  71 + nfs_page_free(req);
  72 + return ERR_PTR(-ENOMEM);
  73 + }
  74 +
68 75 /* Initialize the request struct. Initially, we assume a
69 76 * long write-back delay. This will be adjusted in
70 77 * update_nfs_request below if the region is not locked. */
... ... @@ -79,7 +86,6 @@
79 86 req->wb_pgbase = offset;
80 87 req->wb_bytes = count;
81 88 req->wb_context = get_nfs_open_context(ctx);
82   - req->wb_lock_context = nfs_get_lock_context(ctx);
83 89 kref_init(&req->wb_kref);
84 90 return req;
85 91 }