All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
	Theodore Ts'o <tytso-3s7WtUTddSA@public.gmane.org>,
	Matt Fleming
	<matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>,
	Rasmus Villemoes
	<linux-qQsb+v5E8BnlAoU/VqSP6n9LOBIZ5rWg@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID
Date: Tue, 05 Apr 2016 13:51:50 +0300	[thread overview]
Message-ID: <1459853510.12843.8.camel@linux.intel.com> (raw)
In-Reply-To: <20160404164029.9c72a93cb29d619766fbb2d2-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>

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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Intel Finland Oy

WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>, "Theodore Ts'o" <tytso@mit.edu>,
	Matt Fleming <matt@codeblueprint.co.uk>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org,
	linux-api@vger.kernel.org
Subject: Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID
Date: Tue, 05 Apr 2016 13:51:50 +0300	[thread overview]
Message-ID: <1459853510.12843.8.camel@linux.intel.com> (raw)
In-Reply-To: <20160404164029.9c72a93cb29d619766fbb2d2@linux-foundation.org>

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

  parent reply	other threads:[~2016-04-05 10:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-04 13:30 [PATCH v2 0/8] uuid: convert users to generic UUID API Andy Shevchenko
2016-04-04 13:30 ` Andy Shevchenko
2016-04-04 13:30 ` [PATCH v2 1/8] lib/vsprintf: simplify UUID printing Andy Shevchenko
2016-04-04 13:30 ` [PATCH v2 2/8] lib/uuid: move generate_random_uuid() to uuid.c Andy Shevchenko
2016-04-04 13:30 ` [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID Andy Shevchenko
2016-04-04 23:40   ` Andrew Morton
2016-04-04 23:55     ` Joe Perches
     [not found]     ` <20160404164029.9c72a93cb29d619766fbb2d2-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2016-04-05  0:48       ` Stephen Rothwell
2016-04-05  0:48         ` Stephen Rothwell
2016-04-05 10:51       ` Andy Shevchenko [this message]
2016-04-05 10:51         ` Andy Shevchenko
     [not found] ` <1459776610-68469-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-04-04 13:30   ` [PATCH v2 4/8] lib/uuid: remove FSF address Andy Shevchenko
2016-04-04 13:30     ` Andy Shevchenko
2016-04-04 13:30   ` [PATCH v2 5/8] sysctl: drop away useless label Andy Shevchenko
2016-04-04 13:30     ` Andy Shevchenko
2016-04-04 13:30 ` [PATCH v2 6/8] sysctl: use generic UUID library Andy Shevchenko
2016-04-04 13:30 ` [PATCH v2 7/8] efi: redefine type, constant, macro from generic code Andy Shevchenko
2016-04-04 13:30 ` [PATCH v2 8/8] efivars: use generic UUID library Andy Shevchenko
2016-04-04 23:40 ` [PATCH v2 0/8] uuid: convert users to generic UUID API Andrew Morton
     [not found]   ` <20160404164020.9a3529e6e247aac6ec114fff-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2016-04-05 11:07     ` Andy Shevchenko
2016-04-05 11:07       ` Andy Shevchenko
2016-04-05 14:06     ` Matt Fleming
2016-04-05 14:06       ` Matt Fleming

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=1459853510.12843.8.camel@linux.intel.com \
    --to=andriy.shevchenko-vuqaysv1563yd54fqh9/ca@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-qQsb+v5E8BnlAoU/VqSP6n9LOBIZ5rWg@public.gmane.org \
    --cc=matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org \
    --cc=tytso-3s7WtUTddSA@public.gmane.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 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.