lkml.org 
[lkml]   [2016]   [Apr]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID
From
Date
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

\
 
 \ /
  Last update: 2016-04-05 13:01    [W:0.135 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site