]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
sysfs: correctly handle read offset on PREALLOC attrs
authorKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Wed, 22 Jun 2016 18:42:16 +0000 (21:42 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Sep 2016 06:34:56 +0000 (08:34 +0200)
commit95f837790b66c770d94625206e0cc178df984635
treec66367b439b541f00ae7bb05f662e7ce65f6076e
parent34242c449ae7753772b68436efef5679a0726cf4
sysfs: correctly handle read offset on PREALLOC attrs

commit 17d0774f80681020eccc9638d925a23f1fc4f671 upstream.

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: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")
Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/sysfs/file.c