mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@mindspring.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH][RFC] Extend "memparse" to allow a NULL return pointer value.
Date: Sat, 15 Sep 2007 12:27:07 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0709151217530.16440@localhost.localdomain> (raw)


Extend the memparse() routine to allow a caller to use NULL as the
second parameter value if he has no interest in that returned value.

---

  there appear to be quite a number of calls to "memparse" which have
no use for the value returned in the second parameter (the current
pointer after the successful parse), but which are still forced to
supply a valid char** address since they have no choice but to accept
that value coming back.  in many cases, that value is accepted just
before the end of the calling function, making it clear that the value
is ignored entirely, anyway.

  this patch simply allows NULL as a second parameter to show that the
caller has no interest in that returned value, and it makes that
visually more obvious as well.  theoretically, this extension is
entirely backwards compatible.

  compile-tested on i386.  not boot-time tested yet, but i'm just
asking for feedback.


diff --git a/lib/cmdline.c b/lib/cmdline.c
index f596c08..53a668f 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -128,9 +128,11 @@ char *get_options(const char *str, int nints, int *ints)

 unsigned long long memparse (char *ptr, char **retptr)
 {
-	unsigned long long ret = simple_strtoull (ptr, retptr, 0);
+	char *localptr;

-	switch (**retptr) {
+	unsigned long long ret = simple_strtoull (ptr, &localptr, 0);
+
+	switch (*localptr) {
 	case 'G':
 	case 'g':
 		ret <<= 10;
@@ -140,10 +142,15 @@ unsigned long long memparse (char *ptr, char **retptr)
 	case 'K':
 	case 'k':
 		ret <<= 10;
-		(*retptr)++;
+		localptr++;
 	default:
 		break;
 	}
+
+	if (retptr) {
+		*retptr = localptr;
+	}
+
 	return ret;
 }


-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

             reply	other threads:[~2007-09-15 16:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-15 16:27 Robert P. J. Day [this message]
2007-09-23 20:52 ` Oleg Verych
2007-10-02 18:47   ` Robert P. J. Day

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=Pine.LNX.4.64.0709151217530.16440@localhost.localdomain \
    --to=rpjday@mindspring.com \
    --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

all inboxes | Powered by JetHome®