Skip to content

Commit

Permalink
[PATCH] kfree cleanup: fs
Browse files Browse the repository at this point in the history
This is the fs/ part of the big kfree cleanup patch.

Remove pointless checks for NULL prior to calling kfree() in fs/.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Jesper Juhl authored and Linus Torvalds committed Nov 7, 2005
1 parent 6044ec8 commit f99d49a
Show file tree
Hide file tree
Showing 39 changed files with 137 additions and 245 deletions.
3 changes: 1 addition & 2 deletions fs/9p/trans_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ static void v9fs_sock_close(struct v9fs_transport *trans)
dprintk(DEBUG_TRANS, "socket closed\n");
}

if (ts)
kfree(ts);
kfree(ts);

trans->priv = NULL;
}
Expand Down
16 changes: 6 additions & 10 deletions fs/affs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ affs_put_super(struct super_block *sb)
mark_buffer_dirty(sbi->s_root_bh);
}

if (sbi->s_prefix)
kfree(sbi->s_prefix);
kfree(sbi->s_prefix);
affs_free_bitmap(sb);
affs_brelse(sbi->s_root_bh);
kfree(sbi);
Expand Down Expand Up @@ -198,10 +197,9 @@ parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s
*mount_opts |= SF_MUFS;
break;
case Opt_prefix:
if (*prefix) { /* Free any previous prefix */
kfree(*prefix);
*prefix = NULL;
}
/* Free any previous prefix */
kfree(*prefix);
*prefix = NULL;
*prefix = match_strdup(&args[0]);
if (!*prefix)
return 0;
Expand Down Expand Up @@ -462,11 +460,9 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
out_error:
if (root_inode)
iput(root_inode);
if (sbi->s_bitmap)
kfree(sbi->s_bitmap);
kfree(sbi->s_bitmap);
affs_brelse(root_bh);
if (sbi->s_prefix)
kfree(sbi->s_prefix);
kfree(sbi->s_prefix);
kfree(sbi);
sb->s_fs_info = NULL;
return -EINVAL;
Expand Down
3 changes: 1 addition & 2 deletions fs/afs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ static int afs_file_releasepage(struct page *page, gfp_t gfp_flags)
set_page_private(page, 0);
ClearPagePrivate(page);

if (pageio)
kfree(pageio);
kfree(pageio);
}

_leave(" = 0");
Expand Down
6 changes: 2 additions & 4 deletions fs/autofs/waitq.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,8 @@ int autofs_wait(struct autofs_sb_info *sbi, struct qstr *name)
if ( sbi->catatonic ) {
/* We might have slept, so check again for catatonic mode */
wq->status = -ENOENT;
if ( wq->name ) {
kfree(wq->name);
wq->name = NULL;
}
kfree(wq->name);
wq->name = NULL;
}

if ( wq->name ) {
Expand Down
6 changes: 2 additions & 4 deletions fs/autofs4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

static void ino_lnkfree(struct autofs_info *ino)
{
if (ino->u.symlink) {
kfree(ino->u.symlink);
ino->u.symlink = NULL;
}
kfree(ino->u.symlink);
ino->u.symlink = NULL;
}

struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
Expand Down
6 changes: 2 additions & 4 deletions fs/autofs4/waitq.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
if ( sbi->catatonic ) {
/* We might have slept, so check again for catatonic mode */
wq->status = -ENOENT;
if ( wq->name ) {
kfree(wq->name);
wq->name = NULL;
}
kfree(wq->name);
wq->name = NULL;
}

if ( wq->name ) {
Expand Down
12 changes: 4 additions & 8 deletions fs/befs/linuxvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,20 +725,16 @@ parse_options(char *options, befs_mount_options * opts)
static void
befs_put_super(struct super_block *sb)
{
if (BEFS_SB(sb)->mount_opts.iocharset) {
kfree(BEFS_SB(sb)->mount_opts.iocharset);
BEFS_SB(sb)->mount_opts.iocharset = NULL;
}
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;
}

if (sb->s_fs_info) {
kfree(sb->s_fs_info);
sb->s_fs_info = NULL;
}
kfree(sb->s_fs_info);
sb->s_fs_info = NULL;
return;
}

Expand Down
3 changes: 1 addition & 2 deletions fs/binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,7 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
if (interpreter)
fput(interpreter);
out_free_interp:
if (elf_interpreter)
kfree(elf_interpreter);
kfree(elf_interpreter);
out_free_file:
sys_close(elf_exec_fileno);
out_free_fh:
Expand Down
15 changes: 5 additions & 10 deletions fs/binfmt_elf_fdpic.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,11 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs
allow_write_access(interpreter);
fput(interpreter);
}
if (interpreter_name)
kfree(interpreter_name);
if (exec_params.phdrs)
kfree(exec_params.phdrs);
if (exec_params.loadmap)
kfree(exec_params.loadmap);
if (interp_params.phdrs)
kfree(interp_params.phdrs);
if (interp_params.loadmap)
kfree(interp_params.loadmap);
kfree(interpreter_name);
kfree(exec_params.phdrs);
kfree(exec_params.loadmap);
kfree(interp_params.phdrs);
kfree(interp_params.loadmap);
return retval;

