public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] ubifs: prefer kstrtobool_from_user() over custom helper
@ 2026-04-02  8:13 Dmitry Antipov
  2026-04-02 11:18 ` Zhihao Cheng
  0 siblings, 1 reply; 12+ messages in thread
From: Dmitry Antipov @ 2026-04-02  8:13 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Zhihao Cheng, linux-mtd, Dmitry Antipov

Adjust 'dfs_file_write()' and 'dfs_global_file_write()' to prefer generic
'kstrtobool_from_user()' over an ad-hoc 'interpret_user_input()' helper,
thus making the latter not needed anymore.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 fs/ubifs/debug.c | 44 ++++++++++----------------------------------
 1 file changed, 10 insertions(+), 34 deletions(-)

diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 160c16aa7b6e..252cf82012cf 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -2732,39 +2732,14 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
 	return provide_user_output(val, u, count, ppos);
 }
 
-/**
- * interpret_user_input - interpret user debugfs file input.
- * @u: user-provided buffer with the input
- * @count: buffer size
- *
- * This is a helper function which interpret user input to a boolean UBIFS
- * debugfs file. Returns %0 or %1 in case of success and a negative error code
- * in case of failure.
- */
-static int interpret_user_input(const char __user *u, size_t count)
-{
-	size_t buf_size;
-	char buf[8];
-
-	buf_size = min_t(size_t, count, (sizeof(buf) - 1));
-	if (copy_from_user(buf, u, buf_size))
-		return -EFAULT;
-
-	if (buf[0] == '1')
-		return 1;
-	else if (buf[0] == '0')
-		return 0;
-
-	return -EINVAL;
-}
-
 static ssize_t dfs_file_write(struct file *file, const char __user *u,
 			      size_t count, loff_t *ppos)
 {
 	struct ubifs_info *c = file->private_data;
 	struct ubifs_debug_info *d = c->dbg;
 	struct dentry *dent = file->f_path.dentry;
-	int val;
+	bool val;
+	int ret;
 
 	if (file->f_path.dentry == d->dfs_dump_lprops) {
 		ubifs_dump_lprops(c);
@@ -2781,9 +2756,9 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u,
 		return count;
 	}
 
-	val = interpret_user_input(u, count);
-	if (val < 0)
-		return val;
+	ret = kstrtobool_from_user(u, count, &val);
+	if (unlikely(ret))
+		return ret;
 
 	if (dent == d->dfs_chk_gen)
 		d->chk_gen = val;
@@ -2926,11 +2901,12 @@ static ssize_t dfs_global_file_write(struct file *file, const char __user *u,
 				     size_t count, loff_t *ppos)
 {
 	struct dentry *dent = file->f_path.dentry;
-	int val;
+	bool val;
+	int ret;
 
-	val = interpret_user_input(u, count);
-	if (val < 0)
-		return val;
+	ret = kstrtobool_from_user(u, count, &val);
+	if (unlikely(ret))
+		return ret;
 
 	if (dent == dfs_chk_gen)
 		ubifs_dbg.chk_gen = val;
-- 
2.53.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2026-04-10  5:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02  8:13 [PATCH] ubifs: prefer kstrtobool_from_user() over custom helper Dmitry Antipov
2026-04-02 11:18 ` Zhihao Cheng
2026-04-03 16:37   ` [PATCH v2 1/2] " Dmitry Antipov
2026-04-03 16:37     ` [PATCH v2 2/2] ubifs: use strscpy() and kmemdup_nul() where appropriate Dmitry Antipov
2026-04-07  2:37       ` Zhihao Cheng
2026-04-07 16:05         ` [PATCH v3 1/2] ubifs: prefer kstrtobool_from_user() over custom helper Dmitry Antipov
2026-04-07 16:05           ` [PATCH v3 2/2] ubifs: use strscpy() and kmemdup_nul() where appropriate Dmitry Antipov
2026-04-08  6:09             ` Zhihao Cheng
2026-04-09  4:56               ` [PATCH v4 1/2] ubifs: prefer kstrtobool_from_user() over custom helper Dmitry Antipov
2026-04-09  4:56                 ` [PATCH v4 2/2] ubifs: use strscpy() and kmemdup_nul() where appropriate Dmitry Antipov
2026-04-10  1:06                   ` Zhihao Cheng
2026-04-10  5:57                     ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox