From bfc740938d151001cb1158580796f8f3be3bf0c1 Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Fri, 14 Jul 2017 14:49:54 -0700 Subject: fault-inject: make fail-nth read/write interface symmetric The read interface for fail-nth looks a bit odd. Read from this file returns "NYYYY..." or "YYYYY..." (this makes me surprise when cat this file). Because there is no EOF condition. The first character indicates current->fail_nth is zero or not, and then current->fail_nth is reset to zero. Just returning task->fail_nth value is more natural to understand. Link: http://lkml.kernel.org/r/1491490561-10485-4-git-send-email-akinobu.mita@gmail.com Signed-off-by: Akinobu Mita Cc: Dmitry Vyukov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/proc/base.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'fs/proc') diff --git a/fs/proc/base.c b/fs/proc/base.c index c1fdaecb8d23..7d795d28dd02 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1380,7 +1380,8 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { struct task_struct *task; - int err; + char numbuf[PROC_NUMBUF]; + ssize_t len; task = get_proc_task(file_inode(file)); if (!task) @@ -1388,13 +1389,10 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf, put_task_struct(task); if (task != current) return -EPERM; - if (count < 1) - return -EINVAL; - err = put_user((char)(current->fail_nth ? 'N' : 'Y'), buf); - if (err) - return err; - current->fail_nth = 0; - return 1; + len = snprintf(numbuf, sizeof(numbuf), "%u\n", task->fail_nth); + len = simple_read_from_buffer(buf, count, ppos, numbuf, len); + + return len; } static const struct file_operations proc_fail_nth_operations = { -- cgit v1.2.3-58-ga151