Whamcloud - gitweb
LU-11610 target: Fix correct return value in out_handler.c 60/56260/5
authorRonnie Sahlberg <rsahlberg@whamcloud.com>
Wed, 4 Sep 2024 04:48:48 +0000 (00:48 -0400)
committerOleg Drokin <green@whamcloud.com>
Mon, 2 Dec 2024 05:40:32 +0000 (05:40 +0000)
out_handler.c has a pattern:

    if (IS_ERR(x) || expression) {
        ...
        RETURN(PTR_ERR(x))
    }

which if x is a valid pointer but the expression that represents an
error would cause the function to return PTR_ERR(x) for a valid pointer.
Fix this by either returning PTR_ERR(x) or -EPROTO depending on what the error
is.

Signed-off-by: Ronnie Sahlberg <rsahlberg@whamcloud.com>
Change-Id: Ic9f3427be31a9ba84b46f349ba90cc6aea379845
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56260
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/target/out_handler.c

index 77e22ab..58b829c 100644 (file)
@@ -59,10 +59,17 @@ static int out_create(struct tgt_session_info *tsi)
        ENTRY;
 
        wobdo = object_update_param_get(update, 0, &size);
-       if (IS_ERR(wobdo) || size != sizeof(*wobdo)) {
-               CERROR("%s: obdo is NULL, invalid RPC: rc = %ld\n",
-                      tgt_name(tsi->tsi_tgt), PTR_ERR(wobdo));
-               RETURN(PTR_ERR(wobdo));
+       if (IS_ERR(wobdo)) {
+               rc = PTR_ERR(wobdo);
+               CERROR("%s: obdo is NULL, invalid RPC: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), rc);
+               RETURN(rc);
+       }
+       if (size != sizeof(*wobdo)) {
+               rc = -EPROTO;
+               CERROR("%s: wrong size for obdo %zu != %zu, invalid RPC: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), size, sizeof(*wobdo), rc);
+               RETURN(rc);
        }
 
        if (req_capsule_req_need_swab(tsi->tsi_pill))
@@ -73,10 +80,17 @@ static int out_create(struct tgt_session_info *tsi)
        dof->dof_type = dt_mode_to_dft(attr->la_mode);
        if (update->ou_params_count > 1) {
                fid = object_update_param_get(update, 1, &size);
-               if (IS_ERR(fid) || size != sizeof(*fid)) {
-                       CERROR("%s: invalid fid: rc = %ld\n",
-                              tgt_name(tsi->tsi_tgt), PTR_ERR(fid));
-                       RETURN(PTR_ERR(fid));
+               if (IS_ERR(fid)) {
+                       rc = PTR_ERR(fid);
+                       CERROR("%s: invalid fid: rc = %d\n",
+                              tgt_name(tsi->tsi_tgt), rc);
+                       RETURN(rc);
+               }
+               if (size != sizeof(*fid)) {
+                       rc = -EPROTO;
+                       CERROR("%s: wrong size for fid %zu != %zu: rc = %d\n",
+                              tgt_name(tsi->tsi_tgt), size, sizeof(*fid), rc);
+                       RETURN(rc);
                }
                if (req_capsule_req_need_swab(tsi->tsi_pill))
                        lustre_swab_lu_fid(fid);
@@ -112,10 +126,17 @@ static int out_attr_set(struct tgt_session_info *tsi)
        ENTRY;
 
        wobdo = object_update_param_get(update, 0, &size);
-       if (IS_ERR(wobdo) || size != sizeof(*wobdo)) {
-               CERROR("%s: empty obdo in the update: rc = %ld\n",
-                      tgt_name(tsi->tsi_tgt), PTR_ERR(wobdo));
-               RETURN(PTR_ERR(wobdo));
+       if (IS_ERR(wobdo)) {
+               rc = PTR_ERR(wobdo);
+               CERROR("%s: empty obdo in the update: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), rc);
+               RETURN(rc);
+       }
+       if (size != sizeof(*wobdo)) {
+               rc = -EPROTO;
+               CERROR("%s: wrong size for obdo %zu != %zu in the update: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), size, sizeof(*wobdo), rc);
+               RETURN(rc);
        }
 
        attr->la_valid = 0;
@@ -381,10 +402,17 @@ static int out_xattr_set(struct tgt_session_info *tsi)
        lbuf->lb_len = buf_len;
 
        tmp = object_update_param_get(update, 2, &size);
-       if (IS_ERR(tmp) || size != sizeof(*tmp)) {
-               CERROR("%s: emptry or wrong size %zu flag: rc = %ld\n",
-                      tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp));
-               RETURN(PTR_ERR(tmp));
+       if (IS_ERR(tmp)) {
+               rc = PTR_ERR(tmp);
+               CERROR("%s: emptry flag: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), rc);
+               RETURN(rc);
+       }
+       if (size != sizeof(*tmp)) {
+               rc = -EPROTO;
+               CERROR("%s: wrong size for flag %zu != %zu: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), size, sizeof(*tmp), rc);
+               RETURN(rc);
        }
 
        if (req_capsule_req_need_swab(tsi->tsi_pill))
@@ -478,10 +506,17 @@ static int out_index_insert(struct tgt_session_info *tsi)
        }
 
        fid = object_update_param_get(update, 1, &size);
-       if (IS_ERR(fid) || size != sizeof(*fid)) {
-               CERROR("%s: invalid fid: rc = %ld\n",
-                      tgt_name(tsi->tsi_tgt), PTR_ERR(fid));
-               RETURN(PTR_ERR(fid));
+       if (IS_ERR(fid)) {
+               rc = PTR_ERR(fid);
+               CERROR("%s: invalid fid: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), rc);
+               RETURN(rc);
+       }
+       if (size != sizeof(*fid)) {
+               rc = -EPROTO;
+               CERROR("%s: wrong size for fid %zu != %zu: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), size, sizeof(*fid), rc);
+               RETURN(rc);
        }
 
        if (req_capsule_req_need_swab(tsi->tsi_pill))
@@ -494,10 +529,17 @@ static int out_index_insert(struct tgt_session_info *tsi)
        }
 
        ptype = object_update_param_get(update, 2, &size);
-       if (IS_ERR(ptype) || size != sizeof(*ptype)) {
-               CERROR("%s: invalid type for index insert: rc = %ld\n",
-                      tgt_name(tsi->tsi_tgt), PTR_ERR(ptype));
-               RETURN(PTR_ERR(ptype));
+       if (IS_ERR(ptype)) {
+               rc = PTR_ERR(ptype);
+               CERROR("%s: invalid type for index insert: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), rc);
+               RETURN(rc);
+       }
+       if (size != sizeof(*ptype)) {
+               rc = -EPROTO;
+               CERROR("%s: wrong size for index insert %zu != %zu: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), size, sizeof(*ptype), rc);
+               RETURN(rc);
        }
 
        if (req_capsule_req_need_swab(tsi->tsi_pill))
@@ -589,19 +631,33 @@ static int out_write(struct tgt_session_info *tsi)
        ENTRY;
 
        buf = object_update_param_get(update, 0, &buf_len);
-       if (IS_ERR(buf) || buf_len == 0) {
-               CERROR("%s: empty buf for xattr set: rc = %ld\n",
-                      tgt_name(tsi->tsi_tgt), PTR_ERR(buf));
-               RETURN(PTR_ERR(buf));
+       if (IS_ERR(buf)) {
+               rc = PTR_ERR(buf);
+               CERROR("%s: empty buf for xattr set: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), rc);
+               RETURN(rc);
+       }
+       if (buf_len == 0) {
+               rc = -EPROTO;
+               CERROR("%s: wrong buf_len %zu != 0 for xattr set: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), buf_len, rc);
+               RETURN(rc);
        }
        lbuf->lb_buf = buf;
        lbuf->lb_len = buf_len;
 
        tmp = object_update_param_get(update, 1, &size);
-       if (IS_ERR(tmp) || size != sizeof(*tmp)) {
-               CERROR("%s: empty or wrong size %zu pos: rc = %ld\n",
-                      tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp));
-               RETURN(PTR_ERR(tmp));
+       if (IS_ERR(tmp)) {
+               rc = PTR_ERR(tmp);
+               CERROR("%s: empty pos: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), rc);
+               RETURN(rc);
+       }
+       if (size != sizeof(*tmp)) {
+               rc = -EPROTO;
+               CERROR("%s: wrong size for pos %zu != %zu: rc = %d\n",
+                      tgt_name(tsi->tsi_tgt), size, sizeof(*tmp), rc);
+               RETURN(rc);
        }
 
        if (req_capsule_req_need_swab(tsi->tsi_pill))