提交 65da3484 编写于 作者: N NeilBrown 提交者: Greg Kroah-Hartman

sysfs: correctly handle short reads on PREALLOC attrs.

attributes declared with __ATTR_PREALLOC use sysfs_kf_read()
which ignores the 'count' arg.
So a 1-byte read request can return more bytes than that.

This is seen with the 'dash' shell when 'read' is used on
some 'md' sysfs attributes.

So only return the 'min' of count and the attribute length.
Signed-off-by: NNeilBrown <neilb@suse.com>
Acked-by: NTejun Heo <tj@kernel.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 cfcf6a91
...@@ -108,6 +108,7 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, ...@@ -108,6 +108,7 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,
{ {
const struct sysfs_ops *ops = sysfs_file_ops(of->kn); const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
struct kobject *kobj = of->kn->parent->priv; struct kobject *kobj = of->kn->parent->priv;
size_t len;
/* /*
* If buf != of->prealloc_buf, we don't know how * If buf != of->prealloc_buf, we don't know how
...@@ -115,7 +116,8 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, ...@@ -115,7 +116,8 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,
*/ */
if (pos || WARN_ON_ONCE(buf != of->prealloc_buf)) if (pos || WARN_ON_ONCE(buf != of->prealloc_buf))
return 0; return 0;
return ops->show(kobj, of->kn->priv, buf); len = ops->show(kobj, of->kn->priv, buf);
return min(count, len);
} }
/* kernfs write callback for regular sysfs files */ /* kernfs write callback for regular sysfs files */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册