Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757827AbcDEKu5 (ORCPT ); Tue, 5 Apr 2016 06:50:57 -0400 Received: from mga03.intel.com ([134.134.136.65]:58000 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757401AbcDEKuz (ORCPT ); Tue, 5 Apr 2016 06:50:55 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,443,1455004800"; d="scan'208";a="778358711" Message-ID: <1459853510.12843.8.camel@linux.intel.com> Subject: Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID From: Andy Shevchenko To: Andrew Morton Cc: Arnd Bergmann , "Theodore Ts'o" , Matt Fleming , Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-api@vger.kernel.org Date: Tue, 05 Apr 2016 13:51:50 +0300 In-Reply-To: <20160404164029.9c72a93cb29d619766fbb2d2@linux-foundation.org> References: <1459776610-68469-1-git-send-email-andriy.shevchenko@linux.intel.com> <1459776610-68469-4-git-send-email-andriy.shevchenko@linux.intel.com> <20160404164029.9c72a93cb29d619766fbb2d2@linux-foundation.org> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1731 Lines: 73 On Mon, 2016-04-04 at 16:40 -0700, Andrew Morton wrote: > On Mon,  4 Apr 2016 16:30:05 +0300 Andy 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 Intel Finland Oy