From nobody Wed Apr 22 21:08:02 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g1Bdb1Hljz6bKtG for ; Wed, 22 Apr 2026 21:08:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g1BdZ4tmJz3kCv for ; Wed, 22 Apr 2026 21:08:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776892082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QrMm/46VM8j6HUjoN/g0apQGQJRbtEZ5TiLeMTRtWQw=; b=pfIuXF2oChNs+5q2grRZ4+f9eVkdctlOwV6SBnggG8aM5qdEVaIY96Yt4ciOqi5HtJPV+T gp3hMpw8tZsqkk7Y+RYZFkK4vgHFcampd6VyXUbefSMTnX8EKFHpel+VIt4qs5ag/8J4cD YTrj6/4yiOO+c2UyDIItxFx1XogFrf1kx/IVYnTCWLU5XBOyqY01d2BcMzNM+DfsYBOIqn MyRa99K8lKEXC28Z7kcJC/VFkkqKgRWF44K0zZ4Ekd/v99IRhpGWcAkIEm7kXlPqH3ILvV /IUcT4Nd6MxNz5YO5zNPZYSaUQsWLO9H7uThWcnI9AvgYh0WZW8d6AEAfwvxzA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776892082; a=rsa-sha256; cv=none; b=K9nAySIdJOAE74XJfDglA2N6tbM2EPdIFHa+4jihyU5ZRm7Z8QTkgxZIti6lNYbCDyP/JT +8rQbqHBgectj82+BLpOd9KQMGmTJtI8qhILQnfhrMHcP9+k5cXVNSJ5VPJaYP0xQoyaSG 7KlDUoT3QeVpTT61k7XUSZTlUqg6JYeF8uuHKooK74o3LEdyzjoN56uFRNqaFkjWlb8GFg 1DlsQfpHpExSUX8eWRY+yxCJqL7RjeShPdgw0rHg0WdZxgakDWJWQjZDTiRAEgQeTi8lqN MKFsQhmjXmFC8nDBjcbnmmHQ7p0339S0H+v8TAFSVmyXvDb7/FBF/yO6pnxSjQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776892082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QrMm/46VM8j6HUjoN/g0apQGQJRbtEZ5TiLeMTRtWQw=; b=prSfEdjJpi1mJgB4p47jDjnXyZafHdDbb8Sf/6sDodDTIhmEMqrU0XpHxBmr8CafD5DKsT m9nMrp0P906KzRMfU1NwTMy1/Qu813rwpA9k9+48USoVg+lylI6ZaiIberDEmiuq9yBDjd oF3hZupi5G3VCkLNvjwNz/Uto/cz62kbsO10ZHqMbhEymafBgd6R0B8aBwAaNf6i2+ok0V fmBummq6RHkMazm14H+fnHT+IwHO4J83S4ByimmzAZkshKt7oqL2kB/iOF2gTZ4IlZYEQx qEtkTKIw0wBWRg9Ue46CYuAMALErEXl5QvpiSJCbMuwWPiv7cWd3xW/0vT9CEw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1BdZ3lndznZD for ; Wed, 22 Apr 2026 21:08:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26ab5 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 22 Apr 2026 21:08:02 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron From: Bjoern A. Zeeb Subject: git: ada63d6b2e5e - stable/15 - linuxkpi: Add hex_dump_to_buffer() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: ada63d6b2e5e15ad29e08a591a8b2bff443c102d Auto-Submitted: auto-generated Date: Wed, 22 Apr 2026 21:08:02 +0000 Message-Id: <69e938b2.26ab5.5590e270@gitrepo.freebsd.org> The branch stable/15 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=ada63d6b2e5e15ad29e08a591a8b2bff443c102d commit ada63d6b2e5e15ad29e08a591a8b2bff443c102d Author: Jean-Sébastien Pédron AuthorDate: 2025-07-10 23:03:51 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-04-22 20:56:52 +0000 linuxkpi: Add hex_dump_to_buffer() This function prints a single line of hex dump to the given line buffer. The implementation relies on `lkpi_hex_dump()` to format the string. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51559 (cherry picked from commit b1bef9f7e0e182a9eee222639ffc8af4883ec0fa) --- sys/compat/linuxkpi/common/include/linux/printk.h | 6 ++ sys/compat/linuxkpi/common/src/linux_compat.c | 70 +++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/printk.h b/sys/compat/linuxkpi/common/include/linux/printk.h index e10656c8a1d0..066ec900f04e 100644 --- a/sys/compat/linuxkpi/common/include/linux/printk.h +++ b/sys/compat/linuxkpi/common/include/linux/printk.h @@ -50,6 +50,12 @@ void lkpi_hex_dump(int(*)(void *, const char *, ...), void *arg1, const char *, const char *, const int, const int, const int, const void *, size_t, const bool, const bool); +#define hex_dump_to_buffer(buf, len, rowsize, groupsize, linebuf, linebuflen, ascii) \ + lkpi_hex_dump_to_buffer((buf), (len), (rowsize), (groupsize), (linebuf), (linebuflen), (ascii)) + +int lkpi_hex_dump_to_buffer(const void *buf, size_t len, int rowsize, + int groupsize, char *linebuf, size_t linebuflen, bool ascii); + static inline void print_hex_dump(const char *level, const char *prefix_str, const int prefix_type, const int rowsize, const int groupsize, diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index c2bad1f28eaf..8fc644241d79 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -1986,6 +1986,76 @@ lkpi_hex_dump(int(*_fpf)(void *, const char *, ...), void *arg1, } } +struct hdtb_context { + char *linebuf; + size_t linebuflen; + int written; +}; + +static int +hdtb_cb(void *arg, const char *format, ...) +{ + struct hdtb_context *context; + int written; + va_list args; + + context = arg; + + va_start(args, format); + written = vsnprintf( + context->linebuf, context->linebuflen, format, args); + va_end(args); + + if (written < 0) + return (written); + + /* + * Linux' hex_dump_to_buffer() function has the same behaviour as + * snprintf() basically. Therefore, it returns the number of bytes it + * would have written if the destination buffer was large enough. + * + * If the destination buffer was exhausted, lkpi_hex_dump() will + * continue to call this callback but it will only compute the bytes it + * would have written but write nothing to that buffer. + */ + context->written += written; + + if (written < context->linebuflen) { + context->linebuf += written; + context->linebuflen -= written; + } else { + context->linebuf += context->linebuflen; + context->linebuflen = 0; + } + + return (written); +} + +int +lkpi_hex_dump_to_buffer(const void *buf, size_t len, int rowsize, + int groupsize, char *linebuf, size_t linebuflen, bool ascii) +{ + int written; + struct hdtb_context context; + + context.linebuf = linebuf; + context.linebuflen = linebuflen; + context.written = 0; + + if (rowsize != 16 && rowsize != 32) + rowsize = 16; + + len = min(len, rowsize); + + lkpi_hex_dump( + hdtb_cb, &context, NULL, NULL, DUMP_PREFIX_NONE, + rowsize, groupsize, buf, len, ascii, false); + + written = context.written; + + return (written); +} + static void linux_timer_callback_wrapper(void *context) {