Re: [PATCH v2 1/2] lib/strtox: introduce kstrtoull_suffix() helper

From: Qu Wenruo
Date: Sat Dec 23 2023 - 04:58:14 EST




On 2023/12/20 16:08, David Disseldorp wrote:
On Wed, 20 Dec 2023 10:40:00 +1030, Qu Wenruo wrote:

[...]

----
Changelog:
v2:
- Use enum bitmap to describe the suffixes
This gets rid of the upper/lower case problem, and enum makes it
a little more readable.

- Fix the suffix overflow detection

- Move the left shift out of the switch block

- Remove the "done" tag
Since no tailing character can already be handled properly.

nit: git am puts this changelog in the commit message when applied.
Please use `git send-email --annotate` and put it next to the diffstat,
so that it gets discarded.

Got it.

[...]
+};
+
+/*
+ * The default suffix list would not include "E" since it's too easy to overflow
+ * and not much real world usage.
+ */

^ this comment is a duplicate.

+#define KSTRTOULL_SUFFIX_DEFAULT (SUFFIX_K | SUFFIX_M | SUFFIX_G | SUFFIX_T | SUFFIX_P)

I think it'd be clearer if you dropped this default and had callers
explicitly provide the desired suffix mask.

Well, that would be long, and would be even longer as the newer naming
would be MEMPARSE_SUFFIX_*, to be more explicit on what the suffix is for...

And I really want callers to choose a saner default suffix, thus here
comes the default one.

In fact, in my next version, I also found that there are some memparse()
call sites benefits from the newer suffixes (although won't for the "E"
one).
The example is the call site setup_elfcorehdr(). Where the comment only
mentions KMG, but since memparse() silently added "PE" suffixes, maybe
on some mainframes we saved some time for one or two lucky admins.

[...]


With the above changes made, feel free to add
Reviewed-by: David Disseldorp <ddiss@xxxxxxx>

Thanks for the review, but I'm afraid the newer version would be another
beast.

All the ommitted comments would be addressed a in new series.

I'll leave the review of patch 2/2 up to others, as I'm still a little
worried about sysfs trailing whitespace regressions.

That won't be a problem anymore, the new series would keep the old
@retptr behavior, thus for btrfs part it won't be changed at all.

Thanks,
Qu