Merge "This patch is used to update the documents of D-release."
[kvmfornfv.git] / kernel / fs / sysfs / file.c
index 7c2867b..b803213 100644 (file)
@@ -90,7 +90,7 @@ static ssize_t sysfs_kf_bin_read(struct kernfs_open_file *of, char *buf,
                return 0;
 
        if (size) {
-               if (pos > size)
+               if (pos >= size)
                        return 0;
                if (pos + count > size)
                        count = size - pos;
@@ -108,14 +108,22 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,
 {
        const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
        struct kobject *kobj = of->kn->parent->priv;
+       size_t len;
 
        /*
         * If buf != of->prealloc_buf, we don't know how
         * large it is, so cannot safely pass it to ->show
         */
-       if (pos || WARN_ON_ONCE(buf != of->prealloc_buf))
+       if (WARN_ON_ONCE(buf != of->prealloc_buf))
                return 0;
-       return ops->show(kobj, of->kn->priv, buf);
+       len = ops->show(kobj, of->kn->priv, buf);
+       if (pos) {
+               if (len <= pos)
+                       return 0;
+               len -= pos;
+               memmove(buf, buf + pos, len);
+       }
+       return min(count, len);
 }
 
 /* kernfs write callback for regular sysfs files */