ceph: fix variable dereferenced before check in ceph_umount_begin()
authorViacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Mon, 2 Jun 2025 18:49:56 +0000 (11:49 -0700)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 6 Jun 2025 09:08:59 +0000 (11:08 +0200)
smatch warnings:
fs/ceph/super.c:1042 ceph_umount_begin() warn: variable dereferenced before check 'fsc' (see line 1041)

vim +/fsc +1042 fs/ceph/super.c

void ceph_umount_begin(struct super_block *sb)
{
struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);

doutc(fsc->client, "starting forced umount\n");
              ^^^^^^^^^^^
Dereferenced

if (!fsc)
            ^^^^
Checked too late.

return;
fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
__ceph_umount_begin(fsc);
}

The VFS guarantees that the superblock is still
alive when it calls into ceph via ->umount_begin().
Finally, we don't need to check the fsc and
it should be valid. This patch simply removes
the fsc check.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202503280852.YDB3pxUY-lkp@intel.com/
Signed-off-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Reviewed by: Alex Markuze <amarkuze@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/super.c

index fc4cab8b7b7781c5b9b24d9a6d2bc323334c8220..2b8438d8a32412126d70690fb5d1457bf5e810da 100644 (file)
@@ -1033,8 +1033,7 @@ void ceph_umount_begin(struct super_block *sb)
        struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 
        doutc(fsc->client, "starting forced umount\n");
-       if (!fsc)
-               return;
+
        fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
        __ceph_umount_begin(fsc);
 }