Skip to content

Commit

Permalink
fs: Make unload_nls() NULL pointer safe
Browse files Browse the repository at this point in the history
Most call sites of unload_nls() do:
	if (nls)
		unload_nls(nls);

Check the pointer inside unload_nls() like we do in kfree() and
simplify the call sites.

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Steve French <[email protected]>
Cc: OGAWA Hirofumi <[email protected]>
Cc: Roman Zippel <[email protected]>
Cc: Dave Kleikamp <[email protected]>
Cc: Petr Vandrovec <[email protected]>
Cc: Anton Altaparmakov <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
KAGA-KOKO authored and Al Viro committed Sep 24, 2009
1 parent 4504230 commit 6d729e4
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 69 deletions.
7 changes: 1 addition & 6 deletions fs/befs/linuxvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,7 @@ befs_put_super(struct super_block *sb)
{
kfree(BEFS_SB(sb)->mount_opts.iocharset);
BEFS_SB(sb)->mount_opts.iocharset = NULL;

if (BEFS_SB(sb)->nls) {
unload_nls(BEFS_SB(sb)->nls);
BEFS_SB(sb)->nls = NULL;
}

unload_nls(BEFS_SB(sb)->nls);
kfree(sb->s_fs_info);
sb->s_fs_info = NULL;
}
Expand Down
3 changes: 1 addition & 2 deletions fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ cifs_read_super(struct super_block *sb, void *data,
cifs_sb->mountdata = NULL;
}
#endif
if (cifs_sb->local_nls)
unload_nls(cifs_sb->local_nls);
unload_nls(cifs_sb->local_nls);
kfree(cifs_sb);
}
return rc;
Expand Down
16 changes: 4 additions & 12 deletions fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,11 @@ static void fat_put_super(struct super_block *sb)

iput(sbi->fat_inode);

if (sbi->nls_disk) {
unload_nls(sbi->nls_disk);
sbi->nls_disk = NULL;
sbi->options.codepage = fat_default_codepage;
}
if (sbi->nls_io) {
unload_nls(sbi->nls_io);
sbi->nls_io = NULL;
}
if (sbi->options.iocharset != fat_default_iocharset) {
unload_nls(sbi->nls_disk);
unload_nls(sbi->nls_io);

if (sbi->options.iocharset != fat_default_iocharset)
kfree(sbi->options.iocharset);
sbi->options.iocharset = fat_default_iocharset;
}

sb->s_fs_info = NULL;
kfree(sbi);
Expand Down
6 changes: 2 additions & 4 deletions fs/hfs/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,8 @@ void hfs_mdb_put(struct super_block *sb)
brelse(HFS_SB(sb)->mdb_bh);
brelse(HFS_SB(sb)->alt_mdb_bh);

if (HFS_SB(sb)->nls_io)
unload_nls(HFS_SB(sb)->nls_io);
if (HFS_SB(sb)->nls_disk)
unload_nls(HFS_SB(sb)->nls_disk);
unload_nls(HFS_SB(sb)->nls_io);
unload_nls(HFS_SB(sb)->nls_disk);

free_pages((unsigned long)HFS_SB(sb)->bitmap, PAGE_SIZE < 8192 ? 1 : 0);
kfree(HFS_SB(sb));
Expand Down
6 changes: 2 additions & 4 deletions fs/hfsplus/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ static void hfsplus_put_super(struct super_block *sb)
iput(HFSPLUS_SB(sb).alloc_file);
iput(HFSPLUS_SB(sb).hidden_dir);
brelse(HFSPLUS_SB(sb).s_vhbh);
if (HFSPLUS_SB(sb).nls)
unload_nls(HFSPLUS_SB(sb).nls);
unload_nls(HFSPLUS_SB(sb).nls);
kfree(sb->s_fs_info);
sb->s_fs_info = NULL;

Expand Down Expand Up @@ -464,8 +463,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)

cleanup:
hfsplus_put_super(sb);
if (nls)
unload_nls(nls);
unload_nls(nls);
return err;
}

Expand Down
8 changes: 2 additions & 6 deletions fs/isofs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ static void isofs_put_super(struct super_block *sb)
#ifdef CONFIG_JOLIET
lock_kernel();

if (sbi->s_nls_iocharset) {
unload_nls(sbi->s_nls_iocharset);
sbi->s_nls_iocharset = NULL;
}
unload_nls(sbi->s_nls_iocharset);

unlock_kernel();
#endif
Expand Down Expand Up @@ -912,8 +909,7 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
printk(KERN_WARNING "%s: get root inode failed\n", __func__);
out_no_inode:
#ifdef CONFIG_JOLIET
if (sbi->s_nls_iocharset)
unload_nls(sbi->s_nls_iocharset);
unload_nls(sbi->s_nls_iocharset);
#endif
goto out_freesbi;
out_no_read:
Expand Down
9 changes: 3 additions & 6 deletions fs/jfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,11 @@ static void jfs_put_super(struct super_block *sb)
rc = jfs_umount(sb);
if (rc)
jfs_err("jfs_umount failed with return code %d", rc);
if (sbi->nls_tab)
unload_nls(sbi->nls_tab);
sbi->nls_tab = NULL;

unload_nls(sbi->nls_tab);

truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
iput(sbi->direct_inode);
sbi->direct_inode = NULL;

kfree(sbi);

Expand Down Expand Up @@ -347,8 +345,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,

if (nls_map != (void *) -1) {
/* Discard old (if remount) */
if (sbi->nls_tab)
unload_nls(sbi->nls_tab);
unload_nls(sbi->nls_tab);
sbi->nls_tab = nls_map;
}
return 1;
Expand Down
12 changes: 2 additions & 10 deletions fs/ncpfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,8 @@ static void ncp_put_super(struct super_block *sb)

#ifdef CONFIG_NCPFS_NLS
/* unload the NLS charsets */
if (server->nls_vol)
{
unload_nls(server->nls_vol);
server->nls_vol = NULL;
}
if (server->nls_io)
{
unload_nls(server->nls_io);
server->nls_io = NULL;
}
unload_nls(server->nls_vol);
unload_nls(server->nls_io);
#endif /* CONFIG_NCPFS_NLS */

if (server->info_filp)
Expand Down
6 changes: 2 additions & 4 deletions fs/ncpfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,8 @@ ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
oldset_io = server->nls_io;
server->nls_io = iocharset;

if (oldset_cp)
unload_nls(oldset_cp);
if (oldset_io)
unload_nls(oldset_io);
unload_nls(oldset_cp);
unload_nls(oldset_io);

return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion fs/nls/nls_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ struct nls_table *load_nls(char *charset)

void unload_nls(struct nls_table *nls)
{
module_put(nls->owner);
if (nls)
module_put(nls->owner);
}

static const wchar_t charset2uni[256] = {
Expand Down
10 changes: 4 additions & 6 deletions fs/ntfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ static bool parse_options(ntfs_volume *vol, char *opt)
v, old_nls->charset);
nls_map = old_nls;
} else /* nls_map */ {
if (old_nls)
unload_nls(old_nls);
unload_nls(old_nls);
}
} else if (!strcmp(p, "utf8")) {
bool val = false;
Expand Down Expand Up @@ -2427,10 +2426,9 @@ static void ntfs_put_super(struct super_block *sb)
ntfs_free(vol->upcase);
vol->upcase = NULL;
}
if (vol->nls_map) {
unload_nls(vol->nls_map);
vol->nls_map = NULL;
}

unload_nls(vol->nls_map);

sb->s_fs_info = NULL;
kfree(vol);

Expand Down
10 changes: 2 additions & 8 deletions fs/smbfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,8 @@ smb_show_options(struct seq_file *s, struct vfsmount *m)
static void
smb_unload_nls(struct smb_sb_info *server)
{
if (server->remote_nls) {
unload_nls(server->remote_nls);
server->remote_nls = NULL;
}
if (server->local_nls) {
unload_nls(server->local_nls);
server->local_nls = NULL;
}
unload_nls(server->remote_nls);
unload_nls(server->local_nls);
}

static void
Expand Down

0 comments on commit 6d729e4

Please sign in to comment.