lkml.org 
[lkml]   [2021]   [Sep]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] sysfs: Remove page boundary align limitation on sysfs_emit and sysfs_emit_at
Date
The key purpose of sysfs_emit and sysfs_emit_at is to
ensure that no overrun is done. Make them more equivalent
with scnprintf.

Signed-off-by: Lang Yu <lang.yu@amd.com>
---
fs/sysfs/file.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 9aefa7779b29..b754f2ef186f 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -732,14 +732,16 @@ EXPORT_SYMBOL_GPL(sysfs_change_owner);
int sysfs_emit(char *buf, const char *fmt, ...)
{
va_list args;
- int len;
+ int len, offset;

- if (WARN(!buf || offset_in_page(buf),
+ offset = offset_in_page(buf);
+
+ if (WARN(!buf,
"invalid sysfs_emit: buf:%p\n", buf))
return 0;

va_start(args, fmt);
- len = vscnprintf(buf, PAGE_SIZE, fmt, args);
+ len = vscnprintf(buf, PAGE_SIZE - offset, fmt, args);
va_end(args);

return len;
@@ -760,14 +762,16 @@ EXPORT_SYMBOL_GPL(sysfs_emit);
int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
{
va_list args;
- int len;
+ int len, offset;
+
+ offset = offset_in_page(buf);

- if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE,
+ if (WARN(!buf || at < 0 || at + offset >= PAGE_SIZE,
"invalid sysfs_emit_at: buf:%p at:%d\n", buf, at))
return 0;

va_start(args, fmt);
- len = vscnprintf(buf + at, PAGE_SIZE - at, fmt, args);
+ len = vscnprintf(buf + at, PAGE_SIZE - at - offset, fmt, args);
va_end(args);

return len;
--
2.25.1
\
 
 \ /
  Last update: 2021-09-08 14:09    [W:0.102 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site