Re: [PATCH v2 01/31] rust: pci: add domain_nr() accessor

"Alexandre Courbot" <[email protected]>
Newsgroups dev.linux.lists.nova-gpu,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
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 <[email protected]> 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/[email protected]
[2] https://patch.msgid.link/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.