[PATCH 14/21] Unionfs: Call realloc unconditionally

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



krealloc already checks if the new size is greater than the old size.
Therefore, we can call realloc unconditionally - making the code simpler and
cleaner.

Signed-off-by: Josef 'Jeff' Sipek <jsipek@xxxxxxxxxxxxx>
---
 fs/unionfs/lookup.c |   26 ++++++++------------------
 1 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/fs/unionfs/lookup.c b/fs/unionfs/lookup.c
index cf78c46..758c813 100644
--- a/fs/unionfs/lookup.c
+++ b/fs/unionfs/lookup.c
@@ -451,17 +451,17 @@ 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 new_size;
 	int size;
 	struct unionfs_dentry_info *info = UNIONFS_D(dentry);
+	void *p;
 	int unlock_on_err = 0;
 
 	spin_lock(&dentry->d_lock);
 	if (!info) {
 		dentry->d_fsdata = kmem_cache_alloc(unionfs_dentry_cachep,
 						    GFP_ATOMIC);
+		
 		info = UNIONFS_D(dentry);
-
 		if (!info)
 			goto out;
 
@@ -470,9 +470,7 @@ int new_dentry_private_data(struct dentry *dentry)
 		unlock_on_err = 1;
 
 		info->lower_paths = NULL;
-		size = 0;
-	} else
-		size = sizeof(struct path) * info->bcount;
+	}
 
 	info->bstart = -1;
 	info->bend = -1;
@@ -481,21 +479,13 @@ int new_dentry_private_data(struct dentry *dentry)
 	atomic_set(&info->generation,
 		   atomic_read(&UNIONFS_SB(dentry->d_sb)->generation));
 
-	new_size = sizeof(struct path) * sbmax(dentry->d_sb);
-
-	/*
-	 * Don't reallocate when we already have enough space.
-	 */
-	if (new_size > size) {
-		void *p;
+	size = sizeof(struct path) * sbmax(dentry->d_sb);
 
-		p = krealloc(info->lower_paths, new_size, GFP_ATOMIC);
-		if (!p)
-			goto out_free;
+	p = krealloc(info->lower_paths, size, GFP_ATOMIC);
+	if (!p)
+		goto out_free;
 
-		info->lower_paths = p;
-		size = new_size;
-	}
+	info->lower_paths = p;
 	memset(info->lower_paths, 0, size);
 
 	spin_unlock(&dentry->d_lock);
-- 
1.5.2.rc1.165.gaf9b

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux