From 6fe9e919c144f1296d38e2abb10c7ac4320aa7fa Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 29 Oct 2025 19:25:02 +0100 Subject: pwm: Fix Rust formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: d8046cd50879 ("rust: pwm: Add complete abstraction layer") Fixes: 7b3dce814a15 ("rust: pwm: Add Kconfig and basic data structures") Fixes: e03724aac758 ("pwm: Add Rust driver for T-HEAD TH1520 SoC") Signed-off-by: Miguel Ojeda Link: https://patch.msgid.link/20251029182502.783392-1-ojeda@kernel.org Signed-off-by: Uwe Kleine-König --- rust/kernel/pwm.rs | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'rust/kernel/pwm.rs') diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs index e6d1278d8316..cb00f8a8765c 100644 --- a/rust/kernel/pwm.rs +++ b/rust/kernel/pwm.rs @@ -13,7 +13,7 @@ use crate::{ devres, error::{self, to_result}, prelude::*, - types::{ARef, AlwaysRefCounted, Opaque}, + types::{ARef, AlwaysRefCounted, Opaque}, // }; use core::{marker::PhantomData, ptr::NonNull}; @@ -109,7 +109,7 @@ impl Device { // SAFETY: self.as_raw() provides a valid pointer. let label_ptr = unsafe { (*self.as_raw()).label }; if label_ptr.is_null() { - return None + return None; } // SAFETY: label_ptr is non-null and points to a C string @@ -180,11 +180,7 @@ pub trait PwmOps: 'static + Sized { type WfHw: Copy + Default; /// Optional hook for when a PWM device is requested. - fn request( - _chip: &Chip, - _pwm: &Device, - _parent_dev: &device::Device, - ) -> Result { + fn request(_chip: &Chip, _pwm: &Device, _parent_dev: &device::Device) -> Result { Ok(()) } @@ -310,7 +306,9 @@ impl Adapter { // Now, call the original release function to free the `pwm_chip` itself. // SAFETY: `dev` is the valid pointer passed into this callback, which is // the expected argument for `pwmchip_release`. - unsafe { bindings::pwmchip_release(dev); } + unsafe { + bindings::pwmchip_release(dev); + } } /// # Safety @@ -593,9 +591,8 @@ impl Chip { ) -> Result> { let sizeof_priv = core::mem::size_of::(); // SAFETY: `pwmchip_alloc` allocates memory for the C struct and our private data. - let c_chip_ptr_raw = unsafe { - bindings::pwmchip_alloc(parent_dev.as_raw(), num_channels, sizeof_priv) - }; + let c_chip_ptr_raw = + unsafe { bindings::pwmchip_alloc(parent_dev.as_raw(), num_channels, sizeof_priv) }; let c_chip_ptr: *mut bindings::pwm_chip = error::from_err_ptr(c_chip_ptr_raw)?; @@ -607,12 +604,16 @@ impl Chip { unsafe { data.__pinned_init(drvdata_ptr.cast())? }; // SAFETY: `c_chip_ptr` points to a valid chip. - unsafe { (*c_chip_ptr).dev.release = Some(Adapter::::release_callback); } + unsafe { + (*c_chip_ptr).dev.release = Some(Adapter::::release_callback); + } // SAFETY: `c_chip_ptr` points to a valid chip. // The `Adapter`'s `VTABLE` has a 'static lifetime, so the pointer // returned by `as_raw()` is always valid. - unsafe { (*c_chip_ptr).ops = Adapter::::VTABLE.as_raw(); } + unsafe { + (*c_chip_ptr).ops = Adapter::::VTABLE.as_raw(); + } // Cast the `*mut bindings::pwm_chip` to `*mut Chip`. This is valid because // `Chip` is `repr(transparent)` over `Opaque`, and @@ -632,7 +633,9 @@ unsafe impl AlwaysRefCounted for Chip { fn inc_ref(&self) { // SAFETY: `self.0.get()` points to a valid `pwm_chip` because `self` exists. // The embedded `dev` is valid. `get_device` increments its refcount. - unsafe { bindings::get_device(&raw mut (*self.0.get()).dev); } + unsafe { + bindings::get_device(&raw mut (*self.0.get()).dev); + } } #[inline] @@ -641,7 +644,9 @@ unsafe impl AlwaysRefCounted for Chip { // SAFETY: `obj` is a valid pointer to a `Chip` (and thus `bindings::pwm_chip`) // with a non-zero refcount. `put_device` handles decrement and final release. - unsafe { bindings::put_device(&raw mut (*c_chip_ptr).dev); } + unsafe { + bindings::put_device(&raw mut (*c_chip_ptr).dev); + } } } @@ -673,11 +678,8 @@ impl Registration { /// to the parent device. /// On unbind of the parent device, the `devres` entry will be dropped, automatically /// calling `pwmchip_remove`. This function should be called from the driver's `probe`. - pub fn register( - dev: &device::Device, - chip: ARef>, - ) -> Result { - let chip_parent = chip.device().parent().ok_or(EINVAL)?; + pub fn register(dev: &device::Device, chip: ARef>) -> Result { + let chip_parent = chip.device().parent().ok_or(EINVAL)?; if dev.as_raw() != chip_parent.as_raw() { return Err(EINVAL); } @@ -703,7 +705,9 @@ impl Drop for Registration { // SAFETY: `chip_raw` points to a chip that was successfully registered. // `bindings::pwmchip_remove` is the correct C function to unregister it. // This `drop` implementation is called automatically by `devres` on driver unbind. - unsafe { bindings::pwmchip_remove(chip_raw); } + unsafe { + bindings::pwmchip_remove(chip_raw); + } } } -- cgit v1.2.3