lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D8GWCWYM15WI.3II7R71LIAEI9@nvidia.com>
Date: Sat, 15 Mar 2025 23:07:44 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Benno Lossin" <benno.lossin@...ton.me>, "Danilo Krummrich"
 <dakr@...nel.org>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
 <alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
 <gary@...yguo.net>, Björn Roy Baron
 <bjorn3_gh@...tonmail.com>, "Andreas Hindborg" <a.hindborg@...nel.org>,
 "Alice Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
 <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] rust/revocable: add try_with() convenience method

On Fri Mar 14, 2025 at 2:50 AM JST, Benno Lossin wrote:
> On Thu Mar 13, 2025 at 4:48 PM CET, Danilo Krummrich wrote:
>> On Thu, Mar 13, 2025 at 03:38:55PM +0000, Benno Lossin wrote:
>>> On Thu Mar 13, 2025 at 4:08 PM CET, Alexandre Courbot wrote:
>>> > On Thu Mar 13, 2025 at 11:19 PM JST, Benno Lossin wrote:
>>> >> Would it make sense to not use `Result` here and continue with `Option`?
>>> >
>>> > We would have to return an Option<Result<R>> in this case. The current
>>> > code folds the closure's Result into the one of the guard's acquisition
>>> > for convenience.
>>> >
>>> > Actually, I don't think I have ever used try_access() a single time
>>> > without converting its returned Option into a Result. Wouldn't it make
>>> > sense to do the opposite, i.e. make try_access() return Err(ENXIO) when
>>> > the guard cannot be acquired and document this behavior?
>>> 
>>> Sure, if you're always doing
>>> 
>>>     let guard = rev.try_access().ok_or(ENXIO)?;
>>> 
>>> Then it makes sense from my view, maybe Danilo has some other argument
>>> for why `Option` is better.
>>
>> Most of the time I think we indeed want to derive an Err() if try_access()
>> fails, but not with a specific error code. The error code depends on the context
>> of where the revocable is used (e.g. for I/O mappings), but it also depends on
>> the driver semantics.
>
> In that case a single function with this signature would make sense:
>
>     fn access_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>;
>
> If there are common usages that always return the same error code, then
> we could add them as functions with `Result`.

Yeah the more I think about it the more this seems to make sense,
from a strictly logical point of view.

Where I am still on the fence is that the goal is also to reduce the
friction introduced by the Revocable business, which a large driver
might need to interact with hundreds of times. If the user wants the
callback to return a Result, then this method will return an
Option<Result>. One would then need to ok_or the Option, then flatten
the two results, which is a bit verbose.

I suppose drivers could add their own macros to do that automatically
and reduce code verbosity, at the cost of less cohesion across drivers.
Guess I'll go with that if I cannot come with anything better.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