From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2727429D27D for ; Thu, 12 Mar 2026 20:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773348539; cv=none; b=ALjYY5FCEpczz8QgKD7du0GlelD7EjV2Vkq1nWSPmUTelR5p2cko7WQ67HA26zBeqJs3abzdN/GMimWEwdlCrfJFIeTsYqdSut/E9dZ+lQGvPoCMnqGJTjiK3QK7Ws8vqWhvIcYN2Ql1nbw6C3XsnsvXkyAak9CYkt63sxdy5p8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773348539; c=relaxed/simple; bh=kkhZgw6YzFQFLW+SK+rLyOlG63/FdoBW6OkswBaOebA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=RHxwvVSzyWhrnxF+Lflt3Z5j8id39g03LPeGpAgk93YzmT4uipaKh/Gzooyhr0JUluc+ViPJXt7c4jvJNwVpRZpACPgWZA+EmTKvnGbyygOXphjN0aslyyl6x8mM4SIkQOZE8OaXyVKwp6u0eVeaQv0Z8UgB4rAsRQImMMiMLJo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=ieYl8q96; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="ieYl8q96" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98325C4CEF7; Thu, 12 Mar 2026 20:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1773348538; bh=kkhZgw6YzFQFLW+SK+rLyOlG63/FdoBW6OkswBaOebA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ieYl8q96QJsh+fnzmozbrHz2SNUeO44iUicKT1w+50I9QdkJOWEO3niGLCS+HMEsU bSPDXNDJqX///8hG+szuhGdEUCIDvo9wZQuf8b0mummjpU/gnnTLgP7IfuYotAF7P2 oeEeYprh+SDsAnGWQon75FRifaOZIfT4lmBPaiqs= Date: Thu, 12 Mar 2026 13:48:58 -0700 From: Andrew Morton To: Josh Law Cc: Andy Shevchenko , Josh Law , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] lib/uuid: avoid double traversal in __uuid_parse() Message-Id: <20260312134858.672c3a6b63bfdbb3962eccec@linux-foundation.org> In-Reply-To: <20260312184113.23564-1-objecting@objecting.org> References: <20260312184113.23564-1-objecting@objecting.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 12 Mar 2026 18:41:13 +0000 Josh Law wrote: > __uuid_parse() calls uuid_is_valid() to walk all 36 characters for > format validation, then walks the string a second time to parse the > hex bytes. Combine both passes into one: validate each hex digit > inline via hex_to_bin() return value and check the four dash positions > after the loop. > > uuid_is_valid() remains exported unchanged for callers that only need > validation without parsing. > > --- a/lib/uuid.c > +++ b/lib/uuid.c > @@ -108,16 +108,20 @@ static int __uuid_parse(const char *uuid, __u8 b[16], const u8 ei[16]) > static const u8 si[16] = {0,2,4,6,9,11,14,16,19,21,24,26,28,30,32,34}; > unsigned int i; > > - if (!uuid_is_valid(uuid)) > - return -EINVAL; > - > for (i = 0; i < 16; i++) { > int hi = hex_to_bin(uuid[si[i] + 0]); > int lo = hex_to_bin(uuid[si[i] + 1]); > > + if (hi < 0 || lo < 0) > + return -EINVAL; > + > b[ei[i]] = (hi << 4) | lo; > } > > + if (uuid[8] != '-' || uuid[13] != '-' || > + uuid[18] != '-' || uuid[23] != '-') > + return -EINVAL; > + > return 0; This rather messifies the code, and for what? Is this in any way a hot path?