From nobody Sun Apr 13 10:00:55 2025 X-Original-To: dev-commits-src-main@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 4Zb5XR5h2bz5t3Fc; Sun, 13 Apr 2025 10:00:55 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zb5XR4MRLz46ZC; Sun, 13 Apr 2025 10:00:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744538455; 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=dzyUNMLUD1sp8OKvnNX2CMibpsl2GsVbJzBpczcps9A=; b=qAEfDg+mhfk1CC2pi06pk9xWsf/yZxUSca5dV6sScSp7d1kvtDGlg3yIMhylJTRJ9xfMI0 zp930YoChp5Lya3Q+1MXc0rgTGXrUo9eGEGVk+2fktRLDCOWJ1C9YZuEolFtyc/mDS7wYb 6paO1ovuJHTjqzl37+0f9iZhXNCO24qSUB++D80cdogfQazlwRnYFW6pHfjwmXWeN8QGGP j2/5jFzgNxB1LSgiv/SH6Tz+WsR+h+MiK2vOAp5ExV8m9zjS+L5QFrwNr0cJzE/fuG55nb Lbw0XUAABgv5ZVmIPbrYMgUCa4zRCjU80a3a9UPSnPsWVsGJ2zPg5MdHqWuXXg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744538455; a=rsa-sha256; cv=none; b=B8aNHLEuVVOWxHPUr42J2JpFtmKp+AR1/XvXMSG+kjdzHHkkMm0PgGJoQyAb1u4KvvDMSy q1XZ2LbzDuFigj6Zy+ssNWm2kGgBbfM5knbW2nAQmMQXmRLYaGCdUnoFBQ5K9R0D5tSV4f CTnw1gIFqqRqno+r3f5dXH0tTWrNeKAZq4aqHKZuadIrLg3UL/jXeTjohUv8pA/zG0ja1o pe1wsxxOCBnrjleeR2OZ3sJeWmeifTQ3GLMOX7pGyd78TmEHp9/9dmwnjb4VlyDnlTXB/1 HP8baXXstWcng4/9yaC8Ba2k/1bbkFAoIOpNlAOG6DvjrLMhIBD6+ZAqkZK98Q== 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=1744538455; 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=dzyUNMLUD1sp8OKvnNX2CMibpsl2GsVbJzBpczcps9A=; b=he+M2EugjDZioLW2NK71yyRK5D9w6iH5UI7cfVIOcO3UoQNVNasPzEwCQJMJmQVUFfJj7g uAvoI2zZoO3VjLZGsZQzGlj03EbX2yq2sD2nGZJJ+vRP+ySFLYABzVcG5dpxDOkPyA0TCa z3LY73mQDUOEtYsAhvCxUqUiuwt07jOAjMJva1X32KiiqUipPFYlg10yNTSkUZV0eSAFjN 0WHBzZJIWkDKxFXQBHo4YM018jED1+vQ1RA2QWEqaPv7+0hHIbzTysZlwd3f3GpzBpcBB2 8jWeTsib1NN26zgwOdZGSN8/7nk8NluhH+s7JGvSIpgsXqs9jWCkNQNMEIXHKA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Zb5XR3xKvzy1J; Sun, 13 Apr 2025 10:00:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53DA0tbN083917; Sun, 13 Apr 2025 10:00:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53DA0thC083914; Sun, 13 Apr 2025 10:00:55 GMT (envelope-from git) Date: Sun, 13 Apr 2025 10:00:55 GMT Message-Id: <202504131000.53DA0thC083914@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien?= =?utf-8?Q?P=C3=A9dron?= Subject: git: 78e25e65bf38 - main - lindebugfs: Add `debugfs_create_str()` List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 78e25e65bf381303c8bdac9a713ab7b26a854b8c Auto-Submitted: auto-generated The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=78e25e65bf381303c8bdac9a713ab7b26a854b8c commit 78e25e65bf381303c8bdac9a713ab7b26a854b8c Author: Jean-Sébastien Pédron AuthorDate: 2025-02-08 19:10:53 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2025-04-13 09:50:14 +0000 lindebugfs: Add `debugfs_create_str()` This function is used by the i915 DRM driver starting with Linux 6.8. Reviewed by: bz, emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49067 --- sys/compat/lindebugfs/lindebugfs.c | 115 +++++++++++++++++++++ sys/compat/linuxkpi/common/include/linux/debugfs.h | 2 + sys/modules/lindebugfs/Makefile | 1 + 3 files changed, 118 insertions(+) diff --git a/sys/compat/lindebugfs/lindebugfs.c b/sys/compat/lindebugfs/lindebugfs.c index 37028b667be8..97f73e79fb6c 100644 --- a/sys/compat/lindebugfs/lindebugfs.c +++ b/sys/compat/lindebugfs/lindebugfs.c @@ -624,6 +624,121 @@ debugfs_create_atomic_t(const char *name, umode_t mode, struct dentry *parent, a } +static int +fops_str_open(struct inode *inode, struct file *filp) +{ + + return (simple_open(inode, filp)); +} + +static ssize_t +fops_str_read(struct file *filp, char __user *ubuf, size_t read_size, + loff_t *ppos) +{ + ssize_t ret; + char *str, *str_with_newline; + size_t str_len, str_with_newline_len; + + if (filp->private_data == NULL) + return (-EINVAL); + + str = *(char **)filp->private_data; + str_len = strlen(str); + + /* + * `str_with_newline` is terminated with a newline, but is not + * NUL-terminated. + */ + str_with_newline_len = str_len + 1; + str_with_newline = kmalloc(str_with_newline_len, GFP_KERNEL); + if (str_with_newline == NULL) + return (-ENOMEM); + + strncpy(str_with_newline, str, str_len); + str_with_newline[str_len] = '\n'; + + ret = simple_read_from_buffer(ubuf, read_size, ppos, + str_with_newline, str_with_newline_len); + + kfree(str_with_newline); + + return (ret); +} + +static ssize_t +fops_str_write(struct file *filp, const char *buf, size_t write_size, + loff_t *ppos) +{ + char *old, *new; + size_t old_len, new_len; + + if (filp->private_data == NULL) + return (-EINVAL); + + old = *(char **)filp->private_data; + new = NULL; + + /* + * We enforce concatenation of the newly written value to the existing + * value. + */ + old_len = strlen(old); + if (*ppos && *ppos != old_len) + return (-EINVAL); + + new_len = old_len + write_size; + if (new_len + 1 > PAGE_SIZE) + return (-E2BIG); + + new = kmalloc(new_len + 1, GFP_KERNEL); + if (new == NULL) + return (-ENOMEM); + + memcpy(new, old, old_len); + if (copy_from_user(new + old_len, buf, write_size) != 0) { + kfree(new); + return (-EFAULT); + } + + new[new_len] = '\0'; + strim(new); + + filp->private_data = &new; + + kfree(old); + + return (write_size); +} + +static const struct file_operations fops_str = { + .owner = THIS_MODULE, + .open = fops_str_open, + .read = fops_str_read, + .write = fops_str_write, + .llseek = no_llseek +}; +static const struct file_operations fops_str_ro = { + .owner = THIS_MODULE, + .open = fops_str_open, + .read = fops_str_read, + .llseek = no_llseek +}; +static const struct file_operations fops_str_wo = { + .owner = THIS_MODULE, + .open = fops_str_open, + .write = fops_str_write, + .llseek = no_llseek +}; + +void +debugfs_create_str(const char *name, umode_t mode, struct dentry *parent, + char **value) +{ + debugfs_create_mode_unsafe(name, mode, parent, value, + &fops_str, &fops_str_ro, &fops_str_wo); +} + + static ssize_t fops_blob_read(struct file *filp, char __user *ubuf, size_t read_size, loff_t *ppos) { diff --git a/sys/compat/linuxkpi/common/include/linux/debugfs.h b/sys/compat/linuxkpi/common/include/linux/debugfs.h index 54145b61503e..4d146e085a7b 100644 --- a/sys/compat/linuxkpi/common/include/linux/debugfs.h +++ b/sys/compat/linuxkpi/common/include/linux/debugfs.h @@ -115,6 +115,8 @@ void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent, unsigned long *value); void debugfs_create_atomic_t(const char *name, umode_t mode, struct dentry *parent, atomic_t *value); +void debugfs_create_str(const char *name, umode_t mode, struct dentry *parent, + char **value); struct dentry *debugfs_create_blob(const char *name, umode_t mode, struct dentry *parent, struct debugfs_blob_wrapper *value); diff --git a/sys/modules/lindebugfs/Makefile b/sys/modules/lindebugfs/Makefile index dce9a2a3e955..44041011b407 100644 --- a/sys/modules/lindebugfs/Makefile +++ b/sys/modules/lindebugfs/Makefile @@ -14,6 +14,7 @@ EXPORT_SYMS+= debugfs_create_file EXPORT_SYMS+= debugfs_create_file_size EXPORT_SYMS+= debugfs_create_file_unsafe EXPORT_SYMS+= debugfs_create_mode_unsafe +EXPORT_SYMS+= debugfs_create_str EXPORT_SYMS+= debugfs_create_symlink EXPORT_SYMS+= debugfs_create_u8 EXPORT_SYMS+= debugfs_create_u16