Re: [PATCH v2 01/31] rust: pci: add domain_nr() accessor
From: Alexandre Courbot
Date: Sat Aug 22 2026 - 20:09:02 EST
On Sun Aug 23, 2026 at 5:11 AM JST, John Hubbard wrote:
> On 8/22/26 12:57 AM, Miguel Ojeda wrote:
>> On Sat, Aug 22, 2026 at 3:55 AM John Hubbard <jhubbard@xxxxxxxxxx> wrote:
>>>
>>> + // CAST: The C function returns `int`, but a PCI domain number is always
>>> + // non-negative, so this cast will not lose any information.
>>> + domain_nr as u32
>>
>> What about
>>
>> debug_assert!(domain_nr >= 0);
>>
>> ?
>
> Yes, good idea. That's appropriate because the PCI core on the C side
> provides a positive domain number, and the Rust side can assert that
> that continues to be true.
>
> I'll add it right after the "let domain_nr..." statement, when I send
> the next version.
>
> (Although I would like to figure out some way to get this in ahead of
> things, one way or another.)
Since this is a very similar case I thought that maybe we can fix the C
API to return an unsigned like we did in [1], but things appear to be a
bit more intricate here and a negative number is (temporarily) stored at
least once (`PCI_DOMAIN_NR_NOT_SET`).
So indeed `debug_assert` sounds like the right call (and maybe we should
have one in [2] as well)
[1] https://patch.msgid.link/20260722073913.1807677-2-zhiw@xxxxxxxxxx
[2] https://patch.msgid.link/20260722073913.1807677-3-zhiw@xxxxxxxxxx