Message ID | cover.1704324320.git.wqu@suse.com (mailing list archive) |
---|---|
Headers | show |
Series | kstrtox: introduce memparse_safe() | expand |
On Thu, Jan 04, 2024 at 09:57:47AM +1030, Qu Wenruo wrote: > [CHANGELOG] > v3: > - Fix the 32bit pointer pattern in the test case > The old pointer pattern for 32 bit systems is in fact 40 bits, > which would still lead to sparse warning. > The newer pattern is using UINTPTR_MAX to trim the pattern, then > converted to a pointer, which should not cause any trimmed bits and > make sparse happy. Having test cases is quite good, thanks! But as I understood what Alexey wanted, is not using the kstrtox files for this. You can introduce it in the cmdline.c, correct? Just include local "kstrtox.h". I'm on leave till end of the month, I'll look at this later.
On 2024/1/7 01:04, Andy Shevchenko wrote: > On Thu, Jan 04, 2024 at 09:57:47AM +1030, Qu Wenruo wrote: >> [CHANGELOG] >> v3: >> - Fix the 32bit pointer pattern in the test case >> The old pointer pattern for 32 bit systems is in fact 40 bits, >> which would still lead to sparse warning. >> The newer pattern is using UINTPTR_MAX to trim the pattern, then >> converted to a pointer, which should not cause any trimmed bits and >> make sparse happy. > > Having test cases is quite good, thanks! > But as I understood what Alexey wanted, is not using the kstrtox files for this. > You can introduce it in the cmdline.c, correct? Just include local "kstrtox.h". Not really possible, all the needed parsing helpers are internal inside kstrtox.c. Furthermore, this also means memparse() can not be enhanced due to: - Lack of ways to return errors - Unable to call the parsing helpers inside cmdline.c Thanks, Qu > > I'm on leave till end of the month, I'll look at this later. >
On Sun, Jan 07, 2024 at 07:28:27AM +1030, Qu Wenruo wrote: > On 2024/1/7 01:04, Andy Shevchenko wrote: > > On Thu, Jan 04, 2024 at 09:57:47AM +1030, Qu Wenruo wrote: ... > > Having test cases is quite good, thanks! > > But as I understood what Alexey wanted, is not using the kstrtox files for this. > > You can introduce it in the cmdline.c, correct? Just include local "kstrtox.h". > > Not really possible, all the needed parsing helpers are internal inside > kstrtox.c. I'm not sure I follow. The functions are available to other library (built-in) modules. > Furthermore, this also means memparse() can not be enhanced due to: > > - Lack of ways to return errors What does this mean? > - Unable to call the parsing helpers inside cmdline.c ??? (see above)
On 2024/1/15 00:12, Andy Shevchenko wrote: > On Sun, Jan 07, 2024 at 07:28:27AM +1030, Qu Wenruo wrote: >> On 2024/1/7 01:04, Andy Shevchenko wrote: >>> On Thu, Jan 04, 2024 at 09:57:47AM +1030, Qu Wenruo wrote: > > ... > >>> Having test cases is quite good, thanks! >>> But as I understood what Alexey wanted, is not using the kstrtox files for this. >>> You can introduce it in the cmdline.c, correct? Just include local "kstrtox.h". >> >> Not really possible, all the needed parsing helpers are internal inside >> kstrtox.c. > > I'm not sure I follow. The functions are available to other library (built-in) > modules. Did I miss something? Firstly neither _parse_integer_fixup_radix() nor _parse_integer_limit() is exported to modules. (No EXPORT_SYMBOL() call on them). Secondly _parse_integer_fixup_radix() and _parse_integer_limit have "_" prefix, and is only declared in "lib/kstrtox.h", which means they are designed only for internal usage. If putting memparse_safe() into cmdline.c, at least we would need to include local header "kstrtox.h", and I'm not sure if this is any better than putting memparse_safe() into kstrtox.[ch]. Finally, I just tried putting memparse_safe() into cmdline.c, and it failed at linkage stage, even if that offending file has no call to memparse_safe(): ld: arch/x86/boot/compressed/kaslr.o: in function `memparse_safe': kaslr.c:(.text+0xbb1): undefined reference to `_parse_integer_fixup_radix' ld: kaslr.c:(.text+0xbc5): undefined reference to `_parse_integer' ld: arch/x86/boot/compressed/vmlinux: hidden symbol `_parse_integer' isn't defined I can try again but I'm not sure if it's possible to move memparse_safe() to cmdline.[ch]. > >> Furthermore, this also means memparse() can not be enhanced due to: >> >> - Lack of ways to return errors > > What does this mean? If you want to keep the prototype of memparse() (aka, a drop-in enhancement), then there is no good way to indicate the errors like overflow at all. > >> - Unable to call the parsing helpers inside cmdline.c > > ??? (see above) > See above. Thanks, Qu