From nobody Thu Aug 01 22:27:54 2024 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 4WZkB35YxFz5RZbw; Thu, 01 Aug 2024 22:27: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WZkB275Pwz4ZTS; Thu, 1 Aug 2024 22:27:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722551275; 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=BA9O7DeYyNxY7oGZOzwbtJznsz5Y+6X8QkULG16IYSE=; b=u4omA2FfGkoI/ISCk3oGWJgynPodEG7CCDGSEAl9tLHIBlW1MmtJfm5KCL4n2S3cuGaMId poAzJW5uxCjA6fHoutbTvCSql8b7uVIAhHJQw9l4mn/XJ6/3JOZnW4AMF5Nh65F8WwatJi G6JSzF+u6nFKTld85iqwkTOXhmal2qN7KNWXENxXRrcw1Dbnm4vGZtx6KjavlSh2oYQOr7 bX0OgE0xHLZVtd06/yju1mfDe+F9gzqo53LHnNgUxjXsZboEOkafNGYZiVzISqbguXK/mM IUWLjVLTZfr8CT6UvN8q4rySTI3PxSX/Iv5YGXZUmgfZNhelaYLKRruUarAozg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722551275; a=rsa-sha256; cv=none; b=MRmsJLkeTnGS3BqLk3+0iQpRXT4s82XLirGWpjwtUhhldZEFq4/quDiwHZT+jhA9KHfBgT 0gju3Bl4nVNxLtlLe0Wb1MxRcVAgqGO2EUU63dp7hzPNcYykGkJCAkvKKr36GKTOfQDC90 s3ucogVZIcavtYl+pSAJhidAXbJzq1pFFPuM8VH/UXym81QwdyEkzncf+i+09/65ikze2H 6CsMOBQTKbR5kdiM3LhpJNYXMHjKolysQb/8zeQgtUvLgBQr3u2JPyF4KjV+uC7cv3Vhxd 2ZkCCKFmI8wpWQwQDaLZeXiPrKLGODjDPh1wVZI5Zm3PYOa/jwS6rva4pobAmg== 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=1722551275; 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=BA9O7DeYyNxY7oGZOzwbtJznsz5Y+6X8QkULG16IYSE=; b=GoTVR2eMeYz7E1kVCqsmUU9VW9YlHq6wi4GWfymh3/AB/bM4EX4KzNhoX3x5WpFb8yaw8/ zpmqdCFFzos+wsujD6WoxfINoqMx/e4/J09UhDv6SbFjSJ39wXrhEefnKFsNz0dmIB4Ia9 hexB78qeTAYXIlXRzoYen8ONEgS9z04sP3MO2osY9y24IFR7ip8+msHqZR9C7nH3Csyz8d ZLTFWK+FyvTrfFSk9JnQOpzH82ddRgpxeFdKzQKP+ts6pq5Zfq7aUAi4kdYzctldAUCBWG xpcQGj0ShGz+Jh9z7h1AZ0tVsGIjRDdiPYeS0JnEe2aKHXjljUby4sAUMNPuwA== 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 4WZkB26jZJz12l9; Thu, 1 Aug 2024 22:27:54 +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 471MRsuu028275; Thu, 1 Aug 2024 22:27:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 471MRsQG028272; Thu, 1 Aug 2024 22:27:54 GMT (envelope-from git) Date: Thu, 1 Aug 2024 22:27:54 GMT Message-Id: <202408012227.471MRsQG028272@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 88ca9c822616 - stable/14 - LinuxKPI: Add DEFINE_DEBUGFS_ATTRIBUTE_SIGNED to linux/debugfs.h 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: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 88ca9c8226165e31991c25a246d825706c8ec2e7 Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=88ca9c8226165e31991c25a246d825706c8ec2e7 commit 88ca9c8226165e31991c25a246d825706c8ec2e7 Author: Vladimir Kondratyev AuthorDate: 2024-06-26 20:51:34 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-08-01 21:09:41 +0000 LinuxKPI: Add DEFINE_DEBUGFS_ATTRIBUTE_SIGNED to linux/debugfs.h Sponsored by: Serenity CyberSecurity, LLC MFC after: 1 week Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D45615 (cherry picked from commit 8c5c572125665e3fd8a033d1a8b0a370e5a43e24) --- sys/compat/linuxkpi/common/include/linux/debugfs.h | 2 ++ sys/compat/linuxkpi/common/include/linux/fs.h | 12 ++++++++-- sys/compat/linuxkpi/common/src/linux_simple_attr.c | 27 ++++++++++++++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/debugfs.h b/sys/compat/linuxkpi/common/include/linux/debugfs.h index 470b50cb730c..13186334d75c 100644 --- a/sys/compat/linuxkpi/common/include/linux/debugfs.h +++ b/sys/compat/linuxkpi/common/include/linux/debugfs.h @@ -88,6 +88,8 @@ void debugfs_remove_recursive(struct dentry *dentry); #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) +#define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \ + DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent, bool *value); diff --git a/sys/compat/linuxkpi/common/include/linux/fs.h b/sys/compat/linuxkpi/common/include/linux/fs.h index ebe262926e97..74288f9cd461 100644 --- a/sys/compat/linuxkpi/common/include/linux/fs.h +++ b/sys/compat/linuxkpi/common/include/linux/fs.h @@ -375,7 +375,7 @@ simple_read_from_buffer(void __user *dest, size_t read_size, loff_t *ppos, MALLOC_DECLARE(M_LSATTR); -#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ +#define __DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt, __wrfunc)\ static inline int \ __fops ## _open(struct inode *inode, struct file *filp) \ { \ @@ -386,10 +386,15 @@ static const struct file_operations __fops = { \ .open = __fops ## _open, \ .release = simple_attr_release, \ .read = simple_attr_read, \ - .write = simple_attr_write, \ + .write = __wrfunc, \ .llseek = no_llseek \ } +#define DEFINE_SIMPLE_ATTRIBUTE(fops, get, set, fmt) \ + __DEFINE_SIMPLE_ATTRIBUTE(fops, get, set, fmt, simple_attr_write) +#define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(fops, get, set, fmt) \ + __DEFINE_SIMPLE_ATTRIBUTE(fops, get, set, fmt, simple_attr_write_signed) + int simple_attr_open(struct inode *inode, struct file *filp, int (*get)(void *, uint64_t *), int (*set)(void *, uint64_t), const char *fmt); @@ -400,4 +405,7 @@ ssize_t simple_attr_read(struct file *filp, char *buf, size_t read_size, loff_t ssize_t simple_attr_write(struct file *filp, const char *buf, size_t write_size, loff_t *ppos); +ssize_t simple_attr_write_signed(struct file *filp, const char *buf, + size_t write_size, loff_t *ppos); + #endif /* _LINUXKPI_LINUX_FS_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_simple_attr.c b/sys/compat/linuxkpi/common/src/linux_simple_attr.c index 27dc7beb8707..ecd1e135026c 100644 --- a/sys/compat/linuxkpi/common/src/linux_simple_attr.c +++ b/sys/compat/linuxkpi/common/src/linux_simple_attr.c @@ -139,12 +139,13 @@ unlock: } /* - * simple_attr_write: write contents of buffer into simple attribute file + * simple_attr_write_common: write contents of buffer into simple attribute file * * @filp: file pointer * @buf: kernel space buffer * @write_size: number bytes to be transferred * @ppos: starting pointer position for transfer + * @is_signed: signedness of data in @buf * * The simple_attr structure is stored in filp->private_data. * Convert the @buf string to unsigned long long. @@ -154,8 +155,9 @@ unlock: * On success, number of bytes written to simple attr * On failure, negative signed ERRNO */ -ssize_t -simple_attr_write(struct file *filp, const char *buf, size_t write_size, loff_t *ppos) +static ssize_t +simple_attr_write_common(struct file *filp, const char *buf, size_t write_size, + loff_t *ppos, bool is_signed) { struct simple_attr *sattr; unsigned long long data; @@ -173,7 +175,10 @@ simple_attr_write(struct file *filp, const char *buf, size_t write_size, loff_t mutex_lock(&sattr->mutex); - ret = kstrtoull(buf + *ppos, 0, &data); + if (is_signed) + ret = kstrtoll(buf + *ppos, 0, &data); + else + ret = kstrtoull(buf + *ppos, 0, &data); if (ret) goto unlock; @@ -187,3 +192,17 @@ unlock: mutex_unlock(&sattr->mutex); return (ret); } + +ssize_t +simple_attr_write(struct file *filp, const char *buf, size_t write_size, + loff_t *ppos) +{ + return (simple_attr_write_common(filp, buf, write_size, ppos, false)); +} + +ssize_t +simple_attr_write_signed(struct file *filp, const char *buf, size_t write_size, + loff_t *ppos) +{ + return (simple_attr_write_common(filp, buf, write_size, ppos, true)); +}