From: Viacheslav Dubeyko Date: Thu, 6 Nov 2025 23:00:00 +0000 (-0800) Subject: ceph: minor cleanup in ceph_fscrypt_decrypt_extents() X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=23df6ff73982ee310bf28bc29fd050823909a071;p=ceph-client.git ceph: minor cleanup in ceph_fscrypt_decrypt_extents() 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 cc: Alex Markuze cc: Ilya Dryomov cc: Ceph Development --- diff --git a/fs/ceph/crypto.c b/fs/ceph/crypto.c index 9a115282f67d..27ec79b8eb4a 100644 --- a/fs/ceph/crypto.c +++ b/fs/ceph/crypto.c @@ -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;