From nobody Sat Jan 24 19:24:48 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 4dz4W42Lt7z6PWyD for ; Sat, 24 Jan 2026 19:24:48 +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" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dz4W41g7xz4NdK for ; Sat, 24 Jan 2026 19:24:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769282688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Gh0ViHHMIbr0gfCPfFiYgs7C8qKlLXUQxj8uqCyw0vc=; b=wJyST4LKJk85NffhQEOoKafvc5gKQiZ4eELqgomSlJ/42pF+pnmRBQBw6ogYNpZyeKhDC0 VbJ66P2gMyQbdNZbTmrrn0LGZyoI8nN46gFHyWlYKTAILln203oxGf9Tb7xIvhDyN4o5vO tnW3qBDwhSv0Qfr1rkJy3RppukWTU/Z6FrQ03mwJj+xIvgBhuKlX15ruSmyPEDWQYIf1FS WBcQZ4QqKCqfcR3Ldw+nZpBB4BpvBmAQmG+aSlJvl850Xfb57Gh9XSPirzmu209OKgh3Z2 pQ4kB51XRewWm8ApU/VYsC0HUAPKO2R3xf9NPEmsRObMnhG/zym8XshijK0omA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769282688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Gh0ViHHMIbr0gfCPfFiYgs7C8qKlLXUQxj8uqCyw0vc=; b=ORI8W4ejC7ohy1h03qZh5PGEuTaOYDF0preNVbuPg0cFHBq2O8b4yg1hrsRmXJPSBO/kP0 z+FA94xvZlzr8KWmkImm1O36+1sg8v+6V9dbCckB/u3n0/3Qr0F3ztj0dyqBe5kxBGYAEE SQOO/jGksWLoMP2KgljL2nbviDhEn50ng1fS4vy1LGi/yoUtILoRP3XgBPahCdIKAffWIM qRosktgs5cxdgOwlCYNtbgtk69ZYv9ecweiJikOK84xeDw9K9B+asS5DnOSaJ3UI1AkA7S U0vOxEXp2c9c/W90nRynTRyUVeH0VPO0gmZmkQ6L8H2t1YlnaPV450GzRtqebw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769282688; a=rsa-sha256; cv=none; b=VgOWhCOIIk0nO5+ucqtrSvCd16zTMLxNUIkFP3Ka22dDz88c0nQRzmh8llkzXssL51Gu6t +a800bADqN7hZ4np1fhLgfBYCTXUzcPA79vDb8E4tPGOzzEaVihEnfiZsHgv/icppYNh1G SBnxM92tfT5/OJcl01z3LfzawkR8Ro6ynY/ZrXGQ4LfJaDPR1TUjPQ+ia6CcEPZJjfBBYj r5XD4bmr5yugcVCQALowqaAPRz6r3ad4GRuh1v9StmV7yjVZwvz6+BFVr/eNUa7m5ya9j+ N12LjjVGmjq6h7+C5cNDGMAxRqt3qQlcXgVr3ygdKEuiYhIA/H8BVZROpO5I5A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dz4W40zfFz1HLk for ; Sat, 24 Jan 2026 19:24:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 846e by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 24 Jan 2026 19:24:48 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron Subject: git: 710167623d82 - main - linuxkpi: Implement 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: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 710167623d82664ab4276776aed502ab6f91d8ff Auto-Submitted: auto-generated Date: Sat, 24 Jan 2026 19:24:48 +0000 Message-Id: <69751c80.846e.63a3ecf0@gitrepo.freebsd.org> The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=710167623d82664ab4276776aed502ab6f91d8ff commit 710167623d82664ab4276776aed502ab6f91d8ff Author: Jean-Sébastien Pédron AuthorDate: 2025-08-11 17:51:59 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2026-01-24 19:16:14 +0000 linuxkpi: Implement It is a wrapper above a `char *` to track the overall available space in the buffer as well as the used space. This wrapper does not manage memory allocation. The DRM generic code started to use this in Linux 6.10. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D54488 --- sys/compat/linuxkpi/common/include/linux/seq_buf.h | 73 ++++++++++++++++++++++ sys/compat/linuxkpi/common/src/linux_seq_buf.c | 64 +++++++++++++++++++ sys/conf/files | 2 + sys/modules/linuxkpi/Makefile | 1 + 4 files changed, 140 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/seq_buf.h b/sys/compat/linuxkpi/common/include/linux/seq_buf.h new file mode 100644 index 000000000000..d6246a40e6f7 --- /dev/null +++ b/sys/compat/linuxkpi/common/include/linux/seq_buf.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025-2026 The FreeBSD Foundation + * Copyright (c) 2025-2026 Jean-Sébastien Pédron + * + * This software was developed by Jean-Sébastien Pédron under sponsorship + * from the FreeBSD Foundation. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifndef _LINUXKPI_LINUX_SEQ_BUF_H_ +#define _LINUXKPI_LINUX_SEQ_BUF_H_ + +#include +#include +#include +#include + +struct seq_buf { + char *buffer; + size_t size; + size_t len; +}; + +#define DECLARE_SEQ_BUF(NAME, SIZE) \ + struct seq_buf NAME = { \ + .buffer = (char[SIZE]) { 0 }, \ + .size = SIZE, \ + } + +static inline void +seq_buf_clear(struct seq_buf *s) +{ + s->len = 0; + if (s->size > 0) + s->buffer[0] = '\0'; +} + +static inline void +seq_buf_set_overflow(struct seq_buf *s) +{ + s->len = s->size + 1; +} + +static inline bool +seq_buf_has_overflowed(struct seq_buf *s) +{ + return (s->len > s->size); +} + +static inline bool +seq_buf_buffer_left(struct seq_buf *s) +{ + if (seq_buf_has_overflowed(s)) + return (0); + + return (s->size - s->len); +} + +#define seq_buf_init(s, buf, size) linuxkpi_seq_buf_init((s), (buf), (size)) +void linuxkpi_seq_buf_init(struct seq_buf *s, char *buf, unsigned int size); + +#define seq_buf_printf(s, f, ...) linuxkpi_seq_buf_printf((s), (f), __VA_ARGS__) +int linuxkpi_seq_buf_printf(struct seq_buf *s, const char *fmt, ...) \ + __printflike(2, 3); + +#define seq_buf_vprintf(s, f, a) linuxkpi_seq_buf_vprintf((s), (f), (a)) +int linuxkpi_seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args); + +#define seq_buf_str(s) linuxkpi_seq_buf_str((s)) +const char * linuxkpi_seq_buf_str(struct seq_buf *s); + +#endif diff --git a/sys/compat/linuxkpi/common/src/linux_seq_buf.c b/sys/compat/linuxkpi/common/src/linux_seq_buf.c new file mode 100644 index 000000000000..112c53044c22 --- /dev/null +++ b/sys/compat/linuxkpi/common/src/linux_seq_buf.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025-2026 The FreeBSD Foundation + * Copyright (c) 2025-2026 Jean-Sébastien Pédron + * + * This software was developed by Jean-Sébastien Pédron under sponsorship + * from the FreeBSD Foundation. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +void +linuxkpi_seq_buf_init(struct seq_buf *s, char *buf, unsigned int size) +{ + s->buffer = buf; + s->size = size; + + seq_buf_clear(s); +} + +int +linuxkpi_seq_buf_printf(struct seq_buf *s, const char *fmt, ...) +{ + int ret; + va_list args; + + va_start(args, fmt); + ret = seq_buf_vprintf(s, fmt, args); + va_end(args); + + return (ret); +} + +int +linuxkpi_seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args) +{ + int ret; + + if (!seq_buf_has_overflowed(s)) { + ret = vsnprintf(s->buffer + s->len, s->size - s->len, fmt, args); + if (s->len + ret < s->size) { + s->len += ret; + return (0); + } + } + + seq_buf_set_overflow(s); + return (-1); +} + +const char * +linuxkpi_seq_buf_str(struct seq_buf *s) +{ + if (s->size == 0) + return (""); + + if (seq_buf_buffer_left(s)) + s->buffer[s->len] = '\0'; + else + s->buffer[s->size - 1] = '\0'; + + return (s->buffer); +} diff --git a/sys/conf/files b/sys/conf/files index a6a76dec433a..5f8c9379ddf3 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -4700,6 +4700,8 @@ compat/linuxkpi/common/src/linux_rcu.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C} -I$S/contrib/ck/include" compat/linuxkpi/common/src/linux_schedule.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" +compat/linuxkpi/common/src/linux_seq_buf.c optional compat_linuxkpi \ + compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_shmemfs.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_shrinker.c optional compat_linuxkpi \ diff --git a/sys/modules/linuxkpi/Makefile b/sys/modules/linuxkpi/Makefile index c465c76a7626..77d73f19075a 100644 --- a/sys/modules/linuxkpi/Makefile +++ b/sys/modules/linuxkpi/Makefile @@ -24,6 +24,7 @@ SRCS= linux_compat.c \ linux_radix.c \ linux_rcu.c \ linux_schedule.c \ + linux_seq_buf.c \ linux_seq_file.c \ linux_shmemfs.c \ linux_shrinker.c \