fs: Memory allocation cleanups
Subsystems (6)
PATCH 1/1 fs: Memory allocation cleanups
From: Panagiotis Issaris <[email protected]>
- Remove useless casts from k(m|z)alloc and vmallocs
- One conversion of kmalloc+memset to kzalloc
Signed-off-by Panagiotis Issaris <[email protected]>
--- fs/autofs4/inode.c | 4 +--- fs/befs/btree.c | 2 +- fs/befs/debug.c | 6 +++--- fs/binfmt_misc.c | 2 +- fs/binfmt_som.c | 2 +- fs/cifs/cifssmb.c | 3 +-- fs/cifs/misc.c | 8 ++------ fs/file.c | 8 ++++---- fs/jffs/inode-v23.c | 4 ++-- fs/jffs/intrep.c | 14 +++++++------- fs/jfs/jfs_dtree.c | 14 ++++---------- fs/jfs/jfs_imap.c | 2 +- fs/lockd/svcshare.c | 3 +-- fs/nfs/nfs4proc.c | 2 +- fs/reiserfs/xattr_acl.c | 3 +-- 15 files changed, 31 insertions(+), 46 deletions(-)
fs/autofs4/inode.c +1 -3
@@ -305,13 +305,11 @@ int autofs4_fill_super(struct super_blocstruct autofs_sb_info *sbi;struct autofs_info *ino; - sbi = (struct autofs_sb_info *)kmalloc (sizeof (*sbi),GFP_KERNEL ); + sbi =kzalloc (sizeof (*sbi),GFP_KERNEL );if ( !sbi ) goto fail_unlock;DPRINTK ("starting up, sbi = %p" ,sbi); -memset (sbi,0 ,sizeof (*sbi)); - s->s_fs_info = sbi; sbi->magic =AUTOFS_SBI_MAGIC ; sbi->root =NULL ;
fs/befs/btree.c +1 -1
@@ -261,7 +261,7 @@ befs_btree_find(struct super_block *sb, goto error; } - this_node = (befs_btree_node *)kmalloc (sizeof (befs_btree_node), + this_node =kmalloc (sizeof (befs_btree_node),GFP_NOFS );if (!this_node) { befs_error(sb, "befs_btree_find() failed to allocate %u "
fs/befs/debug.c +3 -3
@@ -29,7 +29,7 @@ void befs_error(const struct super_block *sb, const char *fmt, ...) { va_list args; -char *err_buf = (char *)kmalloc (ERRBUFSIZE ,GFP_KERNEL ); +char *err_buf =kmalloc (ERRBUFSIZE ,GFP_KERNEL );if (err_buf ==NULL ) {printk (KERN_ERR "could not allocate %d bytes\n" ,ERRBUFSIZE );return ;
@@ -47,7 +47,7 @@ void befs_warning(const struct super_block *sb, const char *fmt, ...) { va_list args; -char *err_buf = (char *)kmalloc (ERRBUFSIZE ,GFP_KERNEL ); +char *err_buf =kmalloc (ERRBUFSIZE ,GFP_KERNEL );if (err_buf ==NULL ) {printk (KERN_ERR "could not allocate %d bytes\n" ,ERRBUFSIZE );return ;
@@ -71,7 +71,7 @@ #ifdef CONFIG_BEFS_DEBUGchar *err_buf =NULL ;if (BEFS_SB (sb)->mount_opts.debug) { - err_buf = (char *)kmalloc (ERRBUFSIZE ,GFP_KERNEL ); + err_buf =kmalloc (ERRBUFSIZE ,GFP_KERNEL );if (err_buf ==NULL ) {printk (KERN_ERR "could not allocate %d bytes\n" ,ERRBUFSIZE );
fs/binfmt_misc.c +1 -1
@@ -313,7 +313,7 @@ static Node *create_entry(const char __u err = -ENOMEM ; memsize =sizeof (Node) + count +8 ; - e = (Node *)kmalloc (memsize,GFP_USER ); + e =kmalloc (memsize,GFP_USER );if (!e) goto out;
fs/binfmt_som.c +1 -1
@@ -208,7 +208,7 @@ load_som_binary(struct linux_binprm * bp size = som_ex->aux_header_size;if (size >SOM_PAGESIZE ) goto out; - hpuxhdr = (struct som_exec_auxhdr *)kmalloc (size,GFP_KERNEL ); + hpuxhdr =kmalloc (size,GFP_KERNEL );if (!hpuxhdr) goto out;
fs/cifs/cifssmb.c +1 -2
@@ -4788,8 +4788,7 @@ int CIFSSMBNotify(const int xid, struct }else {/* Add file to outstanding requests */ /* BB change to kmem cache alloc */ - dnotify_req = (struct dir_notify_req *)kmalloc ( -sizeof (struct dir_notify_req ), + dnotify_req =kmalloc (sizeof (struct dir_notify_req ),GFP_KERNEL );if (dnotify_req) { dnotify_req->Pid = pSMB->hdr.Pid;
fs/cifs/misc.c +2 -6
@@ -71,9 +71,7 @@ sesInfoAlloc(void) {struct cifsSesInfo *ret_buf; - ret_buf = - (struct cifsSesInfo *)kzalloc (sizeof (struct cifsSesInfo ), -GFP_KERNEL ); + ret_buf =kzalloc (sizeof (struct cifsSesInfo ),GFP_KERNEL );if (ret_buf) {write_lock (&GlobalSMBSeslock);atomic_inc (&sesInfoAllocCount);
@@ -109,9 +107,7 @@ struct cifsTconInfo *tconInfoAlloc (void) {struct cifsTconInfo *ret_buf; - ret_buf = - (struct cifsTconInfo *)kzalloc (sizeof (struct cifsTconInfo ), -GFP_KERNEL ); + ret_buf =kzalloc (sizeof (struct cifsTconInfo ),GFP_KERNEL );if (ret_buf) {write_lock (&GlobalSMBSeslock);atomic_inc (&tconInfoAllocCount);
fs/file.c +4 -4
@@ -44,9 +44,9 @@ struct file ** alloc_fd_array(int num)int size = num *sizeof (struct file *);if (size <=PAGE_SIZE ) - new_fds = (struct file **)kmalloc (size,GFP_KERNEL ); + new_fds =kmalloc (size,GFP_KERNEL );else - new_fds = (struct file **)vmalloc (size); + new_fds =vmalloc (size);return new_fds; }
@@ -213,9 +213,9 @@ fd_set * alloc_fdset(int num)int size = num /8 ;if (size <=PAGE_SIZE ) - new_fdset = (fd_set *)kmalloc (size,GFP_KERNEL ); + new_fdset =kmalloc (size,GFP_KERNEL );else - new_fdset = (fd_set *)vmalloc (size); + new_fdset =vmalloc (size);return new_fdset; }
fs/jffs/inode-v23.c +2 -2
@@ -819,7 +819,7 @@ jffs_mkdir(struct inode *dir, struct den D1({ int len = dentry->d_name.len; - char *_name = (char *) kmalloc(len + 1, GFP_KERNEL); + char *_name = kmalloc(len + 1, GFP_KERNEL); memcpy(_name, dentry->d_name.name, len); _name[len] = '\0'; printk("***jffs_mkdir(): dir = 0x%p, name = \"%s\", "
@@ -965,7 +965,7 @@ jffs_remove(struct inode *dir, struct de D1({ int len = dentry->d_name.len; const char *name = dentry->d_name.name; - char *_name = (char *) kmalloc(len + 1, GFP_KERNEL); + char *_name = kmalloc(len + 1, GFP_KERNEL); memcpy(_name, name, len); _name[len] = '\0'; printk("***jffs_remove(): file = \"%s\", ino = %ld\n", _name, dentry->d_inode->i_ino);
fs/jffs/intrep.c +7 -7
@@ -435,7 +435,7 @@ jffs_checksum_flash(struct mtd_info *mtdint i, length;/* Allocate read buffer */ - read_buf = (__u8 *)kmalloc (sizeof (__u8) *4096 ,GFP_KERNEL ); + read_buf =kmalloc (sizeof (__u8) *4096 ,GFP_KERNEL );if (!read_buf) {printk (KERN_NOTICE "kmalloc failed in jffs_checksum_flash()\n" );return -ENOMEM ;
@@ -747,11 +747,11 @@ #define READ_AHEAD_BYTES 4096 /*/* Allocate read buffers */ - read_buf1 = (__u8 *)kmalloc (sizeof (__u8) *READ_AHEAD_BYTES ,GFP_KERNEL ); + read_buf1 =kmalloc (sizeof (__u8) *READ_AHEAD_BYTES ,GFP_KERNEL );if (!read_buf1)return -ENOMEM ; - read_buf2 = (__u8 *)kmalloc (sizeof (__u8) *READ_AHEAD_BYTES ,GFP_KERNEL ); + read_buf2 =kmalloc (sizeof (__u8) *READ_AHEAD_BYTES ,GFP_KERNEL );if (!read_buf2) {kfree (read_buf1);return -ENOMEM ;
@@ -879,7 +879,7 @@ #define NUMFREEALLOWED 2 /* 2 }/* Allocate read buffer */ - read_buf = (__u8 *)kmalloc (sizeof (__u8) *4096 ,GFP_KERNEL ); + read_buf =kmalloc (sizeof (__u8) *4096 ,GFP_KERNEL );if (!read_buf) {flash_safe_release (fmc->mtd);return -ENOMEM ;
@@ -1466,7 +1466,7 @@ jffs_insert_node(struct jffs_control *c,kfree (f->name);DJM (no_name--); } -if (!(f->name = (char *)kmalloc (raw_inode->nsize +1 , +if (!(f->name =kmalloc (raw_inode->nsize +1 ,GFP_KERNEL ))) {return -ENOMEM ; }
@@ -1740,7 +1740,7 @@ jffs_find_child(struct jffs_file *dir, cprintk ("jffs_find_child(): Found \"%s\".\n" , f->name); }else { -char *copy = (char *)kmalloc (len +1 ,GFP_KERNEL ); +char *copy =kmalloc (len +1 ,GFP_KERNEL );if (copy) {memcpy (copy, name, len); copy[len] ='\0' ;
@@ -2630,7 +2630,7 @@ jffs_print_tree(struct jffs_file *first_return ; } -if (!(space = (char *)kmalloc (indent +1 ,GFP_KERNEL ))) { +if (!(space =kmalloc (indent +1 ,GFP_KERNEL ))) {printk ("jffs_print_tree(): Out of memory!\n" );return ; }
fs/jfs/jfs_dtree.c +4 -10
@@ -592,9 +592,7 @@ int dtSearch(struct inode *ip, struct costruct component_name ciKey;struct super_block *sb = ip->i_sb; - ciKey.name = - (wchar_t *)kmalloc ((JFS_NAME_MAX +1 ) *sizeof (wchar_t), -GFP_NOFS ); + ciKey.name =kmalloc ((JFS_NAME_MAX +1 ) *sizeof (wchar_t),GFP_NOFS );if (ciKey.name ==0 ) { rc = -ENOMEM ; goto dtSearch_Exit2;
@@ -957,9 +955,7 @@ static int dtSplitUp(tid_t tid, smp = split->mp; sp =DT_PAGE (ip, smp); - key.name = - (wchar_t *)kmalloc ((JFS_NAME_MAX +2 ) *sizeof (wchar_t), -GFP_NOFS ); + key.name =kmalloc ((JFS_NAME_MAX +2 ) *sizeof (wchar_t),GFP_NOFS );if (key.name ==0 ) {DT_PUTPAGE (smp); rc = -ENOMEM ;
@@ -3777,13 +3773,11 @@ static int ciGetLeafPrefixKey(dtpage_t *struct component_name lkey;struct component_name rkey; - lkey.name = (wchar_t *)kmalloc ((JFS_NAME_MAX +1 ) *sizeof (wchar_t), -GFP_KERNEL ); + lkey.name =kmalloc ((JFS_NAME_MAX +1 ) *sizeof (wchar_t),GFP_KERNEL );if (lkey.name ==NULL )return -ENOSPC ; - rkey.name = (wchar_t *)kmalloc ((JFS_NAME_MAX +1 ) *sizeof (wchar_t), -GFP_KERNEL ); + rkey.name =kmalloc ((JFS_NAME_MAX +1 ) *sizeof (wchar_t),GFP_KERNEL );if (rkey.name ==NULL ) {kfree (lkey.name);return -ENOSPC ;
fs/jfs/jfs_imap.c +1 -1
@@ -120,7 +120,7 @@ int diMount(struct inode *ipimap)* allocate/initialize the in-memory inode map control structure */ /* allocate the in-memory inode map control structure. */ - imap = (struct inomap *)kmalloc (sizeof (struct inomap ),GFP_KERNEL ); + imap =kmalloc (sizeof (struct inomap ),GFP_KERNEL );if (imap ==NULL ) {jfs_err ("diMount: kmalloc returned NULL!" );return -ENOMEM ;
fs/lockd/svcshare.c +1 -2
@@ -39,8 +39,7 @@ nlmsvc_share_file(struct nlm_host *host,return nlm_lck_denied; } - share = (struct nlm_share *)kmalloc (sizeof (*share) + oh->len, -GFP_KERNEL ); + share =kmalloc (sizeof (*share) + oh->len,GFP_KERNEL );if (share ==NULL )return nlm_lck_denied_nolocks;
fs/nfs/nfs4proc.c +1 -1
@@ -1960,7 +1960,7 @@ static int nfs4_proc_unlink_setup(structstruct nfs_server *server =NFS_SERVER (dir->d_inode);struct unlink_desc *up; - up = (struct unlink_desc *)kmalloc (sizeof (*up),GFP_KERNEL ); + up =kmalloc (sizeof (*up),GFP_KERNEL );if (!up)return -ENOMEM ;
fs/reiserfs/xattr_acl.c +1 -2
@@ -135,8 +135,7 @@ static void *posix_acl_to_disk(const strint n; *size =reiserfs_acl_size (acl->a_count); - ext_acl = (reiserfs_acl_header *)kmalloc (sizeof (reiserfs_acl_header) + - acl->a_count * + ext_acl =kmalloc (sizeof (reiserfs_acl_header) + acl->a_count *sizeof (reiserfs_acl_entry),GFP_NOFS );if (!ext_acl)
Signature · 1 line
1.4.2.rc1.ge7a0-dirty
fs/cifs/cifssmb.c int CIFSSMBNotify(const int xid, struct · line 4792
Quoted 4 lines · On Fri, Jul 21, 2006 at 01:50:55PM +0200, [email protected] wrote:
fs/cifs/cifssmb.c +1
-2- dnotify_req = (struct dir_notify_req *)kmalloc ( -sizeof (struct dir_notify_req ), + dnotify_req =kmalloc (sizeof (struct dir_notify_req ),GFP_KERNEL );
^^^^^
Should be aligned with the kmalloc?
fs/reiserfs/xattr_acl.c static void *posix_acl_to_disk(const str · line 140
Quoted 5 lines
fs/reiserfs/xattr_acl.c +1
-2- ext_acl = (reiserfs_acl_header *)kmalloc (sizeof (reiserfs_acl_header) + - acl->a_count * + ext_acl =kmalloc (sizeof (reiserfs_acl_header) + acl->a_count *sizeof (reiserfs_acl_entry),GFP_NOFS );
^^^^^
This should be aligned too, I think.
Regards,
Frederik
Quoted 6 lines · On Fri, 2006-07-21 at 13:50 +0200, [email protected] wrote:
From: Panagiotis Issaris <[email protected]>
- Remove useless casts from k(m|z)alloc and vmallocs
- One conversion of kmalloc+memset to kzallocSigned-off-by Panagiotis Issaris <[email protected]>
Acked-by Dave Kleikamp <[email protected]>
The jfs part looks good.
Shaggy
Signature · 2 lines
David Kleikamp IBM Linux Technology Center