* [PATCH] rust: regulator: use `to_result` for error handling
@ 2025-08-21 9:07 Onur Özkan
2025-08-27 18:06 ` Daniel Almeida
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Onur Özkan @ 2025-08-21 9:07 UTC (permalink / raw)
To: rust-for-linux
Cc: lgirdwood, broonie, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
linux-kernel, Onur Özkan
Simplifies error handling by replacing the manual check
of the return value with the `to_result` helper.
Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
rust/kernel/regulator.rs | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs
index 65f3a125348f..73ad4ad4747d 100644
--- a/rust/kernel/regulator.rs
+++ b/rust/kernel/regulator.rs
@@ -267,11 +267,8 @@ pub fn set_voltage(&self, min_voltage: Voltage, max_voltage: Voltage) -> Result
pub fn get_voltage(&self) -> Result<Voltage> {
// SAFETY: Safe as per the type invariants of `Regulator`.
let voltage = unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) };
- if voltage < 0 {
- Err(kernel::error::Error::from_errno(voltage))
- } else {
- Ok(Voltage::from_microvolts(voltage))
- }
+
+ to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
}
fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
--
2.50.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: regulator: use `to_result` for error handling
2025-08-21 9:07 [PATCH] rust: regulator: use `to_result` for error handling Onur Özkan
@ 2025-08-27 18:06 ` Daniel Almeida
2025-08-28 10:15 ` Miguel Ojeda
2025-08-28 14:02 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Almeida @ 2025-08-27 18:06 UTC (permalink / raw)
To: Onur Özkan
Cc: rust-for-linux, lgirdwood, broonie, ojeda, alex.gaynor,
boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, linux-kernel
> On 21 Aug 2025, at 06:07, Onur Özkan <work@onurozkan.dev> wrote:
>
> Simplifies error handling by replacing the manual check
> of the return value with the `to_result` helper.
>
> Signed-off-by: Onur Özkan <work@onurozkan.dev>
> ---
> rust/kernel/regulator.rs | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs
> index 65f3a125348f..73ad4ad4747d 100644
> --- a/rust/kernel/regulator.rs
> +++ b/rust/kernel/regulator.rs
> @@ -267,11 +267,8 @@ pub fn set_voltage(&self, min_voltage: Voltage, max_voltage: Voltage) -> Result
> pub fn get_voltage(&self) -> Result<Voltage> {
> // SAFETY: Safe as per the type invariants of `Regulator`.
> let voltage = unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) };
> - if voltage < 0 {
> - Err(kernel::error::Error::from_errno(voltage))
> - } else {
> - Ok(Voltage::from_microvolts(voltage))
> - }
> +
> + to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
> }
>
> fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
> —
> 2.50.0
>
>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: regulator: use `to_result` for error handling
2025-08-21 9:07 [PATCH] rust: regulator: use `to_result` for error handling Onur Özkan
2025-08-27 18:06 ` Daniel Almeida
@ 2025-08-28 10:15 ` Miguel Ojeda
2025-08-28 14:02 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2025-08-28 10:15 UTC (permalink / raw)
To: Onur Özkan
Cc: rust-for-linux, lgirdwood, broonie, ojeda, alex.gaynor,
boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, linux-kernel
On Thu, Aug 21, 2025 at 11:08 AM Onur Özkan <work@onurozkan.dev> wrote:
>
> - if voltage < 0 {
> - Err(kernel::error::Error::from_errno(voltage))
> - } else {
> - Ok(Voltage::from_microvolts(voltage))
> - }
> +
> + to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
No big deal either way, but our usual idiom for this so far is:
to_result(voltage)?;
Ok(Voltage::from_microvolts(voltage))
which, in a way, uses early return to put the happy path in a less
indented / more visible place.
(I noticed a few similar patches lately)
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: regulator: use `to_result` for error handling
2025-08-21 9:07 [PATCH] rust: regulator: use `to_result` for error handling Onur Özkan
2025-08-27 18:06 ` Daniel Almeida
2025-08-28 10:15 ` Miguel Ojeda
@ 2025-08-28 14:02 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-08-28 14:02 UTC (permalink / raw)
To: rust-for-linux, Onur Özkan
Cc: lgirdwood, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
lossin, a.hindborg, aliceryhl, tmgross, dakr, linux-kernel
On Thu, 21 Aug 2025 12:07:20 +0300, Onur Özkan wrote:
> Simplifies error handling by replacing the manual check
> of the return value with the `to_result` helper.
>
>
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
Thanks!
[1/1] rust: regulator: use `to_result` for error handling
commit: e2ab5f600bb01d3625d667d97b3eb7538e388336
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-28 14:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 9:07 [PATCH] rust: regulator: use `to_result` for error handling Onur Özkan
2025-08-27 18:06 ` Daniel Almeida
2025-08-28 10:15 ` Miguel Ojeda
2025-08-28 14:02 ` Mark Brown
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).