rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm: fix Rust formatting
@ 2025-10-29 18:25 Miguel Ojeda
  2025-10-30 22:10 ` Uwe Kleine-König
  0 siblings, 1 reply; 2+ messages in thread
From: Miguel Ojeda @ 2025-10-29 18:25 UTC (permalink / raw)
  To: Michal Wilczynski, Miguel Ojeda, Alex Gaynor
  Cc: linux-pwm, rust-for-linux, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, linux-kernel, patches

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: a3d5a2b8da94 ("rust: pwm: Add complete abstraction layer")
Fixes: 121931a7b4dc ("rust: pwm: Add Kconfig and basic data structures")
Fixes: fb3957af9ec6 ("pwm: Add Rust driver for T-HEAD TH1520 SoC")
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
If you usually rebase your tree, please feel free to do so instead. Thanks!

 drivers/pwm/pwm_th1520.rs | 15 ++++++++++---
 rust/kernel/lib.rs        |  4 ++--
 rust/kernel/pwm.rs        | 46 +++++++++++++++++++++------------------
 3 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/drivers/pwm/pwm_th1520.rs b/drivers/pwm/pwm_th1520.rs
index 0ad38b78be85..ee2a6d573bc2 100644
--- a/drivers/pwm/pwm_th1520.rs
+++ b/drivers/pwm/pwm_th1520.rs
@@ -200,7 +200,10 @@ fn round_waveform_fromhw(
         let rate_hz = data.clk.rate().as_hz() as u64;

         if wfhw.period_cycles == 0 {
-            dev_dbg!(chip.device(), "HW state has zero period, reporting as disabled.\n");
+            dev_dbg!(
+                chip.device(),
+                "HW state has zero period, reporting as disabled.\n"
+            );
             *wf = pwm::Waveform::default();
             return Ok(());
         }
@@ -277,7 +280,10 @@ fn write_waveform(
             if was_enabled {
                 iomap.try_write32(wfhw.ctrl_val, th1520_pwm_ctrl(hwpwm))?;
                 iomap.try_write32(0, th1520_pwm_fp(hwpwm))?;
-                iomap.try_write32(wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE, th1520_pwm_ctrl(hwpwm))?;
+                iomap.try_write32(
+                    wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE,
+                    th1520_pwm_ctrl(hwpwm),
+                )?;
             }
             return Ok(());
         }
@@ -285,7 +291,10 @@ fn write_waveform(
         iomap.try_write32(wfhw.ctrl_val, th1520_pwm_ctrl(hwpwm))?;
         iomap.try_write32(wfhw.period_cycles, th1520_pwm_per(hwpwm))?;
         iomap.try_write32(wfhw.duty_cycles, th1520_pwm_fp(hwpwm))?;
-        iomap.try_write32(wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE, th1520_pwm_ctrl(hwpwm))?;
+        iomap.try_write32(
+            wfhw.ctrl_val | TH1520_PWM_CFG_UPDATE,
+            th1520_pwm_ctrl(hwpwm),
+        )?;

         // The `TH1520_PWM_START` bit must be written in a separate, final transaction, and
         // only when enabling the channel from a disabled state.
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 68c71d888fdb..584aa3282029 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -121,6 +121,8 @@
 pub mod print;
 pub mod processor;
 pub mod ptr;
+#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
+pub mod pwm;
 pub mod rbtree;
 pub mod regulator;
 pub mod revocable;
@@ -129,8 +131,6 @@
 pub mod seq_file;
 pub mod sizes;
 mod static_assert;
-#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
-pub mod pwm;
 #[doc(hidden)]
 pub mod std_vendor;
 pub mod str;
diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs
index 79fbb13cd47f..9149161e6253 100644
--- a/rust/kernel/pwm.rs
+++ b/rust/kernel/pwm.rs
@@ -13,7 +13,7 @@
     devres,
     error::{self, to_result},
     prelude::*,
-    types::{ARef, AlwaysRefCounted, Opaque},
+    types::{ARef, AlwaysRefCounted, Opaque}, //
 };
 use core::{convert::TryFrom, marker::PhantomData, ptr::NonNull};

@@ -156,7 +156,7 @@ pub fn label(&self) -> Option<&CStr> {
         // 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
@@ -234,11 +234,7 @@ pub trait PwmOps: 'static + Sized {
     type WfHw: Copy + Default;

     /// Optional hook for when a PWM device is requested.
-    fn request(
-        _chip: &Chip<Self>,
-        _pwm: &Device,
-        _parent_dev: &device::Device<Bound>,
-    ) -> Result {
+    fn request(_chip: &Chip<Self>, _pwm: &Device, _parent_dev: &device::Device<Bound>) -> Result {
         Ok(())
     }

@@ -364,7 +360,9 @@ unsafe fn deserialize_wfhw(wfhw_ptr: *const c_void) -> Result<T::WfHw> {
         // 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
@@ -647,9 +645,8 @@ pub fn new(
     ) -> Result<ARef<Self>> {
         let sizeof_priv = core::mem::size_of::<T>();
         // 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)?;

@@ -661,12 +658,16 @@ pub fn new(
         unsafe { data.__pinned_init(drvdata_ptr.cast())? };

         // SAFETY: `c_chip_ptr` points to a valid chip.
-        unsafe { (*c_chip_ptr).dev.release = Some(Adapter::<T>::release_callback); }
+        unsafe {
+            (*c_chip_ptr).dev.release = Some(Adapter::<T>::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::<T>::VTABLE.as_raw(); }
+        unsafe {
+            (*c_chip_ptr).ops = Adapter::<T>::VTABLE.as_raw();
+        }

         // Cast the `*mut bindings::pwm_chip` to `*mut Chip`. This is valid because
         // `Chip` is `repr(transparent)` over `Opaque<bindings::pwm_chip>`, and
@@ -686,7 +687,9 @@ unsafe impl<T: PwmOps> AlwaysRefCounted for Chip<T> {
     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]
@@ -695,7 +698,9 @@ unsafe fn dec_ref(obj: NonNull<Chip<T>>) {

         // 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);
+        }
     }
 }

@@ -727,11 +732,8 @@ impl<T: 'static + PwmOps + Send + Sync> Registration<T> {
     /// 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<Bound>,
-        chip: ARef<Chip<T>>,
-    ) -> Result {
-	let chip_parent = chip.device().parent().ok_or(EINVAL)?;
+    pub fn register(dev: &device::Device<Bound>, chip: ARef<Chip<T>>) -> Result {
+        let chip_parent = chip.device().parent().ok_or(EINVAL)?;
         if dev.as_raw() != chip_parent.as_raw() {
             return Err(EINVAL);
         }
@@ -757,6 +759,8 @@ fn drop(&mut self) {
         // 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);
+        }
     }
 }

base-commit: 04a698c800c25149f9aa379250e78f737adeb3f1
--
2.51.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pwm: fix Rust formatting
  2025-10-29 18:25 [PATCH] pwm: fix Rust formatting Miguel Ojeda
@ 2025-10-30 22:10 ` Uwe Kleine-König
  0 siblings, 0 replies; 2+ messages in thread
From: Uwe Kleine-König @ 2025-10-30 22:10 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Michal Wilczynski, Alex Gaynor, linux-pwm, rust-for-linux,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-kernel, patches

[-- Attachment #1: Type: text/plain, Size: 882 bytes --]

Hello,

On Wed, Oct 29, 2025 at 07:25:02PM +0100, Miguel Ojeda wrote:
> 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: a3d5a2b8da94 ("rust: pwm: Add complete abstraction layer")
> Fixes: 121931a7b4dc ("rust: pwm: Add Kconfig and basic data structures")
> Fixes: fb3957af9ec6 ("pwm: Add Rust driver for T-HEAD TH1520 SoC")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next
.

Thanks!
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-30 22:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29 18:25 [PATCH] pwm: fix Rust formatting Miguel Ojeda
2025-10-30 22:10 ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).