]> 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>
Mon, 16 Mar 2026 10:08:34 +0000 (11:08 +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 f3de43ccb470ddbd7945426d79f9024ae615c127..dce6fdf700e1266882b20ca98cfad7bd95bdbcdd 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;