| @@ -463,29 +463,31 @@ static ssize_t regmap_cache_only_write_file(struct file *file, · 462 unmodified lines |
| 463 | 463 | { |
| 464 | 464 | struct regmap *map = container_of(file->private_data, |
| 465 | 465 | struct regmap, cache_only); |
| 466 | | − ssize_t result; |
| 467 | | − bool was_enabled, require_sync = false; |
| 466 | + bool new_val, require_sync = false; |
| 468 | 467 | int err; |
| 469 | 468 | |
| 470 | | − map->lock(map->lock_arg); |
| 469 | + err = kstrtobool_from_user(user_buf, count, &new_val); |
| 470 | + /* Ignore malforned data like debugfs_write_file_bool() */ |
| 471 | + if (err) |
| 472 | + return count; |
| 471 | 473 | |
| 472 | | − was_enabled = map->cache_only; |
| 474 | + err = debugfs_file_get(file->f_path.dentry); |
| 475 | + if (err) |
| 476 | + return err; |
| 473 | 477 | |
| 474 | | − result = debugfs_write_file_bool(file, user_buf, count, ppos); |
| 475 | | − if (result < 0) { |
| 476 | | − map->unlock(map->lock_arg); |
| 477 | | − return result; |
| 478 | | − } |
| 478 | + map->lock(map->lock_arg); |
| 479 | 479 | |
| 480 | | − if (map->cache_only && !was_enabled) { |
| 480 | + if (new_val && !map->cache_only) { |
| 481 | 481 | dev_warn(map->dev, "debugfs cache_only=Y forced\n"); |
| 482 | 482 | add_taint(TAINT_USER, LOCKDEP_STILL_OK); |
| 483 | | − } else if (!map->cache_only && was_enabled) { |
| 483 | + } else if (!new_val && map->cache_only) { |
| 484 | 484 | dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n"); |
| 485 | 485 | require_sync = true; |
| 486 | 486 | } |
| 487 | + map->cache_only = new_val; |
| 487 | 488 | |
| 488 | 489 | map->unlock(map->lock_arg); |
| 490 | + debugfs_file_put(file->f_path.dentry); |
| 489 | 491 | |
| 490 | 492 | if (require_sync) { |
| 491 | 493 | err = regcache_sync(map); |
| @@ -493,7 +495,7 @@ static ssize_t regmap_cache_only_write_file(struct file *file, · 1 unmodified line |
| 493 | 495 | dev_err(map->dev, "Failed to sync cache %d\n", err); |
| 494 | 496 | } |
| 495 | 497 | |
| 496 | | − return result; |
| 498 | + return count; |
| 497 | 499 | } |
| 498 | 500 | |
| 499 | 501 | static const struct file_operations regmap_cache_only_fops = { |
| @@ -508,28 +510,32 @@ static ssize_t regmap_cache_bypass_write_file(struct file *file, · 8 unmodified lines |
| 508 | 510 | { |
| 509 | 511 | struct regmap *map = container_of(file->private_data, |
| 510 | 512 | struct regmap, cache_bypass); |
| 511 | | − ssize_t result; |
| 512 | | − bool was_enabled; |
| 513 | + bool new_val; |
| 514 | + int err; |
| 513 | 515 | |
| 514 | | − map->lock(map->lock_arg); |
| 516 | + err = kstrtobool_from_user(user_buf, count, &new_val); |
| 517 | + /* Ignore malforned data like debugfs_write_file_bool() */ |
| 518 | + if (err) |
| 519 | + return count; |
| 515 | 520 | |
| 516 | | − was_enabled = map->cache_bypass; |
| 521 | + err = debugfs_file_get(file->f_path.dentry); |
| 522 | + if (err) |
| 523 | + return err; |
| 517 | 524 | |
| 518 | | − result = debugfs_write_file_bool(file, user_buf, count, ppos); |
| 519 | | − if (result < 0) |
| 520 | | − goto out; |
| 525 | + map->lock(map->lock_arg); |
| 521 | 526 | |
| 522 | | − if (map->cache_bypass && !was_enabled) { |
| 527 | + if (new_val && !map->cache_bypass) { |
| 523 | 528 | dev_warn(map->dev, "debugfs cache_bypass=Y forced\n"); |
| 524 | 529 | add_taint(TAINT_USER, LOCKDEP_STILL_OK); |
| 525 | | − } else if (!map->cache_bypass && was_enabled) { |
| 530 | + } else if (!new_val && map->cache_bypass) { |
| 526 | 531 | dev_warn(map->dev, "debugfs cache_bypass=N forced\n"); |
| 527 | 532 | } |
| 533 | + map->cache_bypass = new_val; |
| 528 | 534 | |
| 529 | | −out: |
| 530 | 535 | map->unlock(map->lock_arg); |
| 536 | + debugfs_file_put(file->f_path.dentry); |
| 531 | 537 | |
| 532 | | − return result; |
| 538 | + return count; |
| 533 | 539 | } |
| 534 | 540 | |
| 535 | 541 | static const struct file_operations regmap_cache_bypass_fops = { |