Merge remote-tracking branch 'regmap/for-5.8' into regmap-linus
authorMark Brown <broonie@kernel.org>
Thu, 16 Jul 2020 23:56:05 +0000 (00:56 +0100)
committerMark Brown <broonie@kernel.org>
Thu, 16 Jul 2020 23:56:05 +0000 (00:56 +0100)
1  2 
drivers/base/regmap/regmap-debugfs.c

index 089e5dc7144a6a1a090cbe61dd04fcc0b9fd6c38,e16afa27700db12486912d93c4398f66d6de8c0a..f58baff2be0af6d0eb5e28091cce3a2c3a76a039
@@@ -227,9 -227,6 +227,9 @@@ static ssize_t regmap_read_debugfs(stru
        if (*ppos < 0 || !count)
                return -EINVAL;
  
 +      if (count > (PAGE_SIZE << (MAX_ORDER - 1)))
 +              count = PAGE_SIZE << (MAX_ORDER - 1);
 +
        buf = kmalloc(count, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
@@@ -374,9 -371,6 +374,9 @@@ static ssize_t regmap_reg_ranges_read_f
        if (*ppos < 0 || !count)
                return -EINVAL;
  
 +      if (count > (PAGE_SIZE << (MAX_ORDER - 1)))
 +              count = PAGE_SIZE << (MAX_ORDER - 1);
 +
        buf = kmalloc(count, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
@@@ -463,29 -457,31 +463,31 @@@ static ssize_t regmap_cache_only_write_
  {
        struct regmap *map = container_of(file->private_data,
                                          struct regmap, cache_only);
-       ssize_t result;
-       bool was_enabled, require_sync = false;
+       bool new_val, require_sync = false;
        int err;
  
-       map->lock(map->lock_arg);
+       err = kstrtobool_from_user(user_buf, count, &new_val);
+       /* Ignore malforned data like debugfs_write_file_bool() */
+       if (err)
+               return count;
  
-       was_enabled = map->cache_only;
+       err = debugfs_file_get(file->f_path.dentry);
+       if (err)
+               return err;
  
-       result = debugfs_write_file_bool(file, user_buf, count, ppos);
-       if (result < 0) {
-               map->unlock(map->lock_arg);
-               return result;
-       }
+       map->lock(map->lock_arg);
  
-       if (map->cache_only && !was_enabled) {
+       if (new_val && !map->cache_only) {
                dev_warn(map->dev, "debugfs cache_only=Y forced\n");
                add_taint(TAINT_USER, LOCKDEP_STILL_OK);
-       } else if (!map->cache_only && was_enabled) {
+       } else if (!new_val && map->cache_only) {
                dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n");
                require_sync = true;
        }
+       map->cache_only = new_val;
  
        map->unlock(map->lock_arg);
+       debugfs_file_put(file->f_path.dentry);
  
        if (require_sync) {
                err = regcache_sync(map);
                        dev_err(map->dev, "Failed to sync cache %d\n", err);
        }
  
-       return result;
+       return count;
  }
  
  static const struct file_operations regmap_cache_only_fops = {
@@@ -508,28 -504,32 +510,32 @@@ static ssize_t regmap_cache_bypass_writ
  {
        struct regmap *map = container_of(file->private_data,
                                          struct regmap, cache_bypass);
-       ssize_t result;
-       bool was_enabled;
+       bool new_val;
+       int err;
  
-       map->lock(map->lock_arg);
+       err = kstrtobool_from_user(user_buf, count, &new_val);
+       /* Ignore malforned data like debugfs_write_file_bool() */
+       if (err)
+               return count;
  
-       was_enabled = map->cache_bypass;
+       err = debugfs_file_get(file->f_path.dentry);
+       if (err)
+               return err;
  
-       result = debugfs_write_file_bool(file, user_buf, count, ppos);
-       if (result < 0)
-               goto out;
+       map->lock(map->lock_arg);
  
-       if (map->cache_bypass && !was_enabled) {
+       if (new_val && !map->cache_bypass) {
                dev_warn(map->dev, "debugfs cache_bypass=Y forced\n");
                add_taint(TAINT_USER, LOCKDEP_STILL_OK);
-       } else if (!map->cache_bypass && was_enabled) {
+       } else if (!new_val && map->cache_bypass) {
                dev_warn(map->dev, "debugfs cache_bypass=N forced\n");
        }
+       map->cache_bypass = new_val;
  
- out:
        map->unlock(map->lock_arg);
+       debugfs_file_put(file->f_path.dentry);
  
-       return result;
+       return count;
  }
  
  static const struct file_operations regmap_cache_bypass_fops = {