/* unrecoverable error - kill the process */
Expand Down
3 changes: 1 addition & 2 deletions fs/cifs/asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
*(oid + 3)));
rc = compare_oid(oid, oidlen, NTLMSSP_OID,
NTLMSSP_OID_LEN);
if(oid)
kfree(oid);
kfree(oid);
if (rc)
use_ntlmssp = TRUE;
}
Expand Down
81 changes: 27 additions & 54 deletions fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,7 @@ connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
the helper that resolves tcp names, mount to it, try to
tcon to it unmount it if fail */

if(referrals)
kfree(referrals);
kfree(referrals);

return rc;
}
Expand Down Expand Up @@ -1535,10 +1534,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,

memset(&volume_info,0,sizeof(struct smb_vol));
if (cifs_parse_mount_options(mount_data, devname, &volume_info)) {
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return -EINVAL;
}
Expand All @@ -1551,10 +1548,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
cifserror("No username specified ");
/* In userspace mount helper we can get user name from alternate
locations such as env variables and files on disk */
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return -EINVAL;
}
Expand All @@ -1573,10 +1568,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,

if(rc <= 0) {
/* we failed translating address */
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return -EINVAL;
}
Expand All @@ -1587,19 +1580,15 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
} else if (volume_info.UNCip){
/* BB using ip addr as server name connect to the DFS root below */
cERROR(1,("Connecting to DFS root not implemented yet"));
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return -EINVAL;
} else /* which servers DFS root would we conect to */ {
cERROR(1,
("CIFS mount error: No UNC path (e.g. -o unc=//192.168.1.100/public) specified "));
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return -EINVAL;
}
Expand All @@ -1612,10 +1601,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
cifs_sb->local_nls = load_nls(volume_info.iocharset);
if(cifs_sb->local_nls == NULL) {
cERROR(1,("CIFS mount error: iocharset %s not found",volume_info.iocharset));
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return -ELIBACC;
}
Expand All @@ -1630,10 +1617,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
&sin_server6.sin6_addr,
volume_info.username, &srvTcp);
else {
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return -EINVAL;
}
Expand All @@ -1654,10 +1639,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
("Error connecting to IPv4 socket. Aborting operation"));
if(csocket != NULL)
sock_release(csocket);
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return rc;
}
Expand All @@ -1666,10 +1649,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
if (srvTcp == NULL) {
rc = -ENOMEM;
sock_release(csocket);
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return rc;
} else {
Expand All @@ -1692,10 +1673,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
if(rc < 0) {
rc = -ENOMEM;
sock_release(csocket);
if(volume_info.UNC)
kfree(volume_info.UNC);
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.UNC);
kfree(volume_info.password);
FreeXid(xid);
return rc;
}
Expand All @@ -1710,8 +1689,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
if (existingCifsSes) {
pSesInfo = existingCifsSes;
cFYI(1, ("Existing smb sess found "));
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.password);
/* volume_info.UNC freed at end of function */
} else if (!rc) {
cFYI(1, ("Existing smb sess not found "));
Expand Down Expand Up @@ -1741,8 +1719,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
if(!rc)
atomic_inc(&srvTcp->socketUseCount);
} else
if(volume_info.password)
kfree(volume_info.password);
kfree(volume_info.password);
}

/* search for existing tcon to this server share */
Expand Down Expand Up @@ -1821,8 +1798,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
"", cifs_sb->local_nls,
cifs_sb->mnt_cifs_flags &
CIFS_MOUNT_MAP_SPECIAL_CHR);
if(volume_info.UNC)
kfree(volume_info.UNC);
kfree(volume_info.UNC);
FreeXid(xid);
return -ENODEV;
} else {
Expand Down Expand Up @@ -1925,8 +1901,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
(in which case it is not needed anymore) but when new sesion is created
the password ptr is put in the new session structure (in which case the
password will be freed at unmount time) */
if(volume_info.UNC)
kfree(volume_info.UNC);
kfree(volume_info.UNC);
FreeXid(xid);
return rc;
}
Expand Down Expand Up @@ -3283,8 +3258,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
if ((bcc_ptr + (2 * length)) -
pByteArea(smb_buffer_response) <=
BCC(smb_buffer_response)) {
if(tcon->nativeFileSystem)
kfree(tcon->nativeFileSystem);
kfree(tcon->nativeFileSystem);
tcon->nativeFileSystem =
kzalloc(length + 2, GFP_KERNEL);
cifs_strfromUCS_le(tcon->nativeFileSystem,
Expand All @@ -3301,8 +3275,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
if ((bcc_ptr + length) -
pByteArea(smb_buffer_response) <=
BCC(smb_buffer_response)) {
if(tcon->nativeFileSystem)
kfree(tcon->nativeFileSystem);
kfree(tcon->nativeFileSystem);
tcon->nativeFileSystem =
kzalloc(length + 1, GFP_KERNEL);
strncpy(tcon->nativeFileSystem, bcc_ptr,
Expand Down
Loading

0 comments on commit f99d49a

Please sign in to comment.