All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Petr Tesa__ík" <ptesarik@suse.cz>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: [PATCH] remove_arg_zero() rewrite
Date: Wed, 07 Mar 2007 23:09:57 +0100	[thread overview]
Message-ID: <1173305397.4868.4.camel@lappy> (raw)
In-Reply-To: <20070221154159.d316d526.akpm@linux-foundation.org>

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

> I mean.... what the hell?
> 
> As you appear to have managed to work out what the sorry thing is trying to
> do, would you have time to simply rip it out and completely rewrite it,
> including a nice comment telling the world what this function's function is?
> 
> Because what we have there is beyond repairing.

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);



  reply	other threads:[~2007-03-07 22:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-20 13:29 [PATCH] free pages in remove_arg_zero() Petr Tesařík
2007-02-21 23:41 ` Andrew Morton
2007-03-07 22:09   ` Peter Zijlstra [this message]
2007-03-07 22:41     ` [PATCH] remove_arg_zero() rewrite Andrew Morton
2007-03-07 22:55       ` Peter Zijlstra
2007-03-07 23:05         ` Randy Dunlap

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=1173305397.4868.4.camel@lappy \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ptesarik@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.