From nobody Wed Jun 26 20:54:47 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 4W8YqD26D6z5QD7G; Wed, 26 Jun 2024 20:54: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W8YqC5Ngnz4M28; Wed, 26 Jun 2024 20:54:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719435287; 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=qBsChlI55FNeNvPTYQfNFcsWgv+9YPNoTfyLhp8exWs=; b=JbpXGfKn7OqcCwzfCyBs03d9HNVuGEozyCyIGs8PfTMx4kNiKcPTu+elMydpWHYyMOM5Li qHcw+NKt0rUj2bSlX3yvUPu//l+pDZHphDDHysAB/kUzE24rFPvs++UzxEaE4a0+PEdhvX qjflRp1r8GF1oKLoh8x6w05GT19T2WXRjF5pp4THvg84KjZyezAmaoPheV+x9SLAFwDnuB Aect6H7etR50JnYPqikM9tM6sq2qelbQvBsM0eivMV/baUQ++G3gwqfcL3tSocma6RegvK QYbYl28XyBJ+o/mwQ/g9my8dTuCuiUFZ8RbgAhYx9WTO1JKvz9U/yCzQvrycUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1719435287; a=rsa-sha256; cv=none; b=JW6zfkzEE7/ZUQBVM3hoQHdvw95qAZDAgzy4BQ11eWHNg/kjnVH8g/ejmT73VKIq6BjY70 YBgyNxdR8OQvD3zvWBvcEwrKQgBY3eZYqV8JBGNYZ7JC6hCAD+PlDPsZfi+UJJTHFPhy66 C+xE8TasSOa/UOuv86j5Ci+zjPfCvNRnCW9+BLuUs+/aMFQ+Ot8Tn0hKzX4rFzzGSBmnvT XhGttC8jTPFAAaHs/muqzZuPFrRrN2zRwln9liBUVChHWxX3oGfPSzdw3uBZ7TmtnMFGZ2 ehusYdrJhPdM4OJebqeEv4hLm+RVYKSu98GJdNIHBVTn/KQlejMlYsPSlNKerQ== 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=1719435287; 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=qBsChlI55FNeNvPTYQfNFcsWgv+9YPNoTfyLhp8exWs=; b=gAKz7QVm8Jmk3m1dXi8FguAC4i3TP/xBxuyPMjx9xIG2ub7AFmcQgTkBg74HMKezHEAba4 kDQXY3E9PqGtO79sk2+JvK2MebrJ1G8ZO8Lt3OuUtgdYGbvximlLDhzm9SemmeOVAv7afs 14mbQdR687qNfxoAq43nG+oR0a5GHrqVLQN/dk3irihWVE8n0gK6B8HVsngkpDudlD2Pdc 5rdKX/LhJ4Rn4XX6wHz4GSq4nvejALZDFyOWUvwvfVdEsnq9oZHFP2NRIAiUzFuA8ASrMx v5MHk6OnSSYri5XuYHJ22ye8I2XUAyGDwBfTnaS0Sz0WrzooGC6FzYhgbxP5Rg== 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 4W8YqC3yMFz10HW; Wed, 26 Jun 2024 20:54:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45QKslaj092669; Wed, 26 Jun 2024 20:54:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45QKslsm092666; Wed, 26 Jun 2024 20:54:47 GMT (envelope-from git) Date: Wed, 26 Jun 2024 20:54:47 GMT Message-Id: <202406262054.45QKslsm092666@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 8c5c57212566 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 8c5c572125665e3fd8a033d1a8b0a370e5a43e24 Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=8c5c572125665e3fd8a033d1a8b0a370e5a43e24 commit 8c5c572125665e3fd8a033d1a8b0a370e5a43e24 Author: Vladimir Kondratyev AuthorDate: 2024-06-26 20:51:34 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-06-26 20:51:34 +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 --- 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 a28d5bf97121..9c763168b0f4 100644 --- a/sys/compat/linuxkpi/common/include/linux/fs.h +++ b/sys/compat/linuxkpi/common/include/linux/fs.h @@ -374,7 +374,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) \ { \ @@ -385,10 +385,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); @@ -399,4 +404,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 1bdacd7c1491..8cc9ec7ecbc9 100644 --- a/sys/compat/linuxkpi/common/src/linux_simple_attr.c +++ b/sys/compat/linuxkpi/common/src/linux_simple_attr.c @@ -138,12 +138,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. @@ -153,8 +154,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; @@ -172,7 +174,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; @@ -186,3 +191,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)); +}