Re: [PATCH] ceph: Move a variable assignment behind a condition check in __ceph_remove_cap()

Viacheslav Dubeyko <[email protected]> Mon, 13 Jul 2026 15:10:40 -0700
Newsgroups org.kernel.vger.kernel-janitors,org.kernel.vger.ceph-devel,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Mon, 2026-07-13 at 13:35 +0200, Markus Elfring wrote:
> 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.
> 
> Fixes: 38d46409c4639a1d659ebfa70e27a8bed6b8ee1d ("ceph: print cluster
> fsid and client global_id in all debug logs")
> Cc: [email protected]
> Signed-off-by: Markus Elfring <[email protected]>
> ---
>  fs/ceph/caps.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
> index 4b37d9ffdf7f..5b6640707949 100644
> --- a/fs/ceph/caps.c
> +++ b/fs/ceph/caps.c
> @@ -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;

Makes sense.

Reviewed-by: Viacheslav Dubeyko <[email protected]>

Thanks,
Slava.