Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1371387

Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID

From Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID
Date 2016-04-05 13:00 +0200
Message-ID <rkwSe-1Ul-1@gated-at.bofh.it> (permalink)
References <rkcTw-3Fi-9@gated-at.bofh.it> <rkcTx-3Fi-39@gated-at.bofh.it> <rkmpS-2lv-69@gated-at.bofh.it>
Organization Intel Finland Oy

Show all headers | View raw


On Mon, 2016-04-04 at 16:40 -0700, Andrew Morton wrote:
> On Mon,  4 Apr 2016 16:30:05 +0300 Andy Shevchenko <andriy.shevchenko
> @linux.intel.com> wrote:
> 
> > 
> > There are new helpers in this patch:
> > 
> > uuid_is_valid		checks if a UUID is valid
> > uuid_be_to_bin		converts from string to binary (big
> > endian)
> > uuid_le_to_bin		converts from string to binary
> > (little endian)
> 	> 
> > 
> > They will be used in future, i.e. in the following patches in the
> > series.
> > 
> > This also moves indices arrays to lib/uuid.c to be shared accross
> > modules.
> > 
> > ...
> > 
> > --- a/include/linux/uuid.h
> > +++ b/include/linux/uuid.h
> Nit:
> 
> > 
> > +/**
> > +  * uuid_is_valid - checks if UUID string valid
> > +  * @uuid:	UUID string to check
> > +  *
> > +  * Description:
> > +  * It checks if the UUID string is following the format:
> > +  *	xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
> > +  * where x is a hex digit.
> > +  *
> > +  * Return: 0 on success, %-EINVAL otherwise.
> > +  */
> > +int uuid_is_valid(const char *uuid)
> > +{
> > +	unsigned int i;
> > +
> > +	if (strnlen(uuid, UUID_STRING_LEN) < UUID_STRING_LEN)
> > +		return -EINVAL;
> > +
> > +	for (i = 0; i < UUID_STRING_LEN; i++) {
> > +		if (i == 8 || i == 13 || i == 18 || i == 23) {
> > +			if (uuid[i] != '-')
> > +				return -EINVAL;
> > +		} else if (!isxdigit(uuid[i])) {
> > +			return -EINVAL;
> > +		}
> > +	}
> Could add
> 
> 	if (uuid[i])
> 		return -EINVAL;
> 
> here and lose the additional pass across the input (strlen).

Others suggested a boolean. I would send a fixup later.

> 
> > 
> > +	return 0;
> > +}
> > 
> > ...
> > 

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/8] uuid: convert users to generic UUID API Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-04 15:40 +0200
  [PATCH v2 1/8] lib/vsprintf: simplify UUID printing Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-04 15:40 +0200
  [PATCH v2 2/8] lib/uuid: move generate_random_uuid() to uuid.c Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-04 15:40 +0200
  [PATCH v2 4/8] lib/uuid: remove FSF address Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-04 15:40 +0200
  [PATCH v2 8/8] efivars: use generic UUID library Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-04 15:40 +0200
  [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-04 15:40 +0200
    Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for  UUID Andrew Morton <akpm@linux-foundation.org> - 2016-04-05 01:50 +0200
      Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for  UUID Joe Perches <joe@perches.com> - 2016-04-05 02:00 +0200
      Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for  UUID Stephen Rothwell <sfr@canb.auug.org.au> - 2016-04-05 02:50 +0200
      Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for  UUID Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-05 13:00 +0200
  Re: [PATCH v2 0/8] uuid: convert users to generic UUID API Andrew Morton <akpm@linux-foundation.org> - 2016-04-05 01:50 +0200
    Re: [PATCH v2 0/8] uuid: convert users to generic UUID API Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-05 13:10 +0200
    Re: [PATCH v2 0/8] uuid: convert users to generic UUID API Matt Fleming <matt@codeblueprint.co.uk> - 2016-04-05 16:20 +0200

csiph-web