public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Randy Dunlap <randy.dunlap@oracle.com>
To: Derek Fults <dfults@sgi.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Allow a hyphenated range in get_options, with cleanup
Date: Tue, 31 Oct 2006 13:11:52 -0800	[thread overview]
Message-ID: <20061031131152.b4fcd4f6.randy.dunlap@oracle.com> (raw)
In-Reply-To: <1162328823.9542.434.camel@lnx-dfults.americas.sgi.com>

On Tue, 31 Oct 2006 15:07:03 -0600 Derek Fults wrote:

> This allows a hyphenated range of positive numbers in the string passed
> to command line helper function, get_options.    
> Currently the command line option "isolcpus=" takes as its argument a
> list of cpus.  
> Format: <cpu number>,...,<cpu number>
> This can get extremely long when isolating the majority of cpus on a
> large system.  Valid values of <cpu_number>  include all cpus, 0 to
> "number of CPUs in system - 1".
> 
> 
> Signed-off-by: Derek Fults <dfults@sgi.com>  
> 
> Index: linux/lib/cmdline.c
> ===================================================================
> --- linux.orig/lib/cmdline.c	2006-09-19 22:42:06.000000000 -0500
> +++ linux/lib/cmdline.c	2006-10-31 14:57:25.553572860 -0600
> @@ -29,6 +29,7 @@
>   *	0 : no int in string
>   *	1 : int found, no subsequent comma
>   *	2 : int found including a subsequent comma
> + *  -(int): int found with a subsequent hyphen to denote a range.

Does the returned value matter?  Is it used later?  (it appears to be)

If not, I think that we would rather reserved negative return
values to indicate errors.

Or if so, the comment should say what property the negative value
has.

>   */
>  
>  int get_option (char **str, int *pint)
> @@ -44,7 +45,16 @@
>  		(*str)++;
>  		return 2;
>  	}
> +	if (**str == '-') {
> +		int x, inc_counter= 0, upper_range = 0;

space after '='

>  
> +		(*str)++;
> +		upper_range = simple_strtol((*str), NULL, 0);
> +		inc_counter = upper_range - *pint;
> +		for (x =*pint; x < upper_range; x++)

space after '='

> +			*pint++ = x;
> +		return -inc_counter;
> +	}
>  	return 1;
>  }
>  
> @@ -55,7 +65,8 @@
>   *	@ints: integer array
>   *
>   *	This function parses a string containing a comma-separated
> - *	list of integers.  The parse halts when the array is
> + *	list of integers, a hyphen-separated range of _positive_ integers,
> + *	or a combination of both.  The parse halts when the array is
>   *	full, or when no more numbers can be retrieved from the
>   *	string.
>   *
> @@ -75,6 +86,11 @@
>  		i++;
>  		if (res == 1)
>  			break;
> +		if (res < 0)
> +			/* Decrement the result by one to leave out the
> +			   last number in the range.  The next iteration
> +			   will handle the upper number in the range */
> +			i += ((-res) - 1);
>  	}
>  	ints[0] = i - 1;
>  	return (char *)str;
> -

---
~Randy

  reply	other threads:[~2006-10-31 21:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-31 21:07 [PATCH] Allow a hyphenated range in get_options, with cleanup Derek Fults
2006-10-31 21:11 ` Randy Dunlap [this message]
2006-10-31 21:12 ` Andi Kleen

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=20061031131152.b4fcd4f6.randy.dunlap@oracle.com \
    --to=randy.dunlap@oracle.com \
    --cc=dfults@sgi.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