string: import strverscmp_improved from systemd
cover string: import strverscmp_improved from systemd
The Boot Loader specification now references the UAPI group's version format specification[1] on how blspec entries should be sorted.
In preparation of aligning barebox entry sorting with the specification, import systemd's strverscmp_improved as strverscmp and add some tests for it.
The changes to bootloader spec sorting need some more testing and will follow separately.
Ahmad Fatoum (3):
include: sync min/max definitions with Linux
include: minmax.h: implement compare3 helper
string: import strverscmp_improved from systemd
include/linux/const.h | 9 ++ include/linux/kernel.h | 123 +-------------------------- include/linux/minmax.h | 189 +++++++++++++++++++++++++++++++++++++++++ include/string.h | 2 + lib/Kconfig | 9 +- lib/Makefile | 1 + lib/strverscmp.c | 165 +++++++++++++++++++++++++++++++++++ test/self/Kconfig | 6 ++ test/self/Makefile | 1 + test/self/string.c | 175 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 557 insertions(+), 123 deletions(-) create mode 100644 include/linux/minmax.h create mode 100644 lib/strverscmp.c create mode 100644 test/self/string.c
Signature · 1 line
2.38.5
PATCH 1/3 include: sync min/max definitions with Linux
By syncing to Linux, min/max and friends now return constant expressions if possible, which makes them suitable for use as non-VLA array length.
--- include/linux/const.h | 9 +++ include/linux/kernel.h | 123 +----------------------------- include/linux/minmax.h | 169 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 122 deletions(-) create mode 100644 include/linux/minmax.h
include/linux/const.h +9 -0
@@ -26,4 +26,13 @@#define _BITUL (x) (_AC(1,UL) << (x))#define _BITULL (x) (_AC(1,ULL) << (x)) + +/* +* This returns a constant expression while determining if an argument is +* a constant expression, most importantly without evaluating the argument. +* Glory to Martin Uecker <[email protected]> +*/ +#define __is_constexpr (x) \ + (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) +#endif /* !(_LINUX_CONST_H) */
include/linux/kernel.h +1 -122
141 lines not on this page · raw message
include/linux/minmax.h new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.38.5
PATCH 2/3 include: minmax.h: implement compare3 helper
In reply to Ahmad FatoumDefine the macro for use in comparison functions. The macro has the same semantics as systemd's CMP() macro with the difference that it returns constant expressions if possible.
--- include/linux/minmax.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/linux/minmax.h +20 -0
@@ -166,4 +166,24 @@#define swap (a, b) \ do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) + +#define __compare3 (x, y) ((x) < (y) ? -1 : (x) > (y) ? 1 : 0) + +#define __compare3_once (x, y, unique_x, unique_y) ({ \ + typeof(x) unique_x = (x); \ + typeof(y) unique_y = (y); \ + __compare3(unique_x, unique_y); }) + +/** +* compare3 - 3-way comparison of @x and @y +* @x: first value +* @y: second value +* +* returns -1 if x < y, 0 if x == y and 1 if x > y +*/ +#define compare3 (x, y) \ + __builtin_choose_expr(__safe_cmp(x, y), \ + __compare3(x, y), \ + __compare3_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) +#endif /* _LINUX_MINMAX_H */
Signature · 1 line
2.38.5
PATCH 3/3 string: import strverscmp_improved from systemd
In reply to Ahmad FatoumThe Boot Loader specification now references the UAPI group's version format specification[1] on how blspec entries should be sorted.
In preparation of aligning barebox entry sorting with the specification, import systemd's strverscmp_improved as strverscmp and add some tests for it.
The selftest is called string.c, because it indirectly tests some string mangling function and in anticipation of adding more string tests in the future.
[1]: https://uapi-group.org/specifications/specs/version_format_specification/#examples
--- include/string.h | 2 + lib/Kconfig | 9 ++- lib/Makefile | 1 + lib/strverscmp.c | 165 ++++++++++++++++++++++++++++++++++++++++++ test/self/Kconfig | 6 ++ test/self/Makefile | 1 + test/self/string.c | 175 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 lib/strverscmp.c create mode 100644 test/self/string.c
include/string.h +2 -0
@@ -18,4 +18,6 @@ void *__nokasan_default_memcpy(void * dest,const void *src,size_t count);char *parse_assignment (char *str); +int strverscmp (const char *a,const char *b); +#endif /* __STRING_H */
lib/Kconfig +8 -1
@@ -107,7 +107,7 @@ config IMAGE_SPARSE bool config STMP_DEVICE - bool "STMP device support" if COMPILE_TEST + bool "STMP device support" config FSL_QE_FIRMWARE select CRC32
@@ -167,6 +167,13 @@ config PROGRESS_NOTIFIER This is selected by boards that register a notifier to visualize progress, like blinking a LED during an update. +config VERSION_CMP + bool "version comparison utilities" if COMPILE_TEST + help + This is selected by code that needs to compare versions + in a manner compatible with + https://uapi-group.org/specifications/specs/version_format_specification + config PRINTF_UUID bool default y if PRINTF_FULL
lib/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-pbl-y += ctype.o obj-y += rbtree.o obj-y += display_options.o obj-y += string.o +obj-$(CONFIG_VERSION_CMP) += strverscmp.o obj-y += strtox.o obj-y += kstrtox.o obj-y += vsprintf.o
lib/strverscmp.c new file +165 -0
165 lines not on this page · raw message
test/self/Kconfig +6 -0
@@ -38,6 +38,8 @@ config SELFTEST_ENABLE_ALL imply SELFTEST_JSON imply SELFTEST_DIGEST imply SELFTEST_MMU + imply SELFTEST_REGULATOR + imply SELFTEST_STRING help Selects all self-tests compatible with current configuration
@@ -81,4 +83,8 @@ config SELFTEST_DIGEST depends on DIGEST select PRINTF_HEXSTR +config SELFTEST_STRING + bool "String library selftest" + select VERSION_CMP + endif
test/self/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o obj-$(CONFIG_SELFTEST_JSON) += json.o obj-$(CONFIG_SELFTEST_DIGEST) += digest.o obj-$(CONFIG_SELFTEST_MMU) += mmu.o +obj-$(CONFIG_SELFTEST_STRING) += string.o clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z clean-files += *.dtbo *.dtbo.S .*.dtso
test/self/string.c new file +175 -0
175 lines not on this page · raw message
Signature · 1 line
2.38.5
Sascha Hauer
AppliedQuoted 7 lines · Ahmad Fatoum
The Boot Loader specification now references the UAPI group's version format specification[1] on how blspec entries should be sorted.
In preparation of aligning barebox entry sorting with the specification, import systemd's
strverscmp_improvedas strverscmp and add some tests for it.
Quoted 7 lines
The changes to bootloader spec sorting need some more testing and will follow separately.
Ahmad Fatoum (3):
include: sync min/max definitions with Linux
include:minmax.h: implement compare3 helper
string: importstrverscmp_improvedfrom systemd
Applied, thanks
Sascha
Quoted 21 lines
include/linux/const.h | 9 ++ include/linux/kernel.h | 123 +-------------------------- include/linux/minmax.h | 189 +++++++++++++++++++++++++++++++++++++++++ include/string.h | 2 + lib/Kconfig | 9 +- lib/Makefile | 1 + lib/strverscmp.c | 165 +++++++++++++++++++++++++++++++++++ test/self/Kconfig | 6 ++ test/self/Makefile | 1 + test/self/string.c | 175 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 557 insertions(+), 123 deletions(-) create mode 100644 include/linux/minmax.h create mode 100644 lib/strverscmp.c create mode 100644 test/self/string.cSignature · 1 line
2.38.5
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |