* [PATCH] rust: pwm: remove unsound Device::chip helper
@ 2026-12-03 10:42 Franklin-Qi
0 siblings, 0 replies; only message in thread
From: Franklin-Qi @ 2026-12-03 10:42 UTC (permalink / raw)
To: Michal Wilczynski, Uwe Kleine-König, Miguel Ojeda,
Danilo Krummrich
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan, linux-pwm,
rust-for-linux, stable, Franklin-Qi
Device::chip::<T>() is a safe API that forges &Chip<T> for an
arbitrary PwmOps type, after which Chip::drvdata() reinterprets the
chip private allocation as &T. Callers can therefore type-confuse
drvdata from safe Rust; with a larger forged T this is a slab
out-of-bounds read under KASAN.
PwmOps callbacks already receive a correctly typed &Chip<Self>, and
there are no in-tree callers of Device::chip. Remove the helper.
Fixes: d8046cd50879 ("rust: pwm: Add complete abstraction layer")
Cc: stable@vger.kernel.org
Closes: https://github.com/Rust-for-Linux/linux/issues/1274
Signed-off-by: Franklin-Qi <yusq77@gmail.com>
---
rust/kernel/pwm.rs | 8 --------
1 file changed, 8 deletions(-)
diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs
index 8aa47304bec3..4cb5a15d0d8e 100644
--- a/rust/kernel/pwm.rs
+++ b/rust/kernel/pwm.rs
@@ -101,14 +101,6 @@ pub fn hwpwm(&self) -> u32 {
unsafe { (*self.as_raw()).hwpwm }
}
- /// Gets a reference to the parent `Chip` that this device belongs to.
- pub fn chip<T: PwmOps>(&self) -> &Chip<T> {
- // SAFETY: `self.as_raw()` provides a valid pointer. (*self.as_raw()).chip
- // is assumed to be a valid pointer to `pwm_chip` managed by the kernel.
- // Chip::from_raw's safety conditions must be met.
- unsafe { Chip::<T>::from_raw((*self.as_raw()).chip) }
- }
-
/// Gets the label for this PWM device, if any.
pub fn label(&self) -> Option<&CStr> {
// SAFETY: self.as_raw() provides a valid pointer.
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-03 10:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 10:42 [PATCH] rust: pwm: remove unsound Device::chip helper Franklin-Qi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox