ceph: Move a variable assignment behind a condition check in __ceph_remove_cap()
Subsystems (2)
PATCH 1/1 ceph: Move a variable assignment behind a condition check in __ceph_remove_cap()
From: Markus Elfring <[email protected]>
Date: Mon, 13 Jul 2026 13:21:29 +0200
The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “__ceph_remove_cap”.
Thus avoid the risk for undefined behaviour by moving the assignment for the variable “inode” behind a condition check.
This issue was detected by using the Coccinelle software.
--- fs/ceph/caps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/caps.c +2 -2
@@ -1124,7 +1124,7 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release)struct ceph_mds_session *session = cap->session;struct ceph_client *cl = session->s_mdsc->fsc->client;struct ceph_inode_info *ci = cap->ci; -struct inode *inode = &ci->netfs.inode; +struct inode *inode;struct ceph_mds_client *mdsc;int removed =0 ;
@@ -1135,7 +1135,7 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) }lockdep_assert_held (&ci->i_ceph_lock); - + inode = &ci->netfs.inode;doutc (cl,"%p from %p %llx.%llx\n" , cap, inode,ceph_vinop (inode)); mdsc =ceph_inode_to_fs_client (&ci->netfs.inode)->mdsc;
Signature · 1 line
2.55.0
Quoted 41 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 13 Jul 2026 13:21:29 +0200The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “__ceph_remove_cap”.
Thus avoid the risk for undefined behaviour by moving the assignment for the variable “inode” behind a condition check.
This issue was detected by using the Coccinelle software.
Fixes 38d46409c4639a1d659ebfa70e27a8bed6b8ee1d ("ceph: print clusterfsid and client
global_idin all debug logs")Signed-off-by Markus Elfring <[email protected]>---
fs/ceph/caps.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/caps.c +1
-1@@ -1124,7 +1124,7 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) struct ceph_mds_session *session = cap->session; struct ceph_client *cl = session->s_mdsc->fsc->client; struct ceph_inode_info *ci = cap->ci; -struct inode *inode = &ci->netfs.inode; +struct inode *inode; struct ceph_mds_client *mdsc; int removed = 0;fs/ceph/caps.c +0
-0@@ -1135,7 +1135,7 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) }
lockdep_assert_held(&ci->i_ceph_lock);fs/ceph/caps.c +1
-1- + inode = &ci->netfs.inode;
Quoted 4 lines
doutc(cl, "%p from %p %llx.%llx\n", cap, inode, ceph_vinop(inode));
mdsc = ceph_inode_to_fs_client(&ci->netfs.inode)->mdsc;
Makes sense.
Thanks,
Slava.
Quoted 11 lines · Viacheslav Dubeyko
Quoted 10 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 13 Jul 2026 13:21:29 +0200The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “__ceph_remove_cap”.
Thus avoid the risk for undefined behaviour by moving the assignment for the variable “inode” behind a condition check.
Quoted 6 lines
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Fixes 38d46409c4639a1d659ebfa70e27a8bed6b8ee1d ("ceph: print clusterfsid and client
global_idin all debug logs")Signed-off-by Markus Elfring <[email protected]>
I have explained to Markus many times that these are not dereferences, they are just pointer math. So the original code works fine and does not need a Fixes tag or a CC to stable.
And then Markus responds, "the C standard says we are not allowed to dereference NULL pointers"... Which is true, but again, it's not a dereference.
regards,
dan carpenter
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “__ceph_remove_cap”.
Thus avoid the risk for undefined behaviour by moving the assignment for the variable “inode” behind a condition check.
This issue was detected by using the Coccinelle software.
Fixes 38d46409c4639a1d659ebfa70e27a8bed6b8ee1d ("ceph: print clusterfsid and client
global_idin all debug logs")
…
Quoted 2 lines
I have explained to Markus many times that these are not dereferences, they are just pointer math.
How does it help to repeat such a questionable development view?
Quoted 6 lines
So the original code works fine and does
not need a Fixes tag or a CC to stable.And then Markus responds, "the C standard says we are not allowed to dereference NULL pointers"... Which is true, but again, it's not a dereference.
Why did you get special difficulties with adhering to standard specifications also in the discussed case?
Regards,
Markus