From: Markus Elfring <[email protected]>
Date: Tue, 7 Nov 2017 08:51:00 +0100

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---

v1 - Request for comments:
I can offer another bit of information for a software development discussion. ๐Ÿ’ญ

The affected source file can be compiled for the processor architecture โ€œx86_64โ€
by a tool like โ€œGCC 6.4.1+r251631-1.3โ€ from the software distribution
โ€œopenSUSE Tumbleweedโ€ with the following command example.

my_cc=/usr/bin/gcc-6 \
&& my_module=fs/nfs/write.o \
&& for XYZ in 0 s 3; do echo "   _____ $XYZ _____" \
&& my_extra="-O$XYZ" \
&& git checkout next-20171102 \
&& make -j4 CC="${my_cc}" HOSTCC="${my_cc}" EXTRA_CFLAGS="${my_extra}" 
allmodconfig "${my_module}" \
&& size "${my_module}" \
&& git checkout ':/^nfs/write: Use common error handling code in 
nfs_lock_and_join_requests' \
&& make -j4 CC="${my_cc}" HOSTCC="${my_cc}" EXTRA_CFLAGS="${my_extra}" 
allmodconfig "${my_module}" \
&& size "${my_module}"; done


๐Ÿ”ฎ Do you find the following differences worth for further clarification?

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•—
โ•‘ setting โ”‚ text โ•‘
โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•ฃ
โ•‘   O0    โ”‚ ???  โ•‘   Compilation failure?
โ•‘   Os    โ”‚ -17  โ•‘
โ•‘   O3    โ”‚ -16  โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•


 fs/nfs/write.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index babebbccae2a..5b5f464f6f2a 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -487,10 +487,8 @@ nfs_lock_and_join_requests(struct page *page)
        }
 
        ret = nfs_page_group_lock(head);
-       if (ret < 0) {
-               nfs_unlock_and_release_request(head);
-               return ERR_PTR(ret);
-       }
+       if (ret < 0)
+               goto release_request;
 
        /* lock each request in the page group */
        total_bytes = head->wb_bytes;
@@ -515,8 +513,7 @@ nfs_lock_and_join_requests(struct page *page)
                        if (ret < 0) {
                                nfs_unroll_locks(inode, head, subreq);
                                nfs_release_request(subreq);
-                               nfs_unlock_and_release_request(head);
-                               return ERR_PTR(ret);
+                               goto release_request;
                        }
                }
                /*
@@ -532,8 +529,8 @@ nfs_lock_and_join_requests(struct page *page)
                        nfs_page_group_unlock(head);
                        nfs_unroll_locks(inode, head, subreq);
                        nfs_unlock_and_release_request(subreq);
-                       nfs_unlock_and_release_request(head);
-                       return ERR_PTR(-EIO);
+                       ret = -EIO;
+                       goto release_request;
                }
        }
 
@@ -576,6 +573,10 @@ nfs_lock_and_join_requests(struct page *page)
        /* still holds ref on head from nfs_page_find_head_request
         * and still has lock on head from lock loop */
        return head;
+
+release_request:
+       nfs_unlock_and_release_request(head);
+       return ERR_PTR(ret);
 }
 
 static void nfs_write_error_remove_page(struct nfs_page *req)
-- 
2.15.0

Reply via email to