Skip to content

Commit 12c30f3

Browse files
Paulo AlcantaraSteve French
authored andcommitted
smb: client: fix warning in cifs_smb3_do_mount()
This fixes the following warning reported by kernel test robot fs/smb/client/cifsfs.c:982 cifs_smb3_do_mount() warn: possible memory leak of 'cifs_sb' Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent fc1bd51 commit 12c30f3

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

fs/smb/client/cifsfs.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,11 @@ struct dentry *
886886
cifs_smb3_do_mount(struct file_system_type *fs_type,
887887
int flags, struct smb3_fs_context *old_ctx)
888888
{
889-
int rc;
890-
struct super_block *sb = NULL;
891-
struct cifs_sb_info *cifs_sb = NULL;
892889
struct cifs_mnt_data mnt_data;
890+
struct cifs_sb_info *cifs_sb;
891+
struct super_block *sb;
893892
struct dentry *root;
893+
int rc;
894894

895895
if (cifsFYI) {
896896
cifs_dbg(FYI, "%s: devname=%s flags=0x%x\n", __func__,
@@ -899,11 +899,9 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
899899
cifs_info("Attempting to mount %s\n", old_ctx->source);
900900
}
901901

902-
cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
903-
if (cifs_sb == NULL) {
904-
root = ERR_PTR(-ENOMEM);
905-
goto out;
906-
}
902+
cifs_sb = kzalloc(sizeof(*cifs_sb), GFP_KERNEL);
903+
if (!cifs_sb)
904+
return ERR_PTR(-ENOMEM);
907905

908906
cifs_sb->ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
909907
if (!cifs_sb->ctx) {
@@ -940,10 +938,8 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
940938

941939
sb = sget(fs_type, cifs_match_super, cifs_set_super, flags, &mnt_data);
942940
if (IS_ERR(sb)) {
943-
root = ERR_CAST(sb);
944941
cifs_umount(cifs_sb);
945-
cifs_sb = NULL;
946-
goto out;
942+
return ERR_CAST(sb);
947943
}
948944

949945
if (sb->s_root) {
@@ -974,13 +970,9 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
974970
deactivate_locked_super(sb);
975971
return root;
976972
out:
977-
if (cifs_sb) {
978-
if (!sb || IS_ERR(sb)) { /* otherwise kill_sb will handle */
979-
kfree(cifs_sb->prepath);
980-
smb3_cleanup_fs_context(cifs_sb->ctx);
981-
kfree(cifs_sb);
982-
}
983-
}
973+
kfree(cifs_sb->prepath);
974+
smb3_cleanup_fs_context(cifs_sb->ctx);
975+
kfree(cifs_sb);
984976
return root;
985977
}
986978

0 commit comments

Comments
 (0)