[PATCH] remove_arg_zero() rewrite

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>
Cc: Petr <ptesarik@...>, Linux Kernel Mailing List <linux-kernel@...>
Date: Wednesday, March 7, 2007 - 6:09 pm

On Wed, 2007-02-21 at 15:41 -0800, Andrew Morton wrote:


Something like so?
Boots uml seemingly without errors.

---
Rewrite remove_arg_zero() to be more parseable by untwisted minds.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 fs/exec.c |   40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

Index: linux-2.6/fs/exec.c
===================================================================
--- linux-2.6.orig/fs/exec.c	2007-03-07 21:54:17.000000000 +0100
+++ linux-2.6/fs/exec.c	2007-03-07 23:08:27.000000000 +0100
@@ -987,28 +987,34 @@ void compute_creds(struct linux_binprm *
 
 EXPORT_SYMBOL(compute_creds);
 
+/*
+ * Arguments are '\0' separated strings found at the location bprm->p
+ * points to; chop off the first by relocating brpm->p to right after
+ * the first '\0' encountered.
+ */
 void remove_arg_zero(struct linux_binprm *bprm)
 {
-	if (bprm->argc) {
-		unsigned long offset;
-		char * kaddr;
-		struct page *page;
+	unsigned long offset;
+	char *kaddr;
+	struct page *page;
 
-		offset = bprm->p % PAGE_SIZE;
-		goto inside;
+	if (!bprm->argc)
+		return;
+
+	do {
+		offset = bprm->p & ~PAGE_MASK;
+		page = bprm->page[bprm->p >> PAGE_SHIFT];
+		kaddr = kmap_atomic(page, KM_USER0);
+
+		for (; offset < PAGE_SIZE && kaddr[offset];
+				offset++, bprm->p++)
+			;
 
-		while (bprm->p++, *(kaddr+offset++)) {
-			if (offset != PAGE_SIZE)
-				continue;
-			offset = 0;
-			kunmap_atomic(kaddr, KM_USER0);
-inside:
-			page = bprm->page[bprm->p/PAGE_SIZE];
-			kaddr = kmap_atomic(page, KM_USER0);
-		}
 		kunmap_atomic(kaddr, KM_USER0);
-		bprm->argc--;
-	}
+	} while (offset == PAGE_SIZE);
+
+	bprm->p++;
+	bprm->argc--;
 }
 
 EXPORT_SYMBOL(remove_arg_zero);


-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] free pages in remove_arg_zero(), Petr , (Tue Feb 20, 9:29 am)
Re: [PATCH] free pages in remove_arg_zero(), Andrew Morton, (Wed Feb 21, 7:41 pm)
[PATCH] remove_arg_zero() rewrite, Peter Zijlstra, (Wed Mar 7, 6:09 pm)
Re: [PATCH] remove_arg_zero() rewrite, Andrew Morton, (Wed Mar 7, 6:41 pm)
Re: [PATCH] remove_arg_zero() rewrite, Peter Zijlstra, (Wed Mar 7, 6:55 pm)
Re: [PATCH] remove_arg_zero() rewrite, Randy Dunlap, (Wed Mar 7, 7:05 pm)