From nobody Sun Feb 8 22:49:09 2026 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 131C43328ED for ; Fri, 19 Dec 2025 17:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766163794; cv=none; b=EFkFCTb773GhdM1m01k4pTmuU54pXFs8Lqq0YZkwq02odx5TguVL4Qp2t1qz1PUahTOjVPpupnBBy4ahQHJy+JqC56xlj0BzX23Fq9anAkTrGT6rQYTkoxRZYGQObW3YxWn5d9MrWQ7WlTt2c+Rm1VLcDtbdvyR1ID8sPxzot9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766163794; c=relaxed/simple; bh=efsEAY5WuZhVB4BmfqXi5WRiTR8Oxn6NV6rPGVWEAOE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fgbhs/ryBMXWxpYTZUlXFkfGm+AmJ1Uq+jI+Nddi9m9/DhOaTp2R92hKFyCAMPFcEl8MiHajjdckmZo5mpq/KSL7POV8gAoEq2DxEtYgTeKrycAhpPQcF2a2/z976uXfrSuW0zXsOhU9ZGDQNU2AxA6ZTnYp/2ax+kqRfdI/TkY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aw3lC+lv; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aw3lC+lv" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-598f59996aaso2587105e87.1 for ; Fri, 19 Dec 2025 09:03:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766163790; x=1766768590; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pa9nztFG8VMOQ6dqwU2/oLzKHaOnP4dlHhzGZaw1gMs=; b=aw3lC+lv5QZY60WjAdxse/xAY7K4jqkKW7OYGeINPkEiwtPuBfjs5nPX3XiYSwhnaP BedccNwUgpKuL3UbhS7QHb/wmSX5zpn5fqPmNmvEUnmMd2EyiHiANzn3MCjyhRCIjj+g G6kAnufLMgMNOyR7sO8bK5oHTMki7h1+CymnS/6NPK5pLw+fnMjj/y/OrmBHR1ITy5bI lf9ONZetC+xCpY2v9ubL4e9FSTD0d7R6EHTSmi/lK1SpOKI6gmd2n28Vh7bW3hgVm0VV O+hlaKF2LZ3myjxWqb6Hs241AAYyRXGeHntIya/JfFfTXHFZ1SOtUFSn07dO7TMcx2i4 So3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766163790; x=1766768590; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=pa9nztFG8VMOQ6dqwU2/oLzKHaOnP4dlHhzGZaw1gMs=; b=cdO0vihT+lEqZGLtx7g9QhJ/kLLcC7fcX4lYfJG2nX3U4AtQcWd45I5A8DnyseuRkg JnPhVAKAugfjt1Wu1lAhASiGjCAsWSCLwcMeq59DgNPAP25ity6Y/HW8vfYnSt5MEX+f K6yJjnjgn1VQWAvaZOLkawbekCoFiSwyCxTv3YU17TB86LO2e7lU3dqz5LjNhr6s5GZi dtUf/Ha57WaMAc4naqdwSNM8frvDsfmHnn8qbna80HpCoKzK1psTuVvy+PZsr6JU6L/0 n0WxUedf9XIsBQjui9uVcMwQ048d4D4TEGl29pdEf65CT1HdJk+/wzTCy525nfQVjlcd pPYA== X-Forwarded-Encrypted: i=1; AJvYcCUAKILbMEkK09zHpRSxhrNnWaUnudi627VBJcuN4icn42Dms9SPMony4Ez5CvawMfmbdjlelumOcj9iQx8=@vger.kernel.org X-Gm-Message-State: AOJu0Yzyer5otbDZD6iaibabfA/VWd+oWhz+fgLakwsrrprnbtXhgKeC xJFeExTQ8nZ6TeM+mKE/B+u73HVj9dEqvbG5c5Rjv+VADHSSnfdrr20O X-Gm-Gg: AY/fxX76HWAaRHiVnxWlZRyCoJEShypjeKDiwm3EiIfH4wnfU0Ts6gSa4sfXFXviE24 DNG+9uze/m5Wy+ltvBHtYvyFwwveECOP+e66Qkxba6zwbiuJVJnWcRgpFpk9PhS4X+2PxUNB1mL Exv811M87bEsFuAInfaFwXpizYMjkIoVtZGsKbURIaa9UXubqzSTBQuMYHFnWX5Z5GkpoY1sCmw 7lPzhEZ2oMwFMipFlNKPKmuwSuzFtxnHTQzh202f9jIunlfSAIuCSR5bEe18ZsJnX64fnTdq7l1 IDCk1wyl181iFUmQWTmmvpm0s7AAGpbdYLykxdvB5VbWpvsl/pQvbaW6i9Lh5k0hQEq26YbCm2D xoXe1RDz4fFwcjPbzZhJgoSHvsaJVJ/gXH9i/6qi0gHUWibTTyFS1wxz++NyLJMRDc4H4FYQ9xe +EC3HKUCZD3KgkWn8JQAWmgYrfI/LijWgqWd9m2N7hMTH7hwwQHuCaagqbixDjXbeSwOnKAmGM5 KiGJg== X-Google-Smtp-Source: AGHT+IEkCBpl3eKd3d9brWpyXGg/JMPPKAqKU5igDnr8qX9hUH4DhfwKgcrVdyi1T4cSdd0ItDs2Nw== X-Received: by 2002:a05:6512:128c:b0:598:faf1:3c95 with SMTP id 2adb3069b0e04-59a17d46185mr1423702e87.36.1766163789863; Fri, 19 Dec 2025 09:03:09 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-208-48.bb.dnainternet.fi. [84.253.208.48]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59a18618d6fsm828449e87.65.2025.12.19.09.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Dec 2025 09:03:09 -0800 (PST) From: Kari Argillander Date: Fri, 19 Dec 2025 19:02:52 +0200 Subject: [PATCH 2/2] rust: pwm: Simplify to_result call sites and unsafe blocks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251219-pwm-rust-v1-2-46873e19679d@gmail.com> References: <20251219-pwm-rust-v1-0-46873e19679d@gmail.com> In-Reply-To: <20251219-pwm-rust-v1-0-46873e19679d@gmail.com> To: Michal Wilczynski , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: linux-pwm@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1766163785; l=6047; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=efsEAY5WuZhVB4BmfqXi5WRiTR8Oxn6NV6rPGVWEAOE=; b=Daw4DWf9oXGGg6sGSk+Pmokb46y0JxMbfO5poL/1f+cv48f5QlSZDdmc76HCJvGFxtIJVQ0x1 6Yy+r9MVu61AhK9w0hdmP3jpQyJdxiCS45zSlzD6NnuQhf5q1UN3uby X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Remove unnecessary temporary variables around to_result() calls and move trailing semicolons outside unsafe blocks to improve readability and produce cleaner rustfmt output. No functional change intended. Signed-off-by: Kari Argillander --- rust/kernel/pwm.rs | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs index 4b6a3b5ef929..3b6c72dcbd39 100644 --- a/rust/kernel/pwm.rs +++ b/rust/kernel/pwm.rs @@ -129,8 +129,7 @@ pub fn set_waveform(&self, wf: &Waveform, exact: bool) = -> Result { // SAFETY: `self.as_raw()` provides a valid `*mut pwm_device` poin= ter. // `&c_wf` is a valid pointer to a `pwm_waveform` struct. The C fu= nction // handles all necessary internal locking. - let ret =3D unsafe { bindings::pwm_set_waveform_might_sleep(self.a= s_raw(), &c_wf, exact) }; - to_result(ret) + to_result(unsafe { bindings::pwm_set_waveform_might_sleep(self.as_= raw(), &c_wf, exact) }) } =20 /// Queries the hardware for the configuration it would apply for a gi= ven @@ -160,9 +159,7 @@ pub fn get_waveform(&self) -> Result { =20 // SAFETY: `self.as_raw()` is a valid pointer. We provide a valid = pointer // to a stack-allocated `pwm_waveform` struct for the kernel to fi= ll. - let ret =3D unsafe { bindings::pwm_get_waveform_might_sleep(self.a= s_raw(), &mut c_wf) }; - - to_result(ret)?; + to_result(unsafe { bindings::pwm_get_waveform_might_sleep(self.as_= raw(), &mut c_wf) })?; =20 Ok(Waveform::from(c_wf)) } @@ -263,8 +260,8 @@ unsafe fn serialize_wfhw(wfhw: &T::WfHw, wfhw_ptr: *mut= c_void) -> Result { core::ptr::from_ref::(wfhw).cast::(), wfhw_ptr.cast::(), size, - ); - } + ) + }; =20 Ok(()) } @@ -284,8 +281,8 @@ unsafe fn deserialize_wfhw(wfhw_ptr: *const c_void) -> = Result { wfhw_ptr.cast::(), core::ptr::from_mut::(&mut wfhw).cast::(), size, - ); - } + ) + }; =20 Ok(wfhw) } @@ -311,9 +308,7 @@ unsafe fn deserialize_wfhw(wfhw_ptr: *const c_void) -> = Result { // Now, call the original release function to free the `pwm_chip` = itself. // SAFETY: `dev` is the valid pointer passed into this callback, w= hich is // the expected argument for `pwmchip_release`. - unsafe { - bindings::pwmchip_release(dev); - } + unsafe { bindings::pwmchip_release(dev) }; } =20 /// # Safety @@ -413,9 +408,7 @@ unsafe fn deserialize_wfhw(wfhw_ptr: *const c_void) -> = Result { match T::round_waveform_fromhw(chip, pwm, &wfhw, &mut rust_wf) { Ok(()) =3D> { // SAFETY: `wf_ptr` is guaranteed valid by the C caller. - unsafe { - *wf_ptr =3D rust_wf.into(); - }; + unsafe { *wf_ptr =3D rust_wf.into() }; 0 } Err(e) =3D> e.to_errno(), @@ -615,16 +608,12 @@ pub fn new<'a>( } =20 // SAFETY: `c_chip_ptr` points to a valid chip. - unsafe { - (*c_chip_ptr).dev.release =3D Some(Adapter::::release_callb= ack); - } + unsafe { (*c_chip_ptr).dev.release =3D Some(Adapter::::release_= callback) }; =20 // 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 =3D Adapter::::VTABLE.as_raw(); - } + unsafe { (*c_chip_ptr).ops =3D Adapter::::VTABLE.as_raw() }; =20 // Cast the `*mut bindings::pwm_chip` to `*mut Chip`. This is vali= d because // `Chip` is `repr(transparent)` over `Opaque`= , and @@ -646,9 +635,7 @@ unsafe impl AlwaysRefCounted for Chip { fn inc_ref(&self) { // SAFETY: `self.0.get()` points to a valid `pwm_chip` because `se= lf` exists. // The embedded `dev` is valid. `get_device` increments its refcou= nt. - unsafe { - bindings::get_device(&raw mut (*self.0.get()).dev); - } + unsafe { bindings::get_device(&raw mut (*self.0.get()).dev) }; } =20 #[inline] @@ -657,9 +644,7 @@ unsafe fn dec_ref(obj: NonNull>) { =20 // SAFETY: `obj` is a valid pointer to a `Chip` (and thus `binding= s::pwm_chip`) // with a non-zero refcount. `put_device` handles decrement and fi= nal release. - unsafe { - bindings::put_device(&raw mut (*c_chip_ptr).dev); - } + unsafe { bindings::put_device(&raw mut (*c_chip_ptr).dev) }; } } =20 @@ -693,9 +678,7 @@ pub fn register(self) -> Result>> { =20 // SAFETY: `c_chip_ptr` points to a valid chip with its ops initia= lized. // `__pwmchip_add` is the C function to register the chip with the= PWM core. - unsafe { - to_result(bindings::__pwmchip_add(c_chip_ptr, core::ptr::null_= mut()))?; - } + to_result(unsafe { bindings::__pwmchip_add(c_chip_ptr, core::ptr::= null_mut()) })?; =20 let registration =3D Registration { chip: ARef::clone(&self.chip), @@ -731,9 +714,7 @@ fn drop(&mut self) { // SAFETY: `chip_raw` points to a chip that was successfully regis= tered. // `bindings::pwmchip_remove` is the correct C function to unregis= ter it. // This `drop` implementation is called automatically by `devres` = on driver unbind. - unsafe { - bindings::pwmchip_remove(chip_raw); - } + unsafe { bindings::pwmchip_remove(chip_raw) }; } } =20 --=20 2.43.0