Blob Blame History Raw
From 2ff83650a5f05e3f06853df6d79d3b18f88dfb23 Mon Sep 17 00:00:00 2001
From: Nikhil Ladha <nladha@redhat.com>
Date: Thu, 6 May 2021 10:45:46 +0530
Subject: [PATCH 602/610] coverity: null dereference (#2395)

Fix:
Updated the code to make it more readable and fixed
the NULL dereferencing.

CID: 1234622
>Updates: #1060

>Change-Id: I05bd203bc46fe84be86398bd664a3485409c3bfe
>Signed-off-by: nik-redhat <nladha@redhat.com>

Upstream link: https://github.com/gluster/glusterfs/pull/2395
BUG: 1997447

Change-Id: If39cc85115de673a83b6c97137ea8d1f0f825245
Signed-off-by: nik-redhat <nladha@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/280093
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
 xlators/cluster/dht/src/dht-lock.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/xlators/cluster/dht/src/dht-lock.c b/xlators/cluster/dht/src/dht-lock.c
index f9bac4f..6474dfa 100644
--- a/xlators/cluster/dht/src/dht-lock.c
+++ b/xlators/cluster/dht/src/dht-lock.c
@@ -914,37 +914,35 @@ dht_nonblocking_inodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
     dht_local_t *local = NULL;
     int lk_index = 0, call_cnt = 0;
     char gfid[GF_UUID_BUF_SIZE] = {0};
+    dht_ilock_wrap_t *my_layout;
 
     local = frame->local;
     lk_index = (long)cookie;
 
+    my_layout = &(local->lock[0].layout.my_layout);
+
     if (op_ret == -1) {
-        local->lock[0].layout.my_layout.op_ret = -1;
-        local->lock[0].layout.my_layout.op_errno = op_errno;
-
-        if (local && local->lock[0].layout.my_layout.locks[lk_index]) {
-            uuid_utoa_r(local->lock[0]
-                            .layout.my_layout.locks[lk_index]
-                            ->loc.inode->gfid,
-                        gfid);
-
-            gf_msg_debug(
-                this->name, op_errno,
-                "inodelk failed on gfid: %s "
-                "subvolume: %s",
-                gfid,
-                local->lock[0].layout.my_layout.locks[lk_index]->xl->name);
+        my_layout->op_ret = -1;
+        my_layout->op_errno = op_errno;
+
+        if (my_layout->locks[lk_index]) {
+            uuid_utoa_r(my_layout->locks[lk_index]->loc.inode->gfid, gfid);
+
+            gf_msg_debug(this->name, op_errno,
+                         "inodelk failed on gfid: %s "
+                         "subvolume: %s",
+                         gfid, my_layout->locks[lk_index]->xl->name);
         }
 
         goto out;
     }
 
-    local->lock[0].layout.my_layout.locks[lk_index]->locked = _gf_true;
+    my_layout->locks[lk_index]->locked = _gf_true;
 
 out:
     call_cnt = dht_frame_return(frame);
     if (is_last_call(call_cnt)) {
-        if (local->lock[0].layout.my_layout.op_ret < 0) {
+        if (my_layout->op_ret < 0) {
             dht_inodelk_cleanup(frame);
             return 0;
         }
-- 
1.8.3.1