ceph: minor cleanup in ceph_fscrypt_decrypt_extents()
Viacheslav Dubeyko
maintainerPATCH 1/1 ceph: minor cleanup in ceph_fscrypt_decrypt_extents()
From: Viacheslav Dubeyko <[email protected]>
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 <[email protected]>
cc Alex Markuze <[email protected]>
cc Ilya Dryomov <[email protected]>
cc Ceph Development <[email protected]>
--- fs/ceph/crypto.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/ceph/crypto.c +5 -5
@@ -570,7 +570,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 ;
@@ -585,7 +585,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",
@@ -597,12 +597,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;
Signature · 1 line
2.51.1