From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Josh Law <hlcj1234567@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Josh Law <objecting@objecting.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] lib/uuid: avoid double traversal in __uuid_parse()
Date: Fri, 13 Mar 2026 11:04:15 +0200 [thread overview]
Message-ID: <abPTD5sFEr4L4W_k@ashevche-desk.local> (raw)
In-Reply-To: <20260312184113.23564-1-objecting@objecting.org>
On Thu, Mar 12, 2026 at 06:41:13PM +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.
...
> - if (!uuid_is_valid(uuid))
> - return -EINVAL;
In case if valid string it heats up the caches, no?
> 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;
Here we add a branch (or two, depending on the code generation)
> b[ei[i]] = (hi << 4) | lo;
> }
> + if (uuid[8] != '-' || uuid[13] != '-' ||
> + uuid[18] != '-' || uuid[23] != '-')
> + return -EINVAL;
And one more here.
> return 0;
> }
If you a really into performance, please, provide the tests and the results to
show the benefit. Numbers will tell for themselves.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-03-13 9:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 18:41 Josh Law
2026-03-12 20:48 ` Andrew Morton
2026-03-12 20:51 ` Josh Law
2026-03-13 9:04 ` Andy Shevchenko [this message]
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=abPTD5sFEr4L4W_k@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=hlcj1234567@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=objecting@objecting.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®