Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757317AbcDDXzz (ORCPT ); Mon, 4 Apr 2016 19:55:55 -0400 Received: from smtprelay0220.hostedemail.com ([216.40.44.220]:41827 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756528AbcDDXzy (ORCPT ); Mon, 4 Apr 2016 19:55:54 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::,RULES_HIT:41:355:379:541:599:960:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:1978:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3622:3865:3867:3868:3870:3871:3872:4250:4321:5007:7875:7904:10004:10400:10848:10967:11026:11232:11473:11658:11783:11914:12043:12517:12519:12683:12740:13069:13149:13230:13311:13357:13439:13894:14659:14721:21080:30036:30054:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: bun67_160502a2ecd3a X-Filterd-Recvd-Size: 2762 Message-ID: <1459814150.2138.3.camel@perches.com> Subject: Re: [PATCH v2 3/8] lib/uuid: introduce few more generic helpers for UUID From: Joe Perches To: Andrew Morton , Andy Shevchenko 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: Mon, 04 Apr 2016 16:55:50 -0700 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> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu1 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: 1510 Lines: 58 On Mon, 2016-04-04 at 16:40 -0700, Andrew Morton wrote: > On Mon,??4 Apr 2016 16:30:05 +0300 Andy Shevchenko 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). nit2: Could make this return bool.