Skip to content

Commit 6fe9e91

Browse files
ojedaUwe Kleine-König
authored andcommitted
pwm: Fix Rust formatting
We do our best to keep the repository `rustfmt`-clean [1], thus run the tool to fix the formatting issue. A trailing empty comment [2] is added in order to preserve the wanted style for imports (otherwise the tool will compact the first two items). Link: https://rust-for-linux.com/contributing#submit-checklist-addendum [1] Link: https://docs.kernel.org/rust/coding-guidelines.html#style-formatting [2] Fixes: d8046cd ("rust: pwm: Add complete abstraction layer") Fixes: 7b3dce8 ("rust: pwm: Add Kconfig and basic data structures") Fixes: e03724a ("pwm: Add Rust driver for T-HEAD TH1520 SoC") Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Link: https://patch.msgid.link/20251029182502.783392-1-ojeda@kernel.org Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent a367b64 commit 6fe9e91

3 files changed

Lines changed: 39 additions & 26 deletions

File tree

drivers/pwm/pwm_th1520.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ impl pwm::PwmOps for Th1520PwmDriverData {
200200
let rate_hz = data.clk.rate().as_hz() as u64;
201201

202202
if wfhw.period_cycles == 0 {
203-
dev_dbg!(chip.device(), "HW state has zero period, reporting as disabled.\n");
203+
dev_dbg!(
204+
chip.device(),
205+
"HW state has zero period, reporting as disabled.\n"
206+
);
204207
*wf = pwm::Waveform::default();
205208
return Ok(());
206209
}
@@ -277,15 +280,21 @@ impl pwm::PwmOps for Th1520PwmDriverData {
277280
if was_enabled {
278281
iomap.try_write32(wfhw.ctrl_val, th1520_pwm_ctrl(hwpwm))?;
279282
iomap.try_write32(0, th1520_pwm_fp(hwpwm))?;
280-
iomap.try_write32(wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE, th1520_pwm_ctrl(hwpwm))?;
283+
iomap.try_write32(
284+
wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE,
285+
th1520_pwm_ctrl(hwpwm),
286+
)?;
281287
}
282288
return Ok(());
283289
}
284290

285291
iomap.try_write32(wfhw.ctrl_val, th1520_pwm_ctrl(hwpwm))?;
286292
iomap.try_write32(wfhw.period_cycles, th1520_pwm_per(hwpwm))?;
287293
iomap.try_write32(wfhw.duty_cycles, th1520_pwm_fp(hwpwm))?;
288-
iomap.try_write32(wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE, th1520_pwm_ctrl(hwpwm))?;
294+
iomap.try_write32(
295+
wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE,
296+
th1520_pwm_ctrl(hwpwm),
297+
)?;
289298

290299
// The `TH1520_PWM_START` bit must be written in a separate, final transaction, and
291300
// only when enabling the channel from a disabled state.

rust/kernel/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub mod prelude;
121121
pub mod print;
122122
pub mod processor;
123123
pub mod ptr;
124+
#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
125+
pub mod pwm;
124126
pub mod rbtree;
125127
pub mod regulator;
126128
pub mod revocable;
@@ -129,8 +131,6 @@ pub mod security;
129131
pub mod seq_file;
130132
pub mod sizes;
131133
mod static_assert;
132-
#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
133-
pub mod pwm;
134134
#[doc(hidden)]
135135
pub mod std_vendor;
136136
pub mod str;

rust/kernel/pwm.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
devres,
1414
error::{self, to_result},
1515
prelude::*,
16-
types::{ARef, AlwaysRefCounted, Opaque},
16+
types::{ARef, AlwaysRefCounted, Opaque}, //
1717
};
1818
use core::{marker::PhantomData, ptr::NonNull};
1919

@@ -109,7 +109,7 @@ impl Device {
109109
// SAFETY: self.as_raw() provides a valid pointer.
110110
let label_ptr = unsafe { (*self.as_raw()).label };
111111
if label_ptr.is_null() {
112-
return None
112+
return None;
113113
}
114114

115115
// SAFETY: label_ptr is non-null and points to a C string
@@ -180,11 +180,7 @@ pub trait PwmOps: 'static + Sized {
180180
type WfHw: Copy + Default;
181181

182182
/// Optional hook for when a PWM device is requested.
183-
fn request(
184-
_chip: &Chip<Self>,
185-
_pwm: &Device,
186-
_parent_dev: &device::Device<Bound>,
187-
) -> Result {
183+
fn request(_chip: &Chip<Self>, _pwm: &Device, _parent_dev: &device::Device<Bound>) -> Result {
188184
Ok(())
189185
}
190186

@@ -310,7 +306,9 @@ impl<T: PwmOps> Adapter<T> {
310306
// Now, call the original release function to free the `pwm_chip` itself.
311307
// SAFETY: `dev` is the valid pointer passed into this callback, which is
312308
// the expected argument for `pwmchip_release`.
313-
unsafe { bindings::pwmchip_release(dev); }
309+
unsafe {
310+
bindings::pwmchip_release(dev);
311+
}
314312
}
315313

316314
/// # Safety
@@ -593,9 +591,8 @@ impl<T: PwmOps> Chip<T> {
593591
) -> Result<ARef<Self>> {
594592
let sizeof_priv = core::mem::size_of::<T>();
595593
// SAFETY: `pwmchip_alloc` allocates memory for the C struct and our private data.
596-
let c_chip_ptr_raw = unsafe {
597-
bindings::pwmchip_alloc(parent_dev.as_raw(), num_channels, sizeof_priv)
598-
};
594+
let c_chip_ptr_raw =
595+
unsafe { bindings::pwmchip_alloc(parent_dev.as_raw(), num_channels, sizeof_priv) };
599596

600597
let c_chip_ptr: *mut bindings::pwm_chip = error::from_err_ptr(c_chip_ptr_raw)?;
601598

@@ -607,12 +604,16 @@ impl<T: PwmOps> Chip<T> {
607604
unsafe { data.__pinned_init(drvdata_ptr.cast())? };
608605

609606
// SAFETY: `c_chip_ptr` points to a valid chip.
610-
unsafe { (*c_chip_ptr).dev.release = Some(Adapter::<T>::release_callback); }
607+
unsafe {
608+
(*c_chip_ptr).dev.release = Some(Adapter::<T>::release_callback);
609+
}
611610

612611
// SAFETY: `c_chip_ptr` points to a valid chip.
613612
// The `Adapter`'s `VTABLE` has a 'static lifetime, so the pointer
614613
// returned by `as_raw()` is always valid.
615-
unsafe { (*c_chip_ptr).ops = Adapter::<T>::VTABLE.as_raw(); }
614+
unsafe {
615+
(*c_chip_ptr).ops = Adapter::<T>::VTABLE.as_raw();
616+
}
616617

617618
// Cast the `*mut bindings::pwm_chip` to `*mut Chip`. This is valid because
618619
// `Chip` is `repr(transparent)` over `Opaque<bindings::pwm_chip>`, and
@@ -632,7 +633,9 @@ unsafe impl<T: PwmOps> AlwaysRefCounted for Chip<T> {
632633
fn inc_ref(&self) {
633634
// SAFETY: `self.0.get()` points to a valid `pwm_chip` because `self` exists.
634635
// The embedded `dev` is valid. `get_device` increments its refcount.
635-
unsafe { bindings::get_device(&raw mut (*self.0.get()).dev); }
636+
unsafe {
637+
bindings::get_device(&raw mut (*self.0.get()).dev);
638+
}
636639
}
637640

638641
#[inline]
@@ -641,7 +644,9 @@ unsafe impl<T: PwmOps> AlwaysRefCounted for Chip<T> {
641644

642645
// SAFETY: `obj` is a valid pointer to a `Chip` (and thus `bindings::pwm_chip`)
643646
// with a non-zero refcount. `put_device` handles decrement and final release.
644-
unsafe { bindings::put_device(&raw mut (*c_chip_ptr).dev); }
647+
unsafe {
648+
bindings::put_device(&raw mut (*c_chip_ptr).dev);
649+
}
645650
}
646651
}
647652

@@ -673,11 +678,8 @@ impl<T: 'static + PwmOps + Send + Sync> Registration<T> {
673678
/// to the parent device.
674679
/// On unbind of the parent device, the `devres` entry will be dropped, automatically
675680
/// calling `pwmchip_remove`. This function should be called from the driver's `probe`.
676-
pub fn register(
677-
dev: &device::Device<Bound>,
678-
chip: ARef<Chip<T>>,
679-
) -> Result {
680-
let chip_parent = chip.device().parent().ok_or(EINVAL)?;
681+
pub fn register(dev: &device::Device<Bound>, chip: ARef<Chip<T>>) -> Result {
682+
let chip_parent = chip.device().parent().ok_or(EINVAL)?;
681683
if dev.as_raw() != chip_parent.as_raw() {
682684
return Err(EINVAL);
683685
}
@@ -703,7 +705,9 @@ impl<T: PwmOps> Drop for Registration<T> {
703705
// SAFETY: `chip_raw` points to a chip that was successfully registered.
704706
// `bindings::pwmchip_remove` is the correct C function to unregister it.
705707
// This `drop` implementation is called automatically by `devres` on driver unbind.
706-
unsafe { bindings::pwmchip_remove(chip_raw); }
708+
unsafe {
709+
bindings::pwmchip_remove(chip_raw);
710+
}
707711
}
708712
}
709713

0 commit comments

Comments
 (0)