commit 863238b6ad201d59eaafcb27fcc5d906f6a4500d
Author: Erez_Zadok <[EMAIL PROTECTED]>
Date:   Thu May 24 00:20:04 2007 -0400

    cleanup: use krealloc instead of open-coding it with kmalloc/kfree/memcpy
    
    Conflicts:
    
        fs/unionfs/lookup.c

diff --git a/fs/unionfs/lookup.c b/fs/unionfs/lookup.c
index bc59b4a..b64584e 100644
--- a/fs/unionfs/lookup.c
+++ b/fs/unionfs/lookup.c
@@ -409,9 +409,9 @@ void free_dentry_private_data(struct unionfs_dentry_info 
*udi)
 /* allocate new dentry private data, free old one if necessary */
 int new_dentry_private_data(struct dentry *dentry)
 {
-       int newsize;
-       int oldsize = 0;
+       int size;
        struct unionfs_dentry_info *info = UNIONFS_D(dentry);
+       void *p;
        int unlock_on_err = 0;
 
        spin_lock(&dentry->d_lock);
@@ -419,7 +419,6 @@ int new_dentry_private_data(struct dentry *dentry)
                dentry->d_fsdata = kmem_cache_alloc(unionfs_dentry_cachep,
                                                    GFP_ATOMIC);
                info = UNIONFS_D(dentry);
-
                if (!info)
                        goto out;
 
@@ -428,8 +427,7 @@ int new_dentry_private_data(struct dentry *dentry)
                unlock_on_err = 1;
 
                info->lower_paths = NULL;
-       } else
-               oldsize = sizeof(struct path) * info->bcount;
+       }
 
        info->bstart = -1;
        info->bend = -1;
@@ -437,29 +435,15 @@ int new_dentry_private_data(struct dentry *dentry)
        info->odf_info = NULL;
        atomic_set(&info->generation,
                   atomic_read(&UNIONFS_SB(dentry->d_sb)->generation));
-       newsize = sizeof(struct path) * sbmax(dentry->d_sb);
 
-       /*
-        * Don't reallocate when we already have enough space.
-        * It would be ideal if we could actually use the slab macros to
-        * determine what our object sizes is, but those are not exported.
-        */
-       if (oldsize) {
-               int minsize = malloc_sizes[0].cs_size;
+       size = sizeof(struct path) * sbmax(dentry->d_sb);
 
-               if (!newsize || ((oldsize < newsize) && (newsize > minsize))) {
-                       kfree(info->lower_paths);
-                       info->lower_paths = NULL;
-               }
-       }
-
-       if (!info->lower_paths && newsize) {
-               info->lower_paths = kmalloc(newsize, GFP_ATOMIC);
-               if (!info->lower_paths)
-                       goto out_free;
-       }
+       p = krealloc(info->lower_paths, size, GFP_ATOMIC);
+       if (!p)
+               goto out_free;
 
-       memset(info->lower_paths, 0, (oldsize > newsize ? oldsize : newsize));
+       info->lower_paths = p;
+       memset(info->lower_paths, 0, size);
 
        spin_unlock(&dentry->d_lock);
        return 0;
diff --git a/fs/unionfs/super.c b/fs/unionfs/super.c
index 28bf8fe..c70af70 100644
--- a/fs/unionfs/super.c
+++ b/fs/unionfs/super.c
@@ -427,6 +427,7 @@ static int unionfs_remount_fs(struct super_block *sb, int 
*flags,
        struct odf_sb_info *odf = UNIONFS_SB(sb)->odf;
        int odfforce = 0 ;      /* whether the odfforce option was provided */
        int old_ibstart, old_ibend;
+       int size;               /* memory allocation size, temp var */
 
        unionfs_write_lock(sb);
 
@@ -652,47 +653,20 @@ out_no_change:
                goto out_release;
        }
 
-       /*
-        * Allocate space for actual pointers, if needed.  By the time we
-        * finish this block of code, new_branches and new_lower_paths will
-        * have the correct size.  None of this code below would be needed
-        * if the kernel had a realloc() function, at least one capable of
-        * shrinking/truncating an allocation's size (hint, hint).
-        */
-       if (new_branches < max_branches) {
-
-               /* allocate space for new pointers to hidden dentry */
-               new_data = kcalloc(new_branches,
-                                  sizeof(struct unionfs_data), GFP_KERNEL);
-               if (!new_data) {
-                       err = -ENOMEM;
-                       goto out_release;
-               }
-               /* allocate space for new pointers to lower paths */
-               new_lower_paths = kcalloc(new_branches,
-                                         sizeof(struct path), GFP_KERNEL);
-               if (!new_lower_paths) {
-                       err = -ENOMEM;
-                       goto out_release;
-               }
-               /* copy current info into new placeholders */
-               memcpy(new_data, tmp_data,
-                      new_branches * sizeof(struct unionfs_data));
-               memcpy(new_lower_paths, tmp_lower_paths,
-                      new_branches * sizeof(struct path));
-               /*
-                * Since we already hold various refcnts on the objects, we
-                * don't need to redo it here.  Just free the older memory
-                * and re-point the pointers.
-                */
-               kfree(tmp_data);
-               kfree(tmp_lower_paths);
-               /* no need to nullify pointers here (they get reused below) */
-       } else {
-               /* number of branches didn't change, no need to re-alloc */
-               new_data = tmp_data;
-               new_lower_paths = tmp_lower_paths;
+       /* (re)allocate space for new pointers to hidden dentry */
+       size = new_branches * sizeof(struct unionfs_data);
+       new_data = krealloc(tmp_data, size, GFP_KERNEL);
+       if (!new_data) {
+               err = -ENOMEM;
+               goto out_release;
        }
+       /* allocate space for new pointers to lower paths */
+       size = new_branches * sizeof(struct path);
+       new_lower_paths = krealloc(tmp_lower_paths, size, GFP_KERNEL);
+       if (!new_lower_paths) {
+               err = -ENOMEM;
+               goto out_release;
+       }
        /* allocate space for new pointers to lower inodes */
        new_lower_inodes = kcalloc(new_branches,
                                   sizeof(struct inode *), GFP_KERNEL);
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs

Reply via email to