From: Daniel Almeida <daniel.almeida@collabora.com>
To: "Onur Özkan" <work@onurozkan.dev>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
daniel@sedlak.dev, dirk.behme@de.bosch.com, felipe_life@live.com,
tamird@gmail.com, dakr@kernel.org, tmgross@umich.edu,
aliceryhl@google.com, a.hindborg@kernel.org, lossin@kernel.org,
bjorn3_gh@protonmail.com, gary@garyguo.net, boqun.feng@gmail.com,
alex.gaynor@gmail.com, ojeda@kernel.org
Subject: Re: [PATCH v2 1/1] rust: refactor to_result to return the original value
Date: Tue, 9 Sep 2025 15:25:55 -0300 [thread overview]
Message-ID: <468A76F2-FC02-4B54-974B-7C52D946ECEB@collabora.com> (raw)
In-Reply-To: <20250909204308.74ccedf4@nimda.home>
Onur,
> On 9 Sep 2025, at 14:43, Onur Özkan <work@onurozkan.dev> wrote:
>
> On Tue, 9 Sep 2025 19:17:56 +0200
> Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
>
>> On Tue, Sep 9, 2025 at 7:01 PM Onur Özkan <work@onurozkan.dev> wrote:
>>>
>>> This patch only fixes the callers that broke after the changes on
>>> `to_result`. I haven't included all the improvements made possible
>>> by the new design since
>>
>> I think Daniel asked in the previous version what you mean by "callers
>> that broke" here -- it is a bit confusing, since it seems this is a
>> fix (and thus needs to be prioritized).
>>
>> Is that the case?
>>
>> Thanks!
>>
>> Cheers,
>> Miguel
>
> What I meant is that the change on `to_result` signature introduced a
> breaking change so I had to update its callers accordingly.
>
> The fix I mentioned in this version is a different matter.
>
> Before the rebase, the regulator module had a get_voltage function like
> this:
>
> let voltage = unsafe {...};
>
> if voltage < 0 {
> Err(...)
> } else {
> Ok(Voltage::from_microvolts(voltage))
> }
>
> But on the regulator/for-next branch, a patch was applied that changed
> it to:
>
> let voltage = unsafe {...};
> to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
>
> That change was incompatible with v1 (due to the different signature of
> to_result), which fails to build with my patch. This version (v2)
> fixes the issue introduced in v1.
Fixes what issue? What is the actual problem being addressed here?
It looks like a mere change from
to_result(…) and,
to_result(…).map()
To:
to_result(…)?;
Ok(())
and
- let voltage = unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) };
-
- to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
+ to_result(unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) })
+ .map(Voltage::from_microvolts)
}
>
> Sorry for the confusion, I hope it's more clear now.
>
> Thanks,
> Onur
>
Your last regulator patch was minor, correct, and was picked up (merged). It
cleared up an if/else, so that was an improvement.
I now see yet another change, doing apparently the same thing (correct me if
I’m wrong) in a slightly different way, in a patch that now has your previous regulator
patch as a dependency.
So my question is, why do we need this?
diff --git a/rust/kernel/regulator.rsb/rust/kernel/regulator.rs
index 34bb24ec8d4d..a5f357bda6e9 100644
--- a/rust/kernel/regulator.rs
+++ b/rust/kernel/regulator.rs
@@ -260,15 +260,15 @@ pub fn set_voltage(&self, min_voltage: Voltage, max_voltage: Voltage) -> Result
min_voltage.as_microvolts(),
max_voltage.as_microvolts(),
)
- })
+ })?;
+ Ok(())
}
/// Gets the current voltage of the regulator.
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()) };
-
- to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
+ to_result(unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) })
+ .map(Voltage::from_microvolts)
}
fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
@@ -288,12 +288,14 @@ fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
fn enable_internal(&self) -> Result {
// SAFETY: Safe as per the type invariants of `Regulator`.
- to_result(unsafe { bindings::regulator_enable(self.inner.as_ptr()) })
+ to_result(unsafe { bindings::regulator_enable(self.inner.as_ptr()) })?;
+ Ok(())
}
fn disable_internal(&self) -> Result {
// SAFETY: Safe as per the type invariants of `Regulator`.
- to_result(unsafe { bindings::regulator_disable(self.inner.as_ptr()) })
+ to_result(unsafe { bindings::regulator_disable(self.inner.as_ptr()) })?;
+ Ok(())
}
— Daniel
next prev parent reply other threads:[~2025-09-09 18:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 17:00 [PATCH v2 0/1] " Onur Özkan
2025-09-09 17:00 ` [PATCH v2 1/1] " Onur Özkan
2025-09-09 17:17 ` Miguel Ojeda
2025-09-09 17:43 ` Onur Özkan
2025-09-09 18:25 ` Onur
2025-09-09 18:25 ` Daniel Almeida [this message]
2025-09-09 18:53 ` Onur Özkan
2025-09-09 20:13 ` Daniel Almeida
2025-09-09 20:05 ` Miguel Ojeda
2025-09-09 20:12 ` Daniel Almeida
2025-09-09 20:25 ` Miguel Ojeda
2025-09-10 4:50 ` Onur Özkan
2025-09-10 6:26 ` Alice Ryhl
2025-09-10 10:58 ` Onur Özkan
2025-09-10 11:05 ` Alice Ryhl
2025-09-10 12:47 ` Onur Özkan
2025-09-10 12:50 ` Alice Ryhl
2025-09-10 12:55 ` Onur Özkan
2025-09-12 8:41 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=468A76F2-FC02-4B54-974B-7C52D946ECEB@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel@sedlak.dev \
--cc=dirk.behme@de.bosch.com \
--cc=felipe_life@live.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@gmail.com \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®