linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Lukasz Dorau <lukasz.dorau@intel.com>
Cc: linux-raid@vger.kernel.org, ed.ciechanowski@intel.com,
	maciej.patelczyk@intel.com
Subject: Re: [PATCH] fix: adjust parse_size() to the unsigned size variable
Date: Thu, 20 Sep 2012 12:31:56 +1000	[thread overview]
Message-ID: <20120920123156.4f1fb8fb@notabene.brown> (raw)
In-Reply-To: <20120914141245.18725.59647.stgit@gklab-128-085.igk.intel.com>

[-- Attachment #1: Type: text/plain, Size: 1986 bytes --]

On Fri, 14 Sep 2012 16:12:45 +0200 Lukasz Dorau <lukasz.dorau@intel.com>
wrote:

> An error in parse_size() should be reported by 0, not -1,
> because -1 is changed to the max value of unsigned long long
> during calculations of size (e.g. at mdadm.c:412).
> 
> A negative value of size should be reported as error
> (e.g. size equal -1 has been changed to the max value of
> unsigned long long so far).
> 
> Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
> ---
>  mdadm.h |    2 +-
>  util.c  |    9 +++++----
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/mdadm.h b/mdadm.h
> index 9feccc6..f202ffa 100644
> --- a/mdadm.h
> +++ b/mdadm.h
> @@ -1156,7 +1156,7 @@ extern unsigned long bitmap_sectors(struct bitmap_super_s *bsb);
>  extern int md_get_version(int fd);
>  extern int get_linux_version(void);
>  extern int mdadm_version(char *version);
> -extern long long parse_size(char *size);
> +extern unsigned long long parse_size(char *size);
>  extern int parse_uuid(char *str, int uuid[4]);
>  extern int parse_layout_10(char *layout);
>  extern int parse_layout_faulty(char *layout);
> diff --git a/util.c b/util.c
> index a92a663..c63a232 100644
> --- a/util.c
> +++ b/util.c
> @@ -188,13 +188,13 @@ int mdadm_version(char *version)
>  	return (a*1000000)+(b*1000)+c;
>  }
>  
> -long long parse_size(char *size)
> +unsigned long long parse_size(char *size)
>  {
>  	/* parse 'size' which should be a number optionally
>  	 * followed by 'K', 'M', or 'G'.
>  	 * Without a suffix, K is assumed.
>  	 * Number returned is in sectors (half-K)
> -	 * -1 returned on error.
> +	 * 0 returned on error.
>  	 */
>  	char *c;
>  	long long s = strtoll(size, &c, 10);
> @@ -214,9 +214,10 @@ long long parse_size(char *size)
>  			s *= 1024 * 1024 * 2;
>  			break;
>  		}
> -	}
> +	} else
> +		s = 0;
>  	if (*c)
> -		s = -1;
> +		s = 0;
>  	return s;
>  }
>  

Applied, Thanks.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

      reply	other threads:[~2012-09-20  2:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-14 14:12 [PATCH] fix: adjust parse_size() to the unsigned size variable Lukasz Dorau
2012-09-20  2:31 ` NeilBrown [this message]

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=20120920123156.4f1fb8fb@notabene.brown \
    --to=neilb@suse.de \
    --cc=ed.ciechanowski@intel.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=lukasz.dorau@intel.com \
    --cc=maciej.patelczyk@intel.com \
    /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).