mbox series

[v4,0/5] pwm: rockchip: Eliminate potential race condition when probing

Message ID cover.1610976129.git.simon@simonsouth.net
Headers show
Series pwm: rockchip: Eliminate potential race condition when probing | expand

Message

Simon South Jan. 19, 2021, 4:12 p.m. UTC
This patch series eliminates the race condition Trent Piepho
identified[0] in the Rockchip PWM driver's rockchip_pwm_probe()
function, by moving code that checks whether a device is enabled ahead
of the code that registers it via pwmchip_add().

It includes several other small fixes and improvements to the driver
as well: It also

- Fixes a potential kernel hang introduced by my earlier commit
  457f74abbed0 ("pwm: rockchip: Keep enabled PWMs running while
  probing") by ensuring a device's APB clock is enabled before its
  registers are accessed;

- Removes a superfluous call to clk_unprepare() that could produce
  warnings from the kernel;

- Clarifies error messages from the driver by replacing "bus clk" with
  "PWM clk"; and

- Ensures the driver enables a clock before querying its rate with
  clk_get_rate(), as stated as a requirement in that function's
  documentation.

This version of the series incorporates Uwe Kleine-K├Ânig's feedback on
v3 and includes these changes:

- Patch 1's commit message has been edited slightly to improve
  readability, and the error message updated by the patch now reads
  "prepare enable" rather than just "enable" for consistency with the
  error message above it in the code.

- Patch 3's commit message now mentions consistency with the device
  tree.

- Patch 4 has been simplified and now just moves the device-enabled
  check ahead of the call to pwmchip_add(). It no longers changes any
  error-handling behaviour, and an extraneous pair of parentheses has
  been removed.

Patches 2 and 5 are unchanged from v3, while the remaining 2 patches
present in v3 (which removed goto targets from and reordered some
operations in rockchip_pwm_probe()) have been dropped.

I've tested these changes on my Pinebook Pro (RK3399 with a PWM-driven
backlight enabled by U-Boot) and ROCK64 (RK3328) and they appear to
work fine.

[0] https://www.spinics.net/lists/linux-pwm/msg14611.html

--
Simon South
simon@simonsouth.net


Simon South (5):
  pwm: rockchip: Enable APB clock during register access while probing
  pwm: rockchip: rockchip_pwm_probe(): Remove superfluous
    clk_unprepare()
  pwm: rockchip: Replace "bus clk" with "PWM clk"
  pwm: rockchip: Eliminate potential race condition when probing
  pwm: rockchip: Enable clock before calling clk_get_rate()

 drivers/pwm/pwm-rockchip.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)