diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2009-08-16 17:05:08 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2009-09-24 07:47:42 -0400 |
commit | 6d729e44a55547c009d7a87ea66bff21a8e0afea (patch) | |
tree | c27e69babb9b397ad56cb20a935b75c35ceb364f /fs | |
parent | 4504230a71566785a05d3e6b53fa1ee071b864eb (diff) |
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: Thomas 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: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/befs/linuxvfs.c | 7 | ||||
-rw-r--r-- | fs/cifs/cifsfs.c | 3 | ||||
-rw-r--r-- | fs/fat/inode.c | 16 | ||||
-rw-r--r-- | fs/hfs/mdb.c | 6 | ||||
-rw-r--r-- | fs/hfsplus/super.c | 6 | ||||
-rw-r--r-- | fs/isofs/inode.c | 8 | ||||
-rw-r--r-- | fs/jfs/super.c | 9 | ||||
-rw-r--r-- | fs/ncpfs/inode.c | 12 | ||||
-rw-r--r-- | fs/ncpfs/ioctl.c | 6 | ||||
-rw-r--r-- | fs/nls/nls_base.c | 3 | ||||
-rw-r--r-- | fs/ntfs/super.c | 10 | ||||
-rw-r--r-- | fs/smbfs/inode.c | 10 |
12 files changed, 27 insertions, 69 deletions
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index dd376c124e71..33baf27fac78 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c | |||
@@ -737,12 +737,7 @@ befs_put_super(struct super_block *sb) | |||
737 | { | 737 | { |
738 | kfree(BEFS_SB(sb)->mount_opts.iocharset); | 738 | kfree(BEFS_SB(sb)->mount_opts.iocharset); |
739 | BEFS_SB(sb)->mount_opts.iocharset = NULL; | 739 | BEFS_SB(sb)->mount_opts.iocharset = NULL; |
740 | 740 | unload_nls(BEFS_SB(sb)->nls); | |
741 | if (BEFS_SB(sb)->nls) { | ||
742 | unload_nls(BEFS_SB(sb)->nls); | ||
743 | BEFS_SB(sb)->nls = NULL; | ||
744 | } | ||
745 | |||
746 | kfree(sb->s_fs_info); | 741 | kfree(sb->s_fs_info); |
747 | sb->s_fs_info = NULL; | 742 | sb->s_fs_info = NULL; |
748 | } | 743 | } |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index d79ce2e95c23..90c5b39f0313 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -185,8 +185,7 @@ out_mount_failed: | |||
185 | cifs_sb->mountdata = NULL; | 185 | cifs_sb->mountdata = NULL; |
186 | } | 186 | } |
187 | #endif | 187 | #endif |
188 | if (cifs_sb->local_nls) | 188 | unload_nls(cifs_sb->local_nls); |
189 | unload_nls(cifs_sb->local_nls); | ||
190 | kfree(cifs_sb); | 189 | kfree(cifs_sb); |
191 | } | 190 | } |
192 | return rc; | 191 | return rc; |
diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 8970d8c49bb0..04629d1302fc 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c | |||
@@ -470,19 +470,11 @@ static void fat_put_super(struct super_block *sb) | |||
470 | 470 | ||
471 | iput(sbi->fat_inode); | 471 | iput(sbi->fat_inode); |
472 | 472 | ||
473 | if (sbi->nls_disk) { | 473 | unload_nls(sbi->nls_disk); |
474 | unload_nls(sbi->nls_disk); | 474 | unload_nls(sbi->nls_io); |
475 | sbi->nls_disk = NULL; | 475 | |
476 | sbi->options.codepage = fat_default_codepage; | 476 | if (sbi->options.iocharset != fat_default_iocharset) |
477 | } | ||
478 | if (sbi->nls_io) { | ||
479 | unload_nls(sbi->nls_io); | ||
480 | sbi->nls_io = NULL; | ||
481 | } | ||
482 | if (sbi->options.iocharset != fat_default_iocharset) { | ||
483 | kfree(sbi->options.iocharset); | 477 | kfree(sbi->options.iocharset); |
484 | sbi->options.iocharset = fat_default_iocharset; | ||
485 | } | ||
486 | 478 | ||
487 | sb->s_fs_info = NULL; | 479 | sb->s_fs_info = NULL; |
488 | kfree(sbi); | 480 | kfree(sbi); |
diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index 7b6165f25fbe..8bbe03c3f6d5 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c | |||
@@ -344,10 +344,8 @@ void hfs_mdb_put(struct super_block *sb) | |||
344 | brelse(HFS_SB(sb)->mdb_bh); | 344 | brelse(HFS_SB(sb)->mdb_bh); |
345 | brelse(HFS_SB(sb)->alt_mdb_bh); | 345 | brelse(HFS_SB(sb)->alt_mdb_bh); |
346 | 346 | ||
347 | if (HFS_SB(sb)->nls_io) | 347 | unload_nls(HFS_SB(sb)->nls_io); |
348 | unload_nls(HFS_SB(sb)->nls_io); | 348 | unload_nls(HFS_SB(sb)->nls_disk); |
349 | if (HFS_SB(sb)->nls_disk) | ||
350 | unload_nls(HFS_SB(sb)->nls_disk); | ||
351 | 349 | ||
352 | free_pages((unsigned long)HFS_SB(sb)->bitmap, PAGE_SIZE < 8192 ? 1 : 0); | 350 | free_pages((unsigned long)HFS_SB(sb)->bitmap, PAGE_SIZE < 8192 ? 1 : 0); |
353 | kfree(HFS_SB(sb)); | 351 | kfree(HFS_SB(sb)); |
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index c0759fe0855b..43022f3d5148 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c | |||
@@ -229,8 +229,7 @@ static void hfsplus_put_super(struct super_block *sb) | |||
229 | iput(HFSPLUS_SB(sb).alloc_file); | 229 | iput(HFSPLUS_SB(sb).alloc_file); |
230 | iput(HFSPLUS_SB(sb).hidden_dir); | 230 | iput(HFSPLUS_SB(sb).hidden_dir); |
231 | brelse(HFSPLUS_SB(sb).s_vhbh); | 231 | brelse(HFSPLUS_SB(sb).s_vhbh); |
232 | if (HFSPLUS_SB(sb).nls) | 232 | unload_nls(HFSPLUS_SB(sb).nls); |
233 | unload_nls(HFSPLUS_SB(sb).nls); | ||
234 | kfree(sb->s_fs_info); | 233 | kfree(sb->s_fs_info); |
235 | sb->s_fs_info = NULL; | 234 | sb->s_fs_info = NULL; |
236 | 235 | ||
@@ -464,8 +463,7 @@ out: | |||
464 | 463 | ||
465 | cleanup: | 464 | cleanup: |
466 | hfsplus_put_super(sb); | 465 | hfsplus_put_super(sb); |
467 | if (nls) | 466 | unload_nls(nls); |
468 | unload_nls(nls); | ||
469 | return err; | 467 | return err; |
470 | } | 468 | } |
471 | 469 | ||
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c index 85f96bc651c7..6b4dcd4f2943 100644 --- a/fs/isofs/inode.c +++ b/fs/isofs/inode.c | |||
@@ -46,10 +46,7 @@ static void isofs_put_super(struct super_block *sb) | |||
46 | #ifdef CONFIG_JOLIET | 46 | #ifdef CONFIG_JOLIET |
47 | lock_kernel(); | 47 | lock_kernel(); |
48 | 48 | ||
49 | if (sbi->s_nls_iocharset) { | 49 | unload_nls(sbi->s_nls_iocharset); |
50 | unload_nls(sbi->s_nls_iocharset); | ||
51 | sbi->s_nls_iocharset = NULL; | ||
52 | } | ||
53 | 50 | ||
54 | unlock_kernel(); | 51 | unlock_kernel(); |
55 | #endif | 52 | #endif |
@@ -912,8 +909,7 @@ out_no_root: | |||
912 | printk(KERN_WARNING "%s: get root inode failed\n", __func__); | 909 | printk(KERN_WARNING "%s: get root inode failed\n", __func__); |
913 | out_no_inode: | 910 | out_no_inode: |
914 | #ifdef CONFIG_JOLIET | 911 | #ifdef CONFIG_JOLIET |
915 | if (sbi->s_nls_iocharset) | 912 | unload_nls(sbi->s_nls_iocharset); |
916 | unload_nls(sbi->s_nls_iocharset); | ||
917 | #endif | 913 | #endif |
918 | goto out_freesbi; | 914 | goto out_freesbi; |
919 | out_no_read: | 915 | out_no_read: |
diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 37e6dcda8fc8..2234c73fc577 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c | |||
@@ -178,13 +178,11 @@ static void jfs_put_super(struct super_block *sb) | |||
178 | rc = jfs_umount(sb); | 178 | rc = jfs_umount(sb); |
179 | if (rc) | 179 | if (rc) |
180 | jfs_err("jfs_umount failed with return code %d", rc); | 180 | jfs_err("jfs_umount failed with return code %d", rc); |
181 | if (sbi->nls_tab) | 181 | |
182 | unload_nls(sbi->nls_tab); | 182 | unload_nls(sbi->nls_tab); |
183 | sbi->nls_tab = NULL; | ||
184 | 183 | ||
185 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); | 184 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
186 | iput(sbi->direct_inode); | 185 | iput(sbi->direct_inode); |
187 | sbi->direct_inode = NULL; | ||
188 | 186 | ||
189 | kfree(sbi); | 187 | kfree(sbi); |
190 | 188 | ||
@@ -347,8 +345,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, | |||
347 | 345 | ||
348 | if (nls_map != (void *) -1) { | 346 | if (nls_map != (void *) -1) { |
349 | /* Discard old (if remount) */ | 347 | /* Discard old (if remount) */ |
350 | if (sbi->nls_tab) | 348 | unload_nls(sbi->nls_tab); |
351 | unload_nls(sbi->nls_tab); | ||
352 | sbi->nls_tab = nls_map; | 349 | sbi->nls_tab = nls_map; |
353 | } | 350 | } |
354 | return 1; | 351 | return 1; |
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c index b99ce205b1bd..cf98da1be23e 100644 --- a/fs/ncpfs/inode.c +++ b/fs/ncpfs/inode.c | |||
@@ -746,16 +746,8 @@ static void ncp_put_super(struct super_block *sb) | |||
746 | 746 | ||
747 | #ifdef CONFIG_NCPFS_NLS | 747 | #ifdef CONFIG_NCPFS_NLS |
748 | /* unload the NLS charsets */ | 748 | /* unload the NLS charsets */ |
749 | if (server->nls_vol) | 749 | unload_nls(server->nls_vol); |
750 | { | 750 | unload_nls(server->nls_io); |
751 | unload_nls(server->nls_vol); | ||
752 | server->nls_vol = NULL; | ||
753 | } | ||
754 | if (server->nls_io) | ||
755 | { | ||
756 | unload_nls(server->nls_io); | ||
757 | server->nls_io = NULL; | ||
758 | } | ||
759 | #endif /* CONFIG_NCPFS_NLS */ | 751 | #endif /* CONFIG_NCPFS_NLS */ |
760 | 752 | ||
761 | if (server->info_filp) | 753 | if (server->info_filp) |
diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c index 53a7ed7eb9c6..0d58caf4a6e1 100644 --- a/fs/ncpfs/ioctl.c +++ b/fs/ncpfs/ioctl.c | |||
@@ -223,10 +223,8 @@ ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) | |||
223 | oldset_io = server->nls_io; | 223 | oldset_io = server->nls_io; |
224 | server->nls_io = iocharset; | 224 | server->nls_io = iocharset; |
225 | 225 | ||
226 | if (oldset_cp) | 226 | unload_nls(oldset_cp); |
227 | unload_nls(oldset_cp); | 227 | unload_nls(oldset_io); |
228 | if (oldset_io) | ||
229 | unload_nls(oldset_io); | ||
230 | 228 | ||
231 | return 0; | 229 | return 0; |
232 | } | 230 | } |
diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c index 477d37d83b31..2224b4d07bf0 100644 --- a/fs/nls/nls_base.c +++ b/fs/nls/nls_base.c | |||
@@ -270,7 +270,8 @@ struct nls_table *load_nls(char *charset) | |||
270 | 270 | ||
271 | void unload_nls(struct nls_table *nls) | 271 | void unload_nls(struct nls_table *nls) |
272 | { | 272 | { |
273 | module_put(nls->owner); | 273 | if (nls) |
274 | module_put(nls->owner); | ||
274 | } | 275 | } |
275 | 276 | ||
276 | static const wchar_t charset2uni[256] = { | 277 | static const wchar_t charset2uni[256] = { |
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index abaaa1cbf8de..80b04770e8e9 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c | |||
@@ -201,8 +201,7 @@ use_utf8: | |||
201 | v, old_nls->charset); | 201 | v, old_nls->charset); |
202 | nls_map = old_nls; | 202 | nls_map = old_nls; |
203 | } else /* nls_map */ { | 203 | } else /* nls_map */ { |
204 | if (old_nls) | 204 | unload_nls(old_nls); |
205 | unload_nls(old_nls); | ||
206 | } | 205 | } |
207 | } else if (!strcmp(p, "utf8")) { | 206 | } else if (!strcmp(p, "utf8")) { |
208 | bool val = false; | 207 | bool val = false; |
@@ -2427,10 +2426,9 @@ static void ntfs_put_super(struct super_block *sb) | |||
2427 | ntfs_free(vol->upcase); | 2426 | ntfs_free(vol->upcase); |
2428 | vol->upcase = NULL; | 2427 | vol->upcase = NULL; |
2429 | } | 2428 | } |
2430 | if (vol->nls_map) { | 2429 | |
2431 | unload_nls(vol->nls_map); | 2430 | unload_nls(vol->nls_map); |
2432 | vol->nls_map = NULL; | 2431 | |
2433 | } | ||
2434 | sb->s_fs_info = NULL; | 2432 | sb->s_fs_info = NULL; |
2435 | kfree(vol); | 2433 | kfree(vol); |
2436 | 2434 | ||
diff --git a/fs/smbfs/inode.c b/fs/smbfs/inode.c index 1402d2d54f52..1c4c8f089970 100644 --- a/fs/smbfs/inode.c +++ b/fs/smbfs/inode.c | |||
@@ -459,14 +459,8 @@ smb_show_options(struct seq_file *s, struct vfsmount *m) | |||
459 | static void | 459 | static void |
460 | smb_unload_nls(struct smb_sb_info *server) | 460 | smb_unload_nls(struct smb_sb_info *server) |
461 | { | 461 | { |
462 | if (server->remote_nls) { | 462 | unload_nls(server->remote_nls); |
463 | unload_nls(server->remote_nls); | 463 | unload_nls(server->local_nls); |
464 | server->remote_nls = NULL; | ||
465 | } | ||
466 | if (server->local_nls) { | ||
467 | unload_nls(server->local_nls); | ||
468 | server->local_nls = NULL; | ||
469 | } | ||
470 | } | 464 | } |
471 | 465 | ||
472 | static void | 466 | static void |