linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] fix error when writing negative value to simple attribute files
@ 2022-09-19 17:24 Akinobu Mita
  2022-09-19 17:24 ` [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value Akinobu Mita
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Akinobu Mita @ 2022-09-19 17:24 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, david, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alexander Viro, akpm
  Cc: Akinobu Mita

The simple attribute files do not accept a negative value since the
commit 488dac0c9237 ("libfs: fix error cast of negative value in
simple_attr_write()"), but some attribute files want to accept
a negative value.

Akinobu Mita (3):
  libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value
  lib/notifier-error-inject: fix error when writing -errno to debugfs
    file
  debugfs: fix error when writing negative value to atomic_t debugfs
    file

 .../fault-injection/fault-injection.rst       | 10 +++----
 fs/debugfs/file.c                             | 28 +++++++++++++++----
 fs/libfs.c                                    | 22 +++++++++++++--
 include/linux/debugfs.h                       | 19 +++++++++++--
 include/linux/fs.h                            | 12 ++++++--
 lib/notifier-error-inject.c                   |  2 +-
 6 files changed, 73 insertions(+), 20 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value
  2022-09-19 17:24 [PATCH 0/3] fix error when writing negative value to simple attribute files Akinobu Mita
@ 2022-09-19 17:24 ` Akinobu Mita
  2022-09-20  8:14   ` David Hildenbrand
  2022-09-19 17:24 ` [PATCH 2/3] lib/notifier-error-inject: fix error when writing -errno to debugfs file Akinobu Mita
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Akinobu Mita @ 2022-09-19 17:24 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, david, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alexander Viro, akpm
  Cc: Akinobu Mita

The simple attribute files do not accept a negative value since the
commit 488dac0c9237 ("libfs: fix error cast of negative value in
simple_attr_write()"), so we have to use a 64-bit value to write a
negative value.

This adds DEFINE_SIMPLE_ATTRIBUTE_SIGNED for a signed value.

Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
Reported-by: Zhao Gongyi <zhaogongyi@huawei.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 fs/libfs.c         | 22 +++++++++++++++++++---
 include/linux/fs.h | 12 ++++++++++--
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/fs/libfs.c b/fs/libfs.c
index 31b0ddf01c31..76fb29a103a2 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -994,8 +994,8 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
 EXPORT_SYMBOL_GPL(simple_attr_read);
 
 /* interpret the buffer as a number to call the set function with */
-ssize_t simple_attr_write(struct file *file, const char __user *buf,
-			  size_t len, loff_t *ppos)
+static ssize_t simple_attr_write_xsigned(struct file *file, const char __user *buf,
+			  size_t len, loff_t *ppos, bool is_signed)
 {
 	struct simple_attr *attr;
 	unsigned long long val;
@@ -1016,7 +1016,10 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
 		goto out;
 
 	attr->set_buf[size] = '\0';
-	ret = kstrtoull(attr->set_buf, 0, &val);
+	if (is_signed)
+		ret = kstrtoll(attr->set_buf, 0, &val);
+	else
+		ret = kstrtoull(attr->set_buf, 0, &val);
 	if (ret)
 		goto out;
 	ret = attr->set(attr->data, val);
@@ -1026,8 +1029,21 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
 	mutex_unlock(&attr->mutex);
 	return ret;
 }
+
+ssize_t simple_attr_write(struct file *file, const char __user *buf,
+			  size_t len, loff_t *ppos)
+{
+	return simple_attr_write_xsigned(file, buf, len, ppos, false);
+}
 EXPORT_SYMBOL_GPL(simple_attr_write);
 
+ssize_t simple_attr_write_signed(struct file *file, const char __user *buf,
+			  size_t len, loff_t *ppos)
+{
+	return simple_attr_write_xsigned(file, buf, len, ppos, true);
+}
+EXPORT_SYMBOL_GPL(simple_attr_write_signed);
+
 /**
  * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation
  * @sb:		filesystem to do the file handle conversion on
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 9eced4cc286e..c79138818922 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3471,7 +3471,7 @@ void simple_transaction_set(struct file *file, size_t n);
  * All attributes contain a text representation of a numeric value
  * that are accessed with the get() and set() functions.
  */
-#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt)		\
+#define DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed)	\
 static int __fops ## _open(struct inode *inode, struct file *file)	\
 {									\
 	__simple_attr_check_format(__fmt, 0ull);			\
@@ -3482,10 +3482,16 @@ static const struct file_operations __fops = {				\
 	.open	 = __fops ## _open,					\
 	.release = simple_attr_release,					\
 	.read	 = simple_attr_read,					\
-	.write	 = simple_attr_write,					\
+	.write	 = (__is_signed) ? simple_attr_write_signed : simple_attr_write,	\
 	.llseek	 = generic_file_llseek,					\
 }
 
+#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt)		\
+	DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false)
+
+#define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt)	\
+	DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true)
+
 static inline __printf(1, 2)
 void __simple_attr_check_format(const char *fmt, ...)
 {
@@ -3500,6 +3506,8 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
 			 size_t len, loff_t *ppos);
 ssize_t simple_attr_write(struct file *file, const char __user *buf,
 			  size_t len, loff_t *ppos);
+ssize_t simple_attr_write_signed(struct file *file, const char __user *buf,
+				 size_t len, loff_t *ppos);
 
 struct ctl_table;
 int __init list_bdev_fs_names(char *buf, size_t size);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] lib/notifier-error-inject: fix error when writing -errno to debugfs file
  2022-09-19 17:24 [PATCH 0/3] fix error when writing negative value to simple attribute files Akinobu Mita
  2022-09-19 17:24 ` [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value Akinobu Mita
@ 2022-09-19 17:24 ` Akinobu Mita
  2022-09-20  8:15   ` David Hildenbrand
  2022-09-19 17:24 ` [PATCH 3/3] debugfs: fix error when writing negative value to atomic_t " Akinobu Mita
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Akinobu Mita @ 2022-09-19 17:24 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, david, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alexander Viro, akpm
  Cc: Akinobu Mita

The simple attribute files do not accept a negative value since the
commit 488dac0c9237 ("libfs: fix error cast of negative value in
simple_attr_write()").

This restores the previous behaviour by using newly introduced
DEFINE_SIMPLE_ATTRIBUTE_SIGNED instead of DEFINE_SIMPLE_ATTRIBUTE.

Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
Reported-by: Zhao Gongyi <zhaogongyi@huawei.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 lib/notifier-error-inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c
index 21016b32d313..2b24ea6c9497 100644
--- a/lib/notifier-error-inject.c
+++ b/lib/notifier-error-inject.c
@@ -15,7 +15,7 @@ static int debugfs_errno_get(void *data, u64 *val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(fops_errno, debugfs_errno_get, debugfs_errno_set,
+DEFINE_SIMPLE_ATTRIBUTE_SIGNED(fops_errno, debugfs_errno_get, debugfs_errno_set,
 			"%lld\n");
 
 static struct dentry *debugfs_create_errno(const char *name, umode_t mode,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] debugfs: fix error when writing negative value to atomic_t debugfs file
  2022-09-19 17:24 [PATCH 0/3] fix error when writing negative value to simple attribute files Akinobu Mita
  2022-09-19 17:24 ` [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value Akinobu Mita
  2022-09-19 17:24 ` [PATCH 2/3] lib/notifier-error-inject: fix error when writing -errno to debugfs file Akinobu Mita
@ 2022-09-19 17:24 ` Akinobu Mita
  2022-09-20  8:19   ` David Hildenbrand
  2022-09-20  7:47 ` [PATCH 0/3] fix error when writing negative value to simple attribute files Greg Kroah-Hartman
  2022-09-22  8:06 ` Zhao Gongyi
  4 siblings, 1 reply; 9+ messages in thread
From: Akinobu Mita @ 2022-09-19 17:24 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, david, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alexander Viro, akpm
  Cc: Akinobu Mita

The simple attribute files do not accept a negative value since the
commit 488dac0c9237 ("libfs: fix error cast of negative value in
simple_attr_write()"), so we have to use a 64-bit value to write a
negative value for a debugfs file created by debugfs_create_atomic_t().

This restores the previous behaviour by introducing
DEFINE_DEBUGFS_ATTRIBUTE_SIGNED for a signed value.

Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
Reported-by: Zhao Gongyi <zhaogongyi@huawei.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 .../fault-injection/fault-injection.rst       | 10 +++----
 fs/debugfs/file.c                             | 28 +++++++++++++++----
 include/linux/debugfs.h                       | 19 +++++++++++--
 3 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/Documentation/fault-injection/fault-injection.rst b/Documentation/fault-injection/fault-injection.rst
index 17779a2772e5..5f6454b9dbd4 100644
--- a/Documentation/fault-injection/fault-injection.rst
+++ b/Documentation/fault-injection/fault-injection.rst
@@ -83,9 +83,7 @@ configuration of fault-injection capabilities.
 - /sys/kernel/debug/fail*/times:
 
 	specifies how many times failures may happen at most. A value of -1
-	means "no limit". Note, though, that this file only accepts unsigned
-	values. So, if you want to specify -1, you better use 'printf' instead
-	of 'echo', e.g.: $ printf %#x -1 > times
+	means "no limit".
 
 - /sys/kernel/debug/fail*/space:
 
@@ -284,7 +282,7 @@ Application Examples
     echo Y > /sys/kernel/debug/$FAILTYPE/task-filter
     echo 10 > /sys/kernel/debug/$FAILTYPE/probability
     echo 100 > /sys/kernel/debug/$FAILTYPE/interval
-    printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times
+    echo -1 > /sys/kernel/debug/$FAILTYPE/times
     echo 0 > /sys/kernel/debug/$FAILTYPE/space
     echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
     echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait
@@ -338,7 +336,7 @@ Application Examples
     echo N > /sys/kernel/debug/$FAILTYPE/task-filter
     echo 10 > /sys/kernel/debug/$FAILTYPE/probability
     echo 100 > /sys/kernel/debug/$FAILTYPE/interval
-    printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times
+    echo -1 > /sys/kernel/debug/$FAILTYPE/times
     echo 0 > /sys/kernel/debug/$FAILTYPE/space
     echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
     echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait
@@ -369,7 +367,7 @@ Application Examples
     echo N > /sys/kernel/debug/$FAILTYPE/task-filter
     echo 100 > /sys/kernel/debug/$FAILTYPE/probability
     echo 0 > /sys/kernel/debug/$FAILTYPE/interval
-    printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times
+    echo -1 > /sys/kernel/debug/$FAILTYPE/times
     echo 0 > /sys/kernel/debug/$FAILTYPE/space
     echo 1 > /sys/kernel/debug/$FAILTYPE/verbose
 
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 950c63fa4d0b..38930d9b0bb7 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -378,8 +378,8 @@ ssize_t debugfs_attr_read(struct file *file, char __user *buf,
 }
 EXPORT_SYMBOL_GPL(debugfs_attr_read);
 
-ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
-			 size_t len, loff_t *ppos)
+static ssize_t debugfs_attr_write_xsigned(struct file *file, const char __user *buf,
+			 size_t len, loff_t *ppos, bool is_signed)
 {
 	struct dentry *dentry = F_DENTRY(file);
 	ssize_t ret;
@@ -387,12 +387,28 @@ ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
 	ret = debugfs_file_get(dentry);
 	if (unlikely(ret))
 		return ret;
-	ret = simple_attr_write(file, buf, len, ppos);
+	if (is_signed)
+		ret = simple_attr_write_signed(file, buf, len, ppos);
+	else
+		ret = simple_attr_write(file, buf, len, ppos);
 	debugfs_file_put(dentry);
 	return ret;
 }
+
+ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
+			 size_t len, loff_t *ppos)
+{
+	return debugfs_attr_write_xsigned(file, buf, len, ppos, false);
+}
 EXPORT_SYMBOL_GPL(debugfs_attr_write);
 
+ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf,
+			 size_t len, loff_t *ppos)
+{
+	return debugfs_attr_write_xsigned(file, buf, len, ppos, true);
+}
+EXPORT_SYMBOL_GPL(debugfs_attr_write_signed);
+
 static struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode,
 					struct dentry *parent, void *value,
 					const struct file_operations *fops,
@@ -738,11 +754,11 @@ static int debugfs_atomic_t_get(void *data, u64 *val)
 	*val = atomic_read((atomic_t *)data);
 	return 0;
 }
-DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
+DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t, debugfs_atomic_t_get,
 			debugfs_atomic_t_set, "%lld\n");
-DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL,
+DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t_ro, debugfs_atomic_t_get, NULL,
 			"%lld\n");
-DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set,
+DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t_wo, NULL, debugfs_atomic_t_set,
 			"%lld\n");
 
 /**
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index f60674692d36..ea2d919fd9c7 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -45,7 +45,7 @@ struct debugfs_u32_array {
 
 extern struct dentry *arch_debugfs_dir;
 
-#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt)		\
+#define DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed)	\
 static int __fops ## _open(struct inode *inode, struct file *file)	\
 {									\
 	__simple_attr_check_format(__fmt, 0ull);			\
@@ -56,10 +56,16 @@ static const struct file_operations __fops = {				\
 	.open	 = __fops ## _open,					\
 	.release = simple_attr_release,					\
 	.read	 = debugfs_attr_read,					\
-	.write	 = debugfs_attr_write,					\
+	.write	 = (__is_signed) ? debugfs_attr_write_signed : debugfs_attr_write,	\
 	.llseek  = no_llseek,						\
 }
 
+#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt)		\
+	DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false)
+
+#define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt)	\
+	DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true)
+
 typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
 
 #if defined(CONFIG_DEBUG_FS)
@@ -102,6 +108,8 @@ ssize_t debugfs_attr_read(struct file *file, char __user *buf,
 			size_t len, loff_t *ppos);
 ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
 			size_t len, loff_t *ppos);
+ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf,
+			size_t len, loff_t *ppos);
 
 struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
                 struct dentry *new_dir, const char *new_name);
@@ -254,6 +262,13 @@ static inline ssize_t debugfs_attr_write(struct file *file,
 	return -ENODEV;
 }
 
+static inline ssize_t debugfs_attr_write_signed(struct file *file,
+					const char __user *buf,
+					size_t len, loff_t *ppos)
+{
+	return -ENODEV;
+}
+
 static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
                 struct dentry *new_dir, char *new_name)
 {
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] fix error when writing negative value to simple attribute files
  2022-09-19 17:24 [PATCH 0/3] fix error when writing negative value to simple attribute files Akinobu Mita
                   ` (2 preceding siblings ...)
  2022-09-19 17:24 ` [PATCH 3/3] debugfs: fix error when writing negative value to atomic_t " Akinobu Mita
@ 2022-09-20  7:47 ` Greg Kroah-Hartman
  2022-09-22  8:06 ` Zhao Gongyi
  4 siblings, 0 replies; 9+ messages in thread
From: Greg Kroah-Hartman @ 2022-09-20  7:47 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, david, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Rafael J. Wysocki, Alexander Viro,
	akpm

On Tue, Sep 20, 2022 at 02:24:15AM +0900, Akinobu Mita wrote:
> The simple attribute files do not accept a negative value since the
> commit 488dac0c9237 ("libfs: fix error cast of negative value in
> simple_attr_write()"), but some attribute files want to accept
> a negative value.
> 
> Akinobu Mita (3):
>   libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value
>   lib/notifier-error-inject: fix error when writing -errno to debugfs
>     file
>   debugfs: fix error when writing negative value to atomic_t debugfs
>     file
> 
>  .../fault-injection/fault-injection.rst       | 10 +++----
>  fs/debugfs/file.c                             | 28 +++++++++++++++----
>  fs/libfs.c                                    | 22 +++++++++++++--
>  include/linux/debugfs.h                       | 19 +++++++++++--
>  include/linux/fs.h                            | 12 ++++++--
>  lib/notifier-error-inject.c                   |  2 +-
>  6 files changed, 73 insertions(+), 20 deletions(-)

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value
  2022-09-19 17:24 ` [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value Akinobu Mita
@ 2022-09-20  8:14   ` David Hildenbrand
  0 siblings, 0 replies; 9+ messages in thread
From: David Hildenbrand @ 2022-09-20  8:14 UTC (permalink / raw)
  To: Akinobu Mita, linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alexander Viro, akpm

On 19.09.22 19:24, Akinobu Mita wrote:
> The simple attribute files do not accept a negative value since the
> commit 488dac0c9237 ("libfs: fix error cast of negative value in
> simple_attr_write()"), so we have to use a 64-bit value to write a
> negative value.
> 
> This adds DEFINE_SIMPLE_ATTRIBUTE_SIGNED for a signed value.
> 
> Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")

This patch itself isn't a fix. The fixes tags belong to the other 
patches that make use of this.

> Reported-by: Zhao Gongyi <zhaogongyi@huawei.com>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] lib/notifier-error-inject: fix error when writing -errno to debugfs file
  2022-09-19 17:24 ` [PATCH 2/3] lib/notifier-error-inject: fix error when writing -errno to debugfs file Akinobu Mita
@ 2022-09-20  8:15   ` David Hildenbrand
  0 siblings, 0 replies; 9+ messages in thread
From: David Hildenbrand @ 2022-09-20  8:15 UTC (permalink / raw)
  To: Akinobu Mita, linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alexander Viro, akpm

On 19.09.22 19:24, Akinobu Mita wrote:
> The simple attribute files do not accept a negative value since the
> commit 488dac0c9237 ("libfs: fix error cast of negative value in
> simple_attr_write()").
> 
> This restores the previous behaviour by using newly introduced
> DEFINE_SIMPLE_ATTRIBUTE_SIGNED instead of DEFINE_SIMPLE_ATTRIBUTE.
> 
> Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
> Reported-by: Zhao Gongyi <zhaogongyi@huawei.com>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---
>   lib/notifier-error-inject.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c
> index 21016b32d313..2b24ea6c9497 100644
> --- a/lib/notifier-error-inject.c
> +++ b/lib/notifier-error-inject.c
> @@ -15,7 +15,7 @@ static int debugfs_errno_get(void *data, u64 *val)
>   	return 0;
>   }
>   
> -DEFINE_SIMPLE_ATTRIBUTE(fops_errno, debugfs_errno_get, debugfs_errno_set,
> +DEFINE_SIMPLE_ATTRIBUTE_SIGNED(fops_errno, debugfs_errno_get, debugfs_errno_set,
>   			"%lld\n");
>   
>   static struct dentry *debugfs_create_errno(const char *name, umode_t mode,

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] debugfs: fix error when writing negative value to atomic_t debugfs file
  2022-09-19 17:24 ` [PATCH 3/3] debugfs: fix error when writing negative value to atomic_t " Akinobu Mita
@ 2022-09-20  8:19   ` David Hildenbrand
  0 siblings, 0 replies; 9+ messages in thread
From: David Hildenbrand @ 2022-09-20  8:19 UTC (permalink / raw)
  To: Akinobu Mita, linux-doc, linux-kernel, linux-mm, linux-kselftest,
	linux-fsdevel, corbet, osalvador, shuah, Zhao Gongyi,
	Wei Yongjun, Yicong Yang, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alexander Viro, akpm

On 19.09.22 19:24, Akinobu Mita wrote:
> The simple attribute files do not accept a negative value since the
> commit 488dac0c9237 ("libfs: fix error cast of negative value in
> simple_attr_write()"), so we have to use a 64-bit value to write a
> negative value for a debugfs file created by debugfs_create_atomic_t().

Is that comment stale?

I would ahve thought you simply document that we restore the original 
behavior essentially by reverting 005747526d4f ("docs: fault-injection: 
fix non-working usage of negative values") and the using 
DEFINE_DEBUGFS_ATTRIBUTE_SIGNED accordingly.

> 
> This restores the previous behaviour by introducing
> DEFINE_DEBUGFS_ATTRIBUTE_SIGNED for a signed value.
> 
> Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
> Reported-by: Zhao Gongyi <zhaogongyi@huawei.com>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>


Apart from that

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] fix error when writing negative value to simple attribute files
  2022-09-19 17:24 [PATCH 0/3] fix error when writing negative value to simple attribute files Akinobu Mita
                   ` (3 preceding siblings ...)
  2022-09-20  7:47 ` [PATCH 0/3] fix error when writing negative value to simple attribute files Greg Kroah-Hartman
@ 2022-09-22  8:06 ` Zhao Gongyi
  4 siblings, 0 replies; 9+ messages in thread
From: Zhao Gongyi @ 2022-09-22  8:06 UTC (permalink / raw)
  To: akinobu.mita
  Cc: akpm, corbet, david, gregkh, linux-doc, linux-fsdevel,
	linux-kernel, linux-kselftest, linux-mm, osalvador, rafael,
	shuah, viro, weiyongjun1, yangyicong, zhaogongyi

On Tue, 20 Sep 2022 02:24:15 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:
> The simple attribute files do not accept a negative value since the
> commit 488dac0c9237 ("libfs: fix error cast of negative value in
> simple_attr_write()"), but some attribute files want to accept
> a negative value.
> 
> Akinobu Mita (3):
>   libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value
>   lib/notifier-error-inject: fix error when writing -errno to debugfs
>     file
>   debugfs: fix error when writing negative value to atomic_t debugfs
>     file
> 
>  .../fault-injection/fault-injection.rst       | 10 +++----
>  fs/debugfs/file.c                             | 28 +++++++++++++++----
>  fs/libfs.c                                    | 22 +++++++++++++--
>  include/linux/debugfs.h                       | 19 +++++++++++--
>  include/linux/fs.h                            | 12 ++++++--
>  lib/notifier-error-inject.c                   |  2 +-
>  6 files changed, 73 insertions(+), 20 deletions(-)

I have tested this version, it is ok.

Tested-by: Zhao Gongyi <zhaogongyi@huawei.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-09-22  8:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19 17:24 [PATCH 0/3] fix error when writing negative value to simple attribute files Akinobu Mita
2022-09-19 17:24 ` [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value Akinobu Mita
2022-09-20  8:14   ` David Hildenbrand
2022-09-19 17:24 ` [PATCH 2/3] lib/notifier-error-inject: fix error when writing -errno to debugfs file Akinobu Mita
2022-09-20  8:15   ` David Hildenbrand
2022-09-19 17:24 ` [PATCH 3/3] debugfs: fix error when writing negative value to atomic_t " Akinobu Mita
2022-09-20  8:19   ` David Hildenbrand
2022-09-20  7:47 ` [PATCH 0/3] fix error when writing negative value to simple attribute files Greg Kroah-Hartman
2022-09-22  8:06 ` Zhao Gongyi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).