Commit 6d729e44 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Al Viro

fs: Make unload_nls() NULL pointer safe

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: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Steve French <sfrench@us.ibm.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Roman Zippel <zippel@linux-m68k.org>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Petr Vandrovec <vandrove@vc.cvut.cz>
Cc: Anton Altaparmakov <aia21@cantab.net>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 4504230a
...@@ -737,12 +737,7 @@ befs_put_super(struct super_block *sb) ...@@ -737,12 +737,7 @@ befs_put_super(struct super_block *sb)
{ {
kfree(BEFS_SB(sb)->mount_opts.iocharset); kfree(BEFS_SB(sb)->mount_opts.iocharset);
BEFS_SB(sb)->mount_opts.iocharset = NULL; BEFS_SB(sb)->mount_opts.iocharset = NULL;
if (BEFS_SB(sb)->nls) {
unload_nls(BEFS_SB(sb)->nls); unload_nls(BEFS_SB(sb)->nls);
BEFS_SB(sb)->nls = NULL;
}
kfree(sb->s_fs_info); kfree(sb->s_fs_info);
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
} }
......
...@@ -185,7 +185,6 @@ cifs_read_super(struct super_block *sb, void *data, ...@@ -185,7 +185,6 @@ cifs_read_super(struct super_block *sb, void *data,
cifs_sb->mountdata = NULL; cifs_sb->mountdata = NULL;
} }
#endif #endif
if (cifs_sb->local_nls)
unload_nls(cifs_sb->local_nls); unload_nls(cifs_sb->local_nls);
kfree(cifs_sb); kfree(cifs_sb);
} }
......
...@@ -470,19 +470,11 @@ static void fat_put_super(struct super_block *sb) ...@@ -470,19 +470,11 @@ static void fat_put_super(struct super_block *sb)
iput(sbi->fat_inode); iput(sbi->fat_inode);
if (sbi->nls_disk) {
unload_nls(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); unload_nls(sbi->nls_io);
sbi->nls_io = NULL;
} if (sbi->options.iocharset != fat_default_iocharset)
if (sbi->options.iocharset != fat_default_iocharset) {
kfree(sbi->options.iocharset); kfree(sbi->options.iocharset);
sbi->options.iocharset = fat_default_iocharset;
}
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
kfree(sbi); kfree(sbi);
......
...@@ -344,9 +344,7 @@ void hfs_mdb_put(struct super_block *sb) ...@@ -344,9 +344,7 @@ void hfs_mdb_put(struct super_block *sb)
brelse(HFS_SB(sb)->mdb_bh); brelse(HFS_SB(sb)->mdb_bh);
brelse(HFS_SB(sb)->alt_mdb_bh); brelse(HFS_SB(sb)->alt_mdb_bh);
if (HFS_SB(sb)->nls_io)
unload_nls(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_disk);
free_pages((unsigned long)HFS_SB(sb)->bitmap, PAGE_SIZE < 8192 ? 1 : 0); free_pages((unsigned long)HFS_SB(sb)->bitmap, PAGE_SIZE < 8192 ? 1 : 0);
......
...@@ -229,7 +229,6 @@ static void hfsplus_put_super(struct super_block *sb) ...@@ -229,7 +229,6 @@ static void hfsplus_put_super(struct super_block *sb)
iput(HFSPLUS_SB(sb).alloc_file); iput(HFSPLUS_SB(sb).alloc_file);
iput(HFSPLUS_SB(sb).hidden_dir); iput(HFSPLUS_SB(sb).hidden_dir);
brelse(HFSPLUS_SB(sb).s_vhbh); 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); kfree(sb->s_fs_info);
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
...@@ -464,7 +463,6 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) ...@@ -464,7 +463,6 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
cleanup: cleanup:
hfsplus_put_super(sb); hfsplus_put_super(sb);
if (nls)
unload_nls(nls); unload_nls(nls);
return err; return err;
} }
......
...@@ -46,10 +46,7 @@ static void isofs_put_super(struct super_block *sb) ...@@ -46,10 +46,7 @@ static void isofs_put_super(struct super_block *sb)
#ifdef CONFIG_JOLIET #ifdef CONFIG_JOLIET
lock_kernel(); lock_kernel();
if (sbi->s_nls_iocharset) {
unload_nls(sbi->s_nls_iocharset); unload_nls(sbi->s_nls_iocharset);
sbi->s_nls_iocharset = NULL;
}
unlock_kernel(); unlock_kernel();
#endif #endif
...@@ -912,7 +909,6 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent) ...@@ -912,7 +909,6 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
printk(KERN_WARNING "%s: get root inode failed\n", __func__); printk(KERN_WARNING "%s: get root inode failed\n", __func__);
out_no_inode: out_no_inode:
#ifdef CONFIG_JOLIET #ifdef CONFIG_JOLIET
if (sbi->s_nls_iocharset)
unload_nls(sbi->s_nls_iocharset); unload_nls(sbi->s_nls_iocharset);
#endif #endif
goto out_freesbi; goto out_freesbi;
......
...@@ -178,13 +178,11 @@ static void jfs_put_super(struct super_block *sb) ...@@ -178,13 +178,11 @@ static void jfs_put_super(struct super_block *sb)
rc = jfs_umount(sb); rc = jfs_umount(sb);
if (rc) if (rc)
jfs_err("jfs_umount failed with return code %d", rc); jfs_err("jfs_umount failed with return code %d", rc);
if (sbi->nls_tab)
unload_nls(sbi->nls_tab); unload_nls(sbi->nls_tab);
sbi->nls_tab = NULL;
truncate_inode_pages(sbi->direct_inode->i_mapping, 0); truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
iput(sbi->direct_inode); iput(sbi->direct_inode);
sbi->direct_inode = NULL;
kfree(sbi); kfree(sbi);
...@@ -347,7 +345,6 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, ...@@ -347,7 +345,6 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
if (nls_map != (void *) -1) { if (nls_map != (void *) -1) {
/* Discard old (if remount) */ /* Discard old (if remount) */
if (sbi->nls_tab)
unload_nls(sbi->nls_tab); unload_nls(sbi->nls_tab);
sbi->nls_tab = nls_map; sbi->nls_tab = nls_map;
} }
......
...@@ -746,16 +746,8 @@ static void ncp_put_super(struct super_block *sb) ...@@ -746,16 +746,8 @@ static void ncp_put_super(struct super_block *sb)
#ifdef CONFIG_NCPFS_NLS #ifdef CONFIG_NCPFS_NLS
/* unload the NLS charsets */ /* unload the NLS charsets */
if (server->nls_vol)
{
unload_nls(server->nls_vol); unload_nls(server->nls_vol);
server->nls_vol = NULL;
}
if (server->nls_io)
{
unload_nls(server->nls_io); unload_nls(server->nls_io);
server->nls_io = NULL;
}
#endif /* CONFIG_NCPFS_NLS */ #endif /* CONFIG_NCPFS_NLS */
if (server->info_filp) if (server->info_filp)
......
...@@ -223,9 +223,7 @@ ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) ...@@ -223,9 +223,7 @@ ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
oldset_io = server->nls_io; oldset_io = server->nls_io;
server->nls_io = iocharset; server->nls_io = iocharset;
if (oldset_cp)
unload_nls(oldset_cp); unload_nls(oldset_cp);
if (oldset_io)
unload_nls(oldset_io); unload_nls(oldset_io);
return 0; return 0;
......
...@@ -270,6 +270,7 @@ struct nls_table *load_nls(char *charset) ...@@ -270,6 +270,7 @@ struct nls_table *load_nls(char *charset)
void unload_nls(struct nls_table *nls) void unload_nls(struct nls_table *nls)
{ {
if (nls)
module_put(nls->owner); module_put(nls->owner);
} }
......
...@@ -201,7 +201,6 @@ static bool parse_options(ntfs_volume *vol, char *opt) ...@@ -201,7 +201,6 @@ static bool parse_options(ntfs_volume *vol, char *opt)
v, old_nls->charset); v, old_nls->charset);
nls_map = old_nls; nls_map = old_nls;
} else /* nls_map */ { } else /* nls_map */ {
if (old_nls)
unload_nls(old_nls); unload_nls(old_nls);
} }
} else if (!strcmp(p, "utf8")) { } else if (!strcmp(p, "utf8")) {
...@@ -2427,10 +2426,9 @@ static void ntfs_put_super(struct super_block *sb) ...@@ -2427,10 +2426,9 @@ static void ntfs_put_super(struct super_block *sb)
ntfs_free(vol->upcase); ntfs_free(vol->upcase);
vol->upcase = NULL; vol->upcase = NULL;
} }
if (vol->nls_map) {
unload_nls(vol->nls_map); unload_nls(vol->nls_map);
vol->nls_map = NULL;
}
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
kfree(vol); kfree(vol);
......
...@@ -459,14 +459,8 @@ smb_show_options(struct seq_file *s, struct vfsmount *m) ...@@ -459,14 +459,8 @@ smb_show_options(struct seq_file *s, struct vfsmount *m)
static void static void
smb_unload_nls(struct smb_sb_info *server) smb_unload_nls(struct smb_sb_info *server)
{ {
if (server->remote_nls) {
unload_nls(server->remote_nls); unload_nls(server->remote_nls);
server->remote_nls = NULL;
}
if (server->local_nls) {
unload_nls(server->local_nls); unload_nls(server->local_nls);
server->local_nls = NULL;
}
} }
static void static void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment