linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Josef 'Jeff' Sipek" <jsipek@cs.sunysb.edu>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: akpm@linux-foundation.org, "Josef 'Jeff' Sipek" <jsipek@cs.sunysb.edu>
Subject: [PATCH 14/21] Unionfs: Call realloc unconditionally
Date: Wed, 23 May 2007 20:36:04 -0400	[thread overview]
Message-ID: <11799669733164-git-send-email-jsipek@cs.sunysb.edu> (raw)
In-Reply-To: <11799669712090-git-send-email-jsipek@cs.sunysb.edu>

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@cs.sunysb.edu>
---
 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


  parent reply	other threads:[~2007-05-24  0:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-24  0:35 [GIT PULL -mm] Unionfs cleanups and fixes Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 01/21] Unionfs: Tiny documentation fixups Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 02/21] Unionfs: Coding style fixes Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 03/21] Unionfs: Every printk should prefix with "unionfs: " consistently Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 04/21] Unionfs: Add missing copyright notices Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 05/21] Unionfs: Cleanup of strings and comments Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 06/21] Unionfs: Added numerous comments Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 07/21] Unionfs: Consistent pointer declaration spacing Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 08/21] Unionfs: Rename Unionfs's double_lock_dentry to avoid confusion Josef 'Jeff' Sipek
2007-05-24  0:35 ` [PATCH 09/21] Unionfs: Rename our "do_rename" to __unionfs_rename Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 10/21] Unionfs: Move unionfs_query_file to commonfops.c Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 11/21] Unionfs: Combine unionfs_write with __unionfs_write Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 12/21] Unionfs: Prefix external functions with 'extern' properly Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 13/21] Unionfs: Don't leak resources when copyup fails partially Josef 'Jeff' Sipek
2007-05-24  0:36 ` Josef 'Jeff' Sipek [this message]
2007-05-24  0:36 ` [PATCH 15/21] Unionfs: Use krealloc instead of open-coding the functionality Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 16/21] Unionfs: Disallow setting leftmost branch to readonly Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 17/21] Unionfs: Documentation update regarding overlapping branches and new lookup code Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 18/21] Unionfs: Remove defunct unionfs_put_inode super op Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 19/21] Unionfs: Actually catch bad use of unionfs_mnt{get,put} Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 20/21] Unionfs: Removed a trailing whitespace Josef 'Jeff' Sipek
2007-05-24  0:36 ` [PATCH 21/21] Unionfs: Correctly decrement refcounts of mnt's upon branch management Josef 'Jeff' Sipek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11799669733164-git-send-email-jsipek@cs.sunysb.edu \
    --to=jsipek@cs.sunysb.edu \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).