]> www.infradead.org Git - users/jedix/linux-maple.git/commit
pwm: Add more locking
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Fri, 20 Sep 2024 08:57:57 +0000 (10:57 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Fri, 27 Sep 2024 15:03:15 +0000 (17:03 +0200)
commit1cc2e1faafb3b5a2be25112559bdb495736b5af7
tree61897cfec378c08e04fd8a5c9bd84a3d037ddb0b
parentd242feaf81d63b25d8c1fb1a68738dc33966a376
pwm: Add more locking

This ensures that a pwm_chip that has no corresponding driver isn't used
and that a driver doesn't go away while a callback is still running.

In the presence of device links this isn't necessary yet (so this is no
fix) but for pwm character device support this is needed.

To not serialize all pwm_apply_state() calls, this introduces a per chip
lock. An additional complication is that for atomic chips a mutex cannot
be used (as pwm_apply_atomic() must not sleep) and a spinlock cannot be
held while calling an operation for a sleeping chip. So depending on the
chip being atomic or not a spinlock or a mutex is used.

An additional change implemented here is that on driver remove the
.free() callback is called for each requested pwm_device. This is the
right time because later (e.g. when the consumer calls pwm_put()) the
free function is (maybe) not available any more.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/026aa891c8270a11723a1ba7e4256f456f7e1e86.1726819463.git.u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/core.c
include/linux/pwm.h