Re: [PATCH] poll: rust: allow poll_table ptrs to be null

From: Benno Lossin
Date: Sun Jun 22 2025 - 03:50:32 EST


On Fri Jun 20, 2025 at 3:19 PM CEST, Alice Ryhl wrote:
> On Fri, Jun 20, 2025 at 2:31 PM Benno Lossin <lossin@xxxxxxxxxx> wrote:
>>
>> On Fri Jun 20, 2025 at 1:49 PM CEST, Alice Ryhl wrote:
>> > ///
>> > /// # Safety
>> > ///
>> > - /// The caller must ensure that for the duration of `'a`, the pointer will point at a valid poll
>> > - /// table (as defined in the type invariants).
>> > - ///
>> > - /// The caller must also ensure that the `poll_table` is only accessed via the returned
>> > - /// reference for the duration of `'a`.
>> > - pub unsafe fn from_ptr<'a>(ptr: *mut bindings::poll_table) -> &'a mut PollTable {
>>
>> Returning `Option<&'a mut PollTable>` is not an option? I'd like to
>> avoid wrapping raw pointers...
>
> You're going to make people handle the Option by early-returning if
> you do that, but that's wrong. You're supposed to treat null and
> non-null the same.

Ah right...

An `PollTableInner` type that wraps the `bindings::poll_table` opaquely
sounds like too much work, so let's go with your approach.

---
Cheers,
Benno