[PATCH 1/1] rust: pwm: track the owner module when registering `Chip`

Gary Guo gary at garyguo.net
Mon Nov 9 04:06:58 PST 2026


On Wed Oct 28, 2026 at 10:28 PM GMT, Priya Bala Govindasamy wrote:
> `UnregisteredChip::register` calls the C function `__pwmchip_add`
> to register a PWM chip with the PWM core.
> `__pwmchip_add` documents that its `owner` argument is supposed to
> be `THIS_MODULE`, but `UnregisteredChip::register` passes
> `core::ptr::null_mut()`. This is acceptable for built-in drivers.
>
> However, for loadable drivers, registering the chip with a null owner
> prevents the PWM core from taking a reference to the owner module when
> a PWM is requested or its character device is opened.
> This means that the owner module can be unloaded while references to the
> chip remain. This can lead to use-after-free and
> kernel panic.
>
> Fix this by marking PwmOps as a `#[vtable]` trait so each implementation
> exposes its actual OwnerModule, then pass that to `__pwmchip_add()`.

For some context the vtable module infrastructure was not there when PWM
abstraction was added.

So I'm more seeing this as improvement as we improve loadable module support
rather than a bug in PWM abstraction that is fixed.

The fix looks good to me.

Reviewed-by: Gary Guo <gary at garyguo.net>

Best,
Gary

>
> Fixes: d8046cd50879 ("rust: pwm: Add complete abstraction layer")
> Reported-by: Dylan Zueck <dzueck at uci.edu>
> Assisted-by: LLM
> Signed-off-by: Priya Bala Govindasamy <pgovind2 at uci.edu>




More information about the linux-riscv mailing list