Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: pwm: Simplify to_result call sites and unsafe blocks

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 <kari.argillander@gmail.com>
Acked-by: Michal Wilczynski <m.wilczynski@samsung.com>
Link: https://patch.msgid.link/20260102-pwm-rust-v2-2-2702ce57d571@gmail.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Kari Argillander and committed by
Uwe Kleine-König
fc1e4eae a2633dc2

+14 -33
+14 -33
rust/kernel/pwm.rs
··· 129 129 // SAFETY: `self.as_raw()` provides a valid `*mut pwm_device` pointer. 130 130 // `&c_wf` is a valid pointer to a `pwm_waveform` struct. The C function 131 131 // handles all necessary internal locking. 132 - let ret = unsafe { bindings::pwm_set_waveform_might_sleep(self.as_raw(), &c_wf, exact) }; 133 - to_result(ret) 132 + to_result(unsafe { bindings::pwm_set_waveform_might_sleep(self.as_raw(), &c_wf, exact) }) 134 133 } 135 134 136 135 /// Queries the hardware for the configuration it would apply for a given ··· 159 160 160 161 // SAFETY: `self.as_raw()` is a valid pointer. We provide a valid pointer 161 162 // to a stack-allocated `pwm_waveform` struct for the kernel to fill. 162 - let ret = unsafe { bindings::pwm_get_waveform_might_sleep(self.as_raw(), &mut c_wf) }; 163 - 164 - to_result(ret)?; 163 + to_result(unsafe { bindings::pwm_get_waveform_might_sleep(self.as_raw(), &mut c_wf) })?; 165 164 166 165 Ok(Waveform::from(c_wf)) 167 166 } ··· 260 263 core::ptr::from_ref::<T::WfHw>(wfhw).cast::<u8>(), 261 264 wfhw_ptr.cast::<u8>(), 262 265 size, 263 - ); 264 - } 266 + ) 267 + }; 265 268 266 269 Ok(()) 267 270 } ··· 281 284 wfhw_ptr.cast::<u8>(), 282 285 core::ptr::from_mut::<T::WfHw>(&mut wfhw).cast::<u8>(), 283 286 size, 284 - ); 285 - } 287 + ) 288 + }; 286 289 287 290 Ok(wfhw) 288 291 } ··· 308 311 // Now, call the original release function to free the `pwm_chip` itself. 309 312 // SAFETY: `dev` is the valid pointer passed into this callback, which is 310 313 // the expected argument for `pwmchip_release`. 311 - unsafe { 312 - bindings::pwmchip_release(dev); 313 - } 314 + unsafe { bindings::pwmchip_release(dev) }; 314 315 } 315 316 316 317 /// # Safety ··· 408 413 match T::round_waveform_fromhw(chip, pwm, &wfhw, &mut rust_wf) { 409 414 Ok(()) => { 410 415 // SAFETY: `wf_ptr` is guaranteed valid by the C caller. 411 - unsafe { 412 - *wf_ptr = rust_wf.into(); 413 - }; 416 + unsafe { *wf_ptr = rust_wf.into() }; 414 417 0 415 418 } 416 419 Err(e) => e.to_errno(), ··· 607 614 })?; 608 615 609 616 // SAFETY: `c_chip_ptr` points to a valid chip. 610 - unsafe { 611 - (*c_chip_ptr).dev.release = Some(Adapter::<T>::release_callback); 612 - } 617 + unsafe { (*c_chip_ptr).dev.release = Some(Adapter::<T>::release_callback) }; 613 618 614 619 // SAFETY: `c_chip_ptr` points to a valid chip. 615 620 // The `Adapter`'s `VTABLE` has a 'static lifetime, so the pointer 616 621 // returned by `as_raw()` is always valid. 617 - unsafe { 618 - (*c_chip_ptr).ops = Adapter::<T>::VTABLE.as_raw(); 619 - } 622 + unsafe { (*c_chip_ptr).ops = Adapter::<T>::VTABLE.as_raw() }; 620 623 621 624 // Cast the `*mut bindings::pwm_chip` to `*mut Chip`. This is valid because 622 625 // `Chip` is `repr(transparent)` over `Opaque<bindings::pwm_chip>`, and ··· 634 645 fn inc_ref(&self) { 635 646 // SAFETY: `self.0.get()` points to a valid `pwm_chip` because `self` exists. 636 647 // The embedded `dev` is valid. `get_device` increments its refcount. 637 - unsafe { 638 - bindings::get_device(&raw mut (*self.0.get()).dev); 639 - } 648 + unsafe { bindings::get_device(&raw mut (*self.0.get()).dev) }; 640 649 } 641 650 642 651 #[inline] ··· 643 656 644 657 // SAFETY: `obj` is a valid pointer to a `Chip` (and thus `bindings::pwm_chip`) 645 658 // with a non-zero refcount. `put_device` handles decrement and final release. 646 - unsafe { 647 - bindings::put_device(&raw mut (*c_chip_ptr).dev); 648 - } 659 + unsafe { bindings::put_device(&raw mut (*c_chip_ptr).dev) }; 649 660 } 650 661 } 651 662 ··· 677 692 678 693 // SAFETY: `c_chip_ptr` points to a valid chip with its ops initialized. 679 694 // `__pwmchip_add` is the C function to register the chip with the PWM core. 680 - unsafe { 681 - to_result(bindings::__pwmchip_add(c_chip_ptr, core::ptr::null_mut()))?; 682 - } 695 + to_result(unsafe { bindings::__pwmchip_add(c_chip_ptr, core::ptr::null_mut()) })?; 683 696 684 697 let registration = Registration { 685 698 chip: ARef::clone(&self.chip), ··· 713 730 // SAFETY: `chip_raw` points to a chip that was successfully registered. 714 731 // `bindings::pwmchip_remove` is the correct C function to unregister it. 715 732 // This `drop` implementation is called automatically by `devres` on driver unbind. 716 - unsafe { 717 - bindings::pwmchip_remove(chip_raw); 718 - } 733 + unsafe { bindings::pwmchip_remove(chip_raw) }; 719 734 } 720 735 } 721 736