1. 15 12月, 2022 1 次提交
    • J
      regulator: core: fix deadlock on regulator enable · cb3543cf
      Johan Hovold 提交于
      When updating the operating mode as part of regulator enable, the caller
      has already locked the regulator tree and drms_uA_update() must not try
      to do the same in order not to trigger a deadlock.
      
      The lock inversion is reported by lockdep as:
      
        ======================================================
        WARNING: possible circular locking dependency detected
        6.1.0-next-20221215 #142 Not tainted
        ------------------------------------------------------
        udevd/154 is trying to acquire lock:
        ffffc11f123d7e50 (regulator_list_mutex){+.+.}-{3:3}, at: regulator_lock_dependent+0x54/0x280
      
        but task is already holding lock:
        ffff80000e4c36e8 (regulator_ww_class_acquire){+.+.}-{0:0}, at: regulator_enable+0x34/0x80
      
        which lock already depends on the new lock.
      
        ...
      
         Possible unsafe locking scenario:
      
               CPU0                    CPU1
               ----                    ----
          lock(regulator_ww_class_acquire);
                                       lock(regulator_list_mutex);
                                       lock(regulator_ww_class_acquire);
          lock(regulator_list_mutex);
      
         *** DEADLOCK ***
      
      just before probe of a Qualcomm UFS controller (occasionally) deadlocks
      when enabling one of its regulators.
      
      Fixes: 9243a195 ("regulator: core: Change voltage setting path")
      Fixes: f8702f9e ("regulator: core: Use ww_mutex for regulators locking")
      Cc: stable@vger.kernel.org      # 5.0
      Signed-off-by: NJohan Hovold <johan+linaro@kernel.org>
      Link: https://lore.kernel.org/r/20221215104646.19818-1-johan+linaro@kernel.orgSigned-off-by: NMark Brown <broonie@kernel.org>
      cb3543cf
  2. 14 12月, 2022 1 次提交
  3. 08 12月, 2022 1 次提交
  4. 02 12月, 2022 2 次提交
    • Y
      regulator: core: fix resource leak in regulator_register() · ba62319a
      Yang Yingliang 提交于
      I got some resource leak reports while doing fault injection test:
      
        OF: ERROR: memory leak, expected refcount 1 instead of 100,
        of_node_get()/of_node_put() unbalanced - destroy cset entry:
        attach overlay node /i2c/pmic@64/regulators/buck1
      
      unreferenced object 0xffff88810deea000 (size 512):
        comm "490-i2c-rt5190a", pid 253, jiffies 4294859840 (age 5061.046s)
        hex dump (first 32 bytes):
          00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00  .....N..........
          ff ff ff ff ff ff ff ff a0 1e 00 a1 ff ff ff ff  ................
        backtrace:
          [<00000000d78541e2>] kmalloc_trace+0x21/0x110
          [<00000000b343d153>] device_private_init+0x32/0xd0
          [<00000000be1f0c70>] device_add+0xb2d/0x1030
          [<00000000e3e6344d>] regulator_register+0xaf2/0x12a0
          [<00000000e2f5e754>] devm_regulator_register+0x57/0xb0
          [<000000008b898197>] rt5190a_probe+0x52a/0x861 [rt5190a_regulator]
      
      unreferenced object 0xffff88810b617b80 (size 32):
        comm "490-i2c-rt5190a", pid 253, jiffies 4294859904 (age 5060.983s)
        hex dump (first 32 bytes):
          72 65 67 75 6c 61 74 6f 72 2e 32 38 36 38 2d 53  regulator.2868-S
          55 50 50 4c 59 00 ff ff 29 00 00 00 2b 00 00 00  UPPLY...)...+...
        backtrace:
          [<000000009da9280d>] __kmalloc_node_track_caller+0x44/0x1b0
          [<0000000025c6a4e5>] kstrdup+0x3a/0x70
          [<00000000790efb69>] create_regulator+0xc0/0x4e0
          [<0000000005ed203a>] regulator_resolve_supply+0x2d4/0x440
          [<0000000045796214>] regulator_register+0x10b3/0x12a0
          [<00000000e2f5e754>] devm_regulator_register+0x57/0xb0
          [<000000008b898197>] rt5190a_probe+0x52a/0x861 [rt5190a_regulator]
      
      After calling regulator_resolve_supply(), the 'rdev->supply' is set
      by set_supply(), after this set, in the error path, the resources
      need be released, so call regulator_put() to avoid the leaks.
      
      Fixes: aea6cb99 ("regulator: resolve supply after creating regulator")
      Fixes: 8a866d52 ("regulator: core: Resolve supply name earlier to prevent double-init")
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      Link: https://lore.kernel.org/r/20221202025111.496402-1-yangyingliang@huawei.comSigned-off-by: NMark Brown <broonie@kernel.org>
      ba62319a
    • Y
      regulator: core: fix module refcount leak in set_supply() · da46ee19
      Yang Yingliang 提交于
      If create_regulator() fails in set_supply(), the module refcount
      needs be put to keep refcount balanced.
      
      Fixes: e2c09ae7 ("regulator: core: Increase refcount for regulator supply's module")
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      Link: https://lore.kernel.org/r/20221201122706.4055992-2-yangyingliang@huawei.comSigned-off-by: NMark Brown <broonie@kernel.org>
      da46ee19
  5. 01 12月, 2022 1 次提交
    • R
      regulator: core: fix use_count leakage when handling boot-on · 0591b14c
      Rui Zhang 提交于
      I found a use_count leakage towards supply regulator of rdev with
      boot-on option.
      
      ┌───────────────────┐           ┌───────────────────┐
      │  regulator_dev A  │           │  regulator_dev B  │
      │     (boot-on)     │           │     (boot-on)     │
      │    use_count=0    │──supply──│    use_count=1    │
      │                   │           │                   │
      └───────────────────┘           └───────────────────┘
      
      In case of rdev(A) configured with `regulator-boot-on', the use_count
      of supplying regulator(B) will increment inside
      regulator_enable(rdev->supply).
      
      Thus, B will acts like always-on, and further balanced
      regulator_enable/disable cannot actually disable it anymore.
      
      However, B was also configured with `regulator-boot-on', we wish it
      could be disabled afterwards.
      Signed-off-by: NRui Zhang <zr.zhang@vivo.com>
      Link: https://lore.kernel.org/r/20221201033806.2567812-1-zr.zhang@vivo.comSigned-off-by: NMark Brown <broonie@kernel.org>
      0591b14c
  6. 23 11月, 2022 1 次提交
  7. 15 11月, 2022 1 次提交
  8. 03 11月, 2022 1 次提交
  9. 10 9月, 2022 1 次提交
  10. 30 8月, 2022 1 次提交
  11. 26 8月, 2022 2 次提交
    • D
      regulator: core: Don't err if allow-set-load but no allowed-modes · 57919f4a
      Douglas Anderson 提交于
      Apparently the device trees of some boards have the property
      "regulator-allow-set-load" for some of their regulators but then they
      don't specify anything for "regulator-allowed-modes". That's not
      really legit, but...
      
      ...before commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()") they used to get away with it, at
      least on boards using RPMH regulators. That's because when a regulator
      driver implements set_load() then the core doesn't look at
      "regulator-allowed-modes" when trying to automatically adjust things
      in response to the regulator's load. The core doesn't know what mode
      we'll end up in, so how could it validate it?
      
      Said another way: before commit efb0cb50 ("regulator: qcom-rpmh:
      Implement get_optimum_mode(), not set_load()") some boards _were_
      having the regulator mode adjusted despite listing no allowed
      modes. After commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()") these same boards were now
      getting an error returned when trying to use their regulators, since
      simply enabling a regulator tries to update its load and that was
      failing.
      
      We don't really want to go back to the behavior from before commit
      efb0cb50 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not
      set_load()"). Boards shouldn't have been changing modes if no allowed
      modes were listed. However, the behavior after commit efb0cb50
      ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()")
      isn't the best because now boards can't even turn their regulators on.
      
      Let's choose to detect this case and return "no error" from
      drms_uA_update(). The net-result will be _different_ behavior than we
      had before commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()"), but this new behavior seems more
      correct. If a board truly needed the mode switched then its device
      tree should be updated to list the allowed modes.
      Reported-by: NAndrew Halaney <ahalaney@redhat.com>
      Fixes: efb0cb50 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()")
      Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Tested-by: NAndrew Halaney <ahalaney@redhat.com>
      Link: https://lore.kernel.org/r/20220824142229.RFT.v2.2.I6f77860e5cd98bf5c67208fa9edda4a08847c304@changeidSigned-off-by: NMark Brown <broonie@kernel.org>
      57919f4a
    • D
      regulator: core: Require regulator drivers to check uV for get_optimum_mode() · 55841199
      Douglas Anderson 提交于
      The get_optimum_mode() for regulator drivers is passed the input
      voltage and output voltage as well as the current. This is because, in
      theory, the optimum mode can depend on all three things.
      
      It turns out that for all regulator drivers in mainline only the
      current is looked at when implementing get_optimum_mode(). None of the
      drivers take the input or output voltage into account. Despite the
      fact that none of the drivers take the input or output voltage into
      account, though, the regulator framework will error out before calling
      into get_optimum_mode() if it doesn't know the input or output
      voltage.
      
      The above behavior turned out to be a probelm for some boards when we
      landed commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()"). Before that change we'd have no
      problems running drms_uA_update() for RPMH regulators even if a
      regulator's input or output voltage was unknown. After that change
      drms_uA_update() started to fail. This is because typically boards
      using RPMH regulators don't model the input supplies of RPMH
      regulators. Input supplies for RPMH regulators nearly always come from
      the output of other RPMH regulators (or always-on regulators) and RPMH
      firmware is initialized with this knowledge and handles enabling (and
      adjusting the voltage of) input supplies. While we could model the
      parent/child relationship of the regulators in Linux, many boards
      don't bother since it adds extra overhead.
      
      Let's change the regulator core to make things work again. Now if we
      fail to get the input or output voltage we'll still call into
      get_optimum_mode() and we'll just pass error codes in for input_uV
      and/or output_uV parameters.
      
      Since no existing regulator drivers even look at input_uV and
      output_uV we don't need to add this error handling anywhere right
      now. We'll add some comments in the core so that it's obvious that (if
      regulator drivers care) it's up to them to add the checks.
      Reported-by: NAndrew Halaney <ahalaney@redhat.com>
      Fixes: efb0cb50 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()")
      Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Tested-by: NAndrew Halaney <ahalaney@redhat.com>
      Link: https://lore.kernel.org/r/20220824142229.RFT.v2.1.I137e6bef4f6d517be7b081be926059321102fd3d@changeidSigned-off-by: NMark Brown <broonie@kernel.org>
      55841199
  12. 22 8月, 2022 2 次提交
  13. 18 8月, 2022 1 次提交
  14. 10 8月, 2022 1 次提交
  15. 27 7月, 2022 1 次提交
  16. 20 7月, 2022 1 次提交
  17. 05 5月, 2022 1 次提交
  18. 04 5月, 2022 1 次提交
  19. 21 4月, 2022 2 次提交
  20. 04 4月, 2022 1 次提交
  21. 08 2月, 2022 1 次提交
    • O
      regulator: core: fix false positive in regulator_late_cleanup() · 4e2a354e
      Oliver Barta 提交于
      The check done by regulator_late_cleanup() to detect whether a regulator
      is on was inconsistent with the check done by _regulator_is_enabled().
      While _regulator_is_enabled() takes the enable GPIO into account,
      regulator_late_cleanup() was not doing that.
      
      This resulted in a false positive, e.g. when a GPIO-controlled fixed
      regulator was used, which was not enabled at boot time, e.g.
      
      reg_disp_1v2: reg_disp_1v2 {
      	compatible = "regulator-fixed";
      	regulator-name = "display_1v2";
      	regulator-min-microvolt = <1200000>;
      	regulator-max-microvolt = <1200000>;
      	gpio = <&tlmm 148 0>;
      	enable-active-high;
      };
      
      Such regulator doesn't have an is_enabled() operation. Nevertheless
      it's state can be determined based on the enable GPIO. The check in
      regulator_late_cleanup() wrongly assumed that the regulator is on and
      tried to disable it.
      Signed-off-by: NOliver Barta <oliver.barta@aptiv.com>
      Link: https://lore.kernel.org/r/20220208084645.8686-1-oliver.barta@aptiv.comSigned-off-by: NMark Brown <broonie@kernel.org>
      4e2a354e
  22. 23 10月, 2021 1 次提交
  23. 30 9月, 2021 1 次提交
  24. 17 9月, 2021 1 次提交
    • M
      kernel/locking: Add context to ww_mutex_trylock() · 12235da8
      Maarten Lankhorst 提交于
      i915 will soon gain an eviction path that trylock a whole lot of locks
      for eviction, getting dmesg failures like below:
      
        BUG: MAX_LOCK_DEPTH too low!
        turning off the locking correctness validator.
        depth: 48  max: 48!
        48 locks held by i915_selftest/5776:
         #0: ffff888101a79240 (&dev->mutex){....}-{3:3}, at: __driver_attach+0x88/0x160
         #1: ffffc900009778c0 (reservation_ww_class_acquire){+.+.}-{0:0}, at: i915_vma_pin.constprop.63+0x39/0x1b0 [i915]
         #2: ffff88800cf74de8 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_vma_pin.constprop.63+0x5f/0x1b0 [i915]
         #3: ffff88810c7f9e38 (&vm->mutex/1){+.+.}-{3:3}, at: i915_vma_pin_ww+0x1c4/0x9d0 [i915]
         #4: ffff88810bad5768 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
         #5: ffff88810bad60e8 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
        ...
         #46: ffff88811964d768 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
         #47: ffff88811964e0e8 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
        INFO: lockdep is turned off.
      
      Fixing eviction to nest into ww_class_acquire is a high priority, but
      it requires a rework of the entire driver, which can only be done one
      step at a time.
      
      As an intermediate solution, add an acquire context to
      ww_mutex_trylock, which allows us to do proper nesting annotations on
      the trylocks, making the above lockdep splat disappear.
      
      This is also useful in regulator_lock_nested, which may avoid dropping
      regulator_nesting_mutex in the uncontended path, so use it there.
      
      TTM may be another user for this, where we could lock a buffer in a
      fastpath with list locks held, without dropping all locks we hold.
      
      [peterz: rework actual ww_mutex_trylock() implementations]
      Signed-off-by: NMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/YUBGPdDDjKlxAuXJ@hirez.programming.kicks-ass.net
      12235da8
  25. 13 9月, 2021 1 次提交
  26. 21 6月, 2021 3 次提交
  27. 02 6月, 2021 1 次提交
  28. 01 6月, 2021 1 次提交
  29. 21 5月, 2021 1 次提交
  30. 23 4月, 2021 1 次提交
    • V
      regulator: core: Fix off_on_delay handling · a8ce7bd8
      Vincent Whitchurch 提交于
      The jiffies-based off_on_delay implementation has a couple of problems
      that cause it to sometimes not actually delay for the required time:
      
       (1) If, for example, the off_on_delay time is equivalent to one jiffy,
           and the ->last_off_jiffy is set just before a new jiffy starts,
           then _regulator_do_enable() does not wait at all since it checks
           using time_before().
      
       (2) When jiffies overflows, the value of "remaining" becomes higher
           than "max_delay" and the code simply proceeds without waiting.
      
      Fix these problems by changing it to use ktime_t instead.
      
      [Note that since jiffies doesn't start at zero but at INITIAL_JIFFIES
       ("-5 minutes"), (2) above also led to the code not delaying if
       the first regulator_enable() is called when the ->last_off_jiffy is not
       initialised, such as for regulators with ->constraints->boot_on set.
       It's not clear to me if this was intended or not, but I've preserved
       this behaviour explicitly with the check for a non-zero ->last_off.]
      Signed-off-by: NVincent Whitchurch <vincent.whitchurch@axis.com>
      Link: https://lore.kernel.org/r/20210423114524.26414-1-vincent.whitchurch@axis.comSigned-off-by: NMark Brown <broonie@kernel.org>
      a8ce7bd8
  31. 22 4月, 2021 1 次提交
  32. 21 4月, 2021 2 次提交
  33. 25 1月, 2021 1 次提交
    • H
      regulator: core: Avoid debugfs: Directory ... already present! error · dbe954d8
      Hans de Goede 提交于
      Sometimes regulator_get() gets called twice for the same supply on the
      same device. This may happen e.g. when a framework / library is used
      which uses the regulator; and the driver itself also needs to enable
      the regulator in some cases where the framework will not enable it.
      
      Commit ff268b56 ("regulator: core: Don't spew backtraces on
      duplicate sysfs") already takes care of the backtrace which would
      trigger when creating a duplicate consumer symlink under
      /sys/class/regulator/regulator.%d in this scenario.
      
      Commit c33d4423 ("debugfs: make error message a bit more verbose")
      causes a new error to get logged in this scenario:
      
      [   26.938425] debugfs: Directory 'wm5102-codec-MICVDD' with parent 'spi-WM510204:00-MICVDD' already present!
      
      There is no _nowarn variant of debugfs_create_dir(), but we can detect
      and avoid this problem by checking the return value of the earlier
      sysfs_create_link_nowarn() call.
      
      Add a check for the earlier sysfs_create_link_nowarn() failing with
      -EEXIST and skip the debugfs_create_dir() call in that case, avoiding
      this error getting logged.
      
      Fixes: c33d4423 ("debugfs: make error message a bit more verbose")
      Cc: Charles Keepax <ckeepax@opensource.cirrus.com>
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Reviewed-by: NCharles Keepax <ckeepax@opensource.cirrus.com>
      Link: https://lore.kernel.org/r/20210122183250.370571-1-hdegoede@redhat.comSigned-off-by: NMark Brown <broonie@kernel.org>
      dbe954d8