Date: Wed, 22 Apr 2026 21:08:54 +0000 From: Bjoern A. Zeeb <bz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 97c58ec8702f - stable/15 - LinuxKPI: move hex2bin() from kernel.h to new hex.h Message-ID: <69e938e6.30a21.7c175af3@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=97c58ec8702ff1275f77e8d5ffb519da0d386268 commit 97c58ec8702ff1275f77e8d5ffb519da0d386268 Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2026-04-14 13:36:40 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> CommitDate: 2026-04-22 20:57:08 +0000 LinuxKPI: move hex2bin() from kernel.h to new hex.h New Linux v7.0 drivers include hex.h. Rather than adding a dummy header, migrate the kernel.h hex2bin() into hex.h, where it belongs. Care needs to be taken as the _h2b() helper function is still used by other bits in kernel.h. Sponsored by: The FreeBSD Foundation Reviewed by: emaste, dumbbell Differential Revision: https://reviews.freebsd.org/D56391 (cherry picked from commit 98297ff3cfbb42df86fa7af51a2740d5aa7236eb) --- sys/compat/linuxkpi/common/include/linux/hex.h | 44 +++++++++++++++++++++++ sys/compat/linuxkpi/common/include/linux/kernel.h | 32 +---------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/hex.h b/sys/compat/linuxkpi/common/include/linux/hex.h new file mode 100644 index 000000000000..7e9f499cfb1b --- /dev/null +++ b/sys/compat/linuxkpi/common/include/linux/hex.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022-2026 Bjoern A. Zeeb + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifndef _LINUXKPI_LINUX_HEX_H_ +#define _LINUXKPI_LINUX_HEX_H_ + +#include <linux/types.h> +#include <linux/errno.h> + +static inline int +_h2b(const char c) +{ + + if (c >= '0' && c <= '9') + return (c - '0'); + if (c >= 'a' && c <= 'f') + return (10 + c - 'a'); + if (c >= 'A' && c <= 'F') + return (10 + c - 'A'); + return (-EINVAL); +} + +static inline int +hex2bin(uint8_t *bindst, const char *hexsrc, size_t binlen) +{ + int hi4, lo4; + + while (binlen > 0) { + hi4 = _h2b(*hexsrc++); + lo4 = _h2b(*hexsrc++); + if (hi4 < 0 || lo4 < 0) + return (-EINVAL); + + *bindst++ = (hi4 << 4) | lo4; + binlen--; + } + + return (0); +} + +#endif /* _LINUXKPI_LINUX_HEX_H_ */ diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index 880d2f67c517..2430b25c6915 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -56,6 +56,7 @@ #include <linux/log2.h> #include <linux/kconfig.h> #include <linux/instruction_pointer.h> +#include <linux/hex.h> #include <asm/byteorder.h> #include <asm/cpufeature.h> @@ -305,37 +306,6 @@ linux_ratelimited(linux_ratelimit_t *rl) #define add_taint(x,y) do { \ } while (0) -static inline int -_h2b(const char c) -{ - - if (c >= '0' && c <= '9') - return (c - '0'); - if (c >= 'a' && c <= 'f') - return (10 + c - 'a'); - if (c >= 'A' && c <= 'F') - return (10 + c - 'A'); - return (-EINVAL); -} - -static inline int -hex2bin(uint8_t *bindst, const char *hexsrc, size_t binlen) -{ - int hi4, lo4; - - while (binlen > 0) { - hi4 = _h2b(*hexsrc++); - lo4 = _h2b(*hexsrc++); - if (hi4 < 0 || lo4 < 0) - return (-EINVAL); - - *bindst++ = (hi4 << 4) | lo4; - binlen--; - } - - return (0); -} - static inline bool mac_pton(const char *macin, uint8_t *macout) {home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e938e6.30a21.7c175af3>
