| @@ -463,29 +463,31 @@ static ssize_t regmap_cache_only_write_file(struct file *file, · 462 unmodified lines |
| 463 | { | 463 | { |
| 464 | struct regmap *map = container_of(file->private_data, | 464 | struct regmap *map = container_of(file->private_data, |
| 465 | struct regmap, cache_only); | 465 | struct regmap, cache_only); |
| 466 | ssize_t result; | 466 | bool new_val, require_sync = false; |
| 467 | bool was_enabled, require_sync = false; | | |
| 468 | int err; | 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); | 478 | map->lock(map->lock_arg); |
| 475 | if (result < 0) { | | |
| 476 | map->unlock(map->lock_arg); | | |
| 477 | return result; | | |
| 478 | } | | |
| 479 | | 479 | |
| 480 | if (map->cache_only && !was_enabled) { | 480 | if (new_val && !map->cache_only) { |
| 481 | dev_warn(map->dev, "debugfs cache_only=Y forced\n"); | 481 | dev_warn(map->dev, "debugfs cache_only=Y forced\n"); |
| 482 | add_taint(TAINT_USER, LOCKDEP_STILL_OK); | 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 | dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n"); | 484 | dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n"); |
| 485 | require_sync = true; | 485 | require_sync = true; |
| 486 | } | 486 | } |
| | 487 | map->cache_only = new_val; |
| 487 | | 488 | |
| 488 | map->unlock(map->lock_arg); | 489 | map->unlock(map->lock_arg); |
| | 490 | debugfs_file_put(file->f_path.dentry); |
| 489 | | 491 | |
| 490 | if (require_sync) { | 492 | if (require_sync) { |
| 491 | err = regcache_sync(map); | 493 | err = regcache_sync(map); |
| @@ -493,7 +495,7 @@ static ssize_t regmap_cache_only_write_file(struct file *file, · 1 unmodified line |
| 493 | dev_err(map->dev, "Failed to sync cache %d\n", err); | 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 | static const struct file_operations regmap_cache_only_fops = { | 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 | struct regmap *map = container_of(file->private_data, | 511 | struct regmap *map = container_of(file->private_data, |
| 510 | struct regmap, cache_bypass); | 512 | struct regmap, cache_bypass); |
| 511 | ssize_t result; | 513 | bool new_val; |
| 512 | bool was_enabled; | 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); | 525 | map->lock(map->lock_arg); |
| 519 | if (result < 0) | | |
| 520 | goto out; | | |
| 521 | | 526 | |
| 522 | if (map->cache_bypass && !was_enabled) { | 527 | if (new_val && !map->cache_bypass) { |
| 523 | dev_warn(map->dev, "debugfs cache_bypass=Y forced\n"); | 528 | dev_warn(map->dev, "debugfs cache_bypass=Y forced\n"); |
| 524 | add_taint(TAINT_USER, LOCKDEP_STILL_OK); | 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 | dev_warn(map->dev, "debugfs cache_bypass=N forced\n"); | 531 | dev_warn(map->dev, "debugfs cache_bypass=N forced\n"); |
| 527 | } | 532 | } |
| | 533 | map->cache_bypass = new_val; |
| 528 | | 534 | |
| 529 | out: | | |
| 530 | map->unlock(map->lock_arg); | 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 | static const struct file_operations regmap_cache_bypass_fops = { | 541 | static const struct file_operations regmap_cache_bypass_fops = { |