Merge tag 'for-v3.13/clock-fixes-a' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / fs / sysfs / file.c
index c324ee9..79b5da2 100644 (file)
@@ -154,9 +154,9 @@ static ssize_t sysfs_bin_read(struct file *file, char __user *userbuf,
                              size_t bytes, loff_t *off)
 {
        struct sysfs_open_file *of = sysfs_of(file);
-       struct bin_attribute *battr = of->sd->s_bin_attr.bin_attr;
+       struct bin_attribute *battr = of->sd->s_attr.bin_attr;
        struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
-       int size = file_inode(file)->i_size;
+       loff_t size = file_inode(file)->i_size;
        int count = min_t(size_t, bytes, PAGE_SIZE);
        loff_t offs = *off;
        char *buf;
@@ -236,7 +236,7 @@ static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off,
        }
 
        if (sysfs_is_bin(of->sd)) {
-               struct bin_attribute *battr = of->sd->s_bin_attr.bin_attr;
+               struct bin_attribute *battr = of->sd->s_attr.bin_attr;
 
                rc = -EIO;
                if (battr->write)
@@ -275,11 +275,10 @@ static ssize_t sysfs_write_file(struct file *file, const char __user *user_buf,
 {
        struct sysfs_open_file *of = sysfs_of(file);
        ssize_t len = min_t(size_t, count, PAGE_SIZE);
+       loff_t size = file_inode(file)->i_size;
        char *buf;
 
-       if (sysfs_is_bin(of->sd)) {
-               loff_t size = file_inode(file)->i_size;
-
+       if (sysfs_is_bin(of->sd) && size) {
                if (size <= *ppos)
                        return 0;
                len = min_t(ssize_t, len, size - *ppos);
@@ -467,7 +466,7 @@ static const struct vm_operations_struct sysfs_bin_vm_ops = {
 static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
 {
        struct sysfs_open_file *of = sysfs_of(file);
-       struct bin_attribute *battr = of->sd->s_bin_attr.bin_attr;
+       struct bin_attribute *battr = of->sd->s_attr.bin_attr;
        struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
        int rc;
 
@@ -478,7 +477,6 @@ static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
        if (!sysfs_get_active(of->sd))
                goto out_unlock;
 
-       rc = -EINVAL;
        if (!battr->mmap)
                goto out_put;
 
@@ -619,7 +617,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
                return -ENODEV;
 
        if (sysfs_is_bin(attr_sd)) {
-               struct bin_attribute *battr = attr_sd->s_bin_attr.bin_attr;
+               struct bin_attribute *battr = attr_sd->s_attr.bin_attr;
 
                has_read = battr->read || battr->mmap;
                has_write = battr->write || battr->mmap;
@@ -802,7 +800,7 @@ EXPORT_SYMBOL_GPL(sysfs_notify);
 const struct file_operations sysfs_file_operations = {
        .read           = seq_read,
        .write          = sysfs_write_file,
-       .llseek         = seq_lseek,
+       .llseek         = generic_file_llseek,
        .open           = sysfs_open_file,
        .release        = sysfs_release,
        .poll           = sysfs_poll,