]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: minor cleanup in ceph_fscrypt_decrypt_extents()
authorViacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Thu, 6 Nov 2025 23:00:00 +0000 (15:00 -0800)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 11 Feb 2026 18:19:17 +0000 (19:19 +0100)
The Coverity Scan service has reported a potential issue
in ceph_fscrypt_decrypt_extents() method [1]. The function
ceph_fscrypt_decrypt_page() can return the negative value as
an error code. Logic of ceph_fscrypt_decrypt_extents()
process this case in correct way. However, it makes sense
to make the minor cleanup of the function logic.

This patch adds several unlikely macros to conditions checks
and it reworks fret variable check by adding else statement
to the condition check.

[1] https://scan5.scan.coverity.com/#/project-view/64304/10063?selectedIssue=1662519

Signed-off-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
cc: Alex Markuze <amarkuze@redhat.com>
cc: Ilya Dryomov <idryomov@gmail.com>
cc: Ceph Development <ceph-devel@vger.kernel.org>

fs/ceph/crypto.c

index 9a115282f67da95390a659330bacf4b260b3bf79..27ec79b8eb4a7a7825c8dcaf9e7c3deabc874047 100644 (file)
@@ -519,7 +519,7 @@ int ceph_fscrypt_decrypt_extents(struct inode *inode, struct page **page,
        u32 xlen;
 
        /* Nothing to do for empty array */
-       if (ext_cnt == 0) {
+       if (unlikely(ext_cnt == 0)) {
                doutc(cl, "%p %llx.%llx empty array, ret 0\n", inode,
                      ceph_vinop(inode));
                return 0;
@@ -534,7 +534,7 @@ int ceph_fscrypt_decrypt_extents(struct inode *inode, struct page **page,
                int pgidx = pgsoff >> PAGE_SHIFT;
                int fret;
 
-               if ((ext->off | ext->len) & ~CEPH_FSCRYPT_BLOCK_MASK) {
+               if (unlikely((ext->off | ext->len) & ~CEPH_FSCRYPT_BLOCK_MASK)) {
                        pr_warn_client(cl,
                                "%p %llx.%llx bad encrypted sparse extent "
                                "idx %d off %llx len %llx\n",
@@ -546,12 +546,12 @@ int ceph_fscrypt_decrypt_extents(struct inode *inode, struct page **page,
                                                 off + pgsoff, ext->len);
                doutc(cl, "%p %llx.%llx [%d] 0x%llx~0x%llx fret %d\n", inode,
                      ceph_vinop(inode), i, ext->off, ext->len, fret);
-               if (fret < 0) {
+               if (unlikely(fret < 0)) {
                        if (ret == 0)
                                ret = fret;
                        break;
-               }
-               ret = pgsoff + fret;
+               } else
+                       ret = pgsoff + fret;
        }
        doutc(cl, "ret %d\n", ret);
        return ret;