From: Yi Yang <yiyang13@huawei.com>
To: <chris@zankel.net>, <jcmvbkbc@gmail.com>, <viro@zeniv.linux.org.uk>
Cc: <linux-xtensa@linux-xtensa.org>, <linux-kernel@vger.kernel.org>,
<axboe@kernel.dk>, <wangweiyang2@huawei.com>
Subject: [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk()
Date: Tue, 10 May 2022 16:05:33 +0800 [thread overview]
Message-ID: <20220510080533.51032-1-yiyang13@huawei.com> (raw)
The frist simple_read_from_buffer() will change ppos. if ppos >= 1.
The second simple_read_from_buffer() will does not work and return 0.
Fixes: a69755b18774 ("xtensa simdisk: switch to proc_create_data()")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
arch/xtensa/platforms/iss/simdisk.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/arch/xtensa/platforms/iss/simdisk.c b/arch/xtensa/platforms/iss/simdisk.c
index 0f0e0724397f..618c080c388d 100644
--- a/arch/xtensa/platforms/iss/simdisk.c
+++ b/arch/xtensa/platforms/iss/simdisk.c
@@ -210,13 +210,21 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf,
{
struct simdisk *dev = pde_data(file_inode(file));
const char *s = dev->filename;
+ char *temp;
+
if (s) {
+ ssize_t len = strlen(s);
+
+ temp = kmalloc(len + 2, GFP_KERNEL);
+ if (!temp)
+ return -ENOMEM;
+
+ scnprintf(temp, len + 2, "%s\n", s);
ssize_t n = simple_read_from_buffer(buf, size, ppos,
- s, strlen(s));
- if (n < 0)
- return n;
- buf += n;
- size -= n;
+ temp, strlen(temp));
+
+ kfree(temp);
+ return n;
}
return simple_read_from_buffer(buf, size, ppos, "\n", 1);
}
--
2.17.1
next reply other threads:[~2022-05-10 8:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 8:05 Yi Yang [this message]
2022-05-10 13:43 ` kernel test robot
2022-05-11 9:04 ` Max Filippov
2022-05-11 9:45 ` yiyang (D)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220510080533.51032-1-yiyang13@huawei.com \
--to=yiyang13@huawei.com \
--cc=axboe@kernel.dk \
--cc=chris@zankel.net \
--cc=jcmvbkbc@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=viro@zeniv.linux.org.uk \
--cc=wangweiyang2@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®