Skip to content

Commit 17d0774

Browse files
koct9igregkh
authored andcommitted
sysfs: correctly handle read offset on PREALLOC attrs
Attributes declared with __ATTR_PREALLOC use sysfs_kf_read() which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where /bin/sh is 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from /sys/block/$dev/md/sync_action and as a result does nothing. This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head. Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Fixes: 4ef67a8 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 Cc: Stable <stable@vger.kernel.org> # v3.19+ Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 96b0af4 commit 17d0774

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/sysfs/file.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,
114114
* If buf != of->prealloc_buf, we don't know how
115115
* large it is, so cannot safely pass it to ->show
116116
*/
117-
if (pos || WARN_ON_ONCE(buf != of->prealloc_buf))
117+
if (WARN_ON_ONCE(buf != of->prealloc_buf))
118118
return 0;
119119
len = ops->show(kobj, of->kn->priv, buf);
120+
if (pos) {
121+
if (len <= pos)
122+
return 0;
123+
len -= pos;
124+
memmove(buf, buf + pos, len);
125+
}
120126
return min(count, len);
121127
}
122128

0 commit comments

Comments
 (0)