[PATCH v3 02/11] driver/pci: Get next capability without passing caps

Jiqian Chen posted 11 patches 6 months, 1 week ago
There is a newer version of this series
[PATCH v3 02/11] driver/pci: Get next capability without passing caps
Posted by Jiqian Chen 6 months, 1 week ago
Modify function pci_find_next_cap_ttl to support returning position
of next capability when size "n" is zero.

That can help caller to get next capability offset if caller just
has a information of current capability offset.

That will be used in a follow-on change.

Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
---
cc: Andrew Cooper <andrew.cooper3@citrix.com>
cc: Anthony PERARD <anthony.perard@vates.tech>
cc: Michal Orzel <michal.orzel@amd.com>
cc: Jan Beulich <jbeulich@suse.com>
cc: Julien Grall <julien@xen.org>
cc: "Roger Pau Monné" <roger.pau@citrix.com>
cc: Stefano Stabellini <sstabellini@kernel.org>
---
v2->v3 changes:
* Only check if n == 0 and add assertion for array "caps".
* Not to change pci_find_next_cap_ttl definition.

v1->v2 changes:
new patch.

Best regards,
Jiqian Chen.
---
 xen/drivers/pci/pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/xen/drivers/pci/pci.c b/xen/drivers/pci/pci.c
index edf5b9f7ae9f..804f4e1e6066 100644
--- a/xen/drivers/pci/pci.c
+++ b/xen/drivers/pci/pci.c
@@ -55,6 +55,9 @@ unsigned int pci_find_next_cap_ttl(pci_sbdf_t sbdf, unsigned int pos,
 
         if ( id == 0xff )
             break;
+        if ( n == 0 )
+            return pos;
+        ASSERT(caps);
         for ( i = 0; i < n; i++ )
         {
             if ( id == caps[i] )
-- 
2.34.1


Re: [PATCH v3 02/11] driver/pci: Get next capability without passing caps
Posted by Jan Beulich 6 months, 1 week ago
On 21.04.2025 08:18, Jiqian Chen wrote:
> Modify function pci_find_next_cap_ttl to support returning position
> of next capability when size "n" is zero.
> 
> That can help caller to get next capability offset if caller just
> has a information of current capability offset.
> 
> That will be used in a follow-on change.
> 
> Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
albeit ...

> --- a/xen/drivers/pci/pci.c
> +++ b/xen/drivers/pci/pci.c
> @@ -55,6 +55,9 @@ unsigned int pci_find_next_cap_ttl(pci_sbdf_t sbdf, unsigned int pos,
>  
>          if ( id == 0xff )
>              break;
> +        if ( n == 0 )
> +            return pos;
> +        ASSERT(caps);
>          for ( i = 0; i < n; i++ )
>          {
>              if ( id == caps[i] )

... blank lines around you insertion might have been nice. I may take the
liberty of adding them while committing.

Jan
Re: [PATCH v3 02/11] driver/pci: Get next capability without passing caps
Posted by Chen, Jiqian 6 months, 1 week ago
On 2025/4/22 23:59, Jan Beulich wrote:
> On 21.04.2025 08:18, Jiqian Chen wrote:
>> Modify function pci_find_next_cap_ttl to support returning position
>> of next capability when size "n" is zero.
>>
>> That can help caller to get next capability offset if caller just
>> has a information of current capability offset.
>>
>> That will be used in a follow-on change.
>>
>> Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
> 
> Acked-by: Jan Beulich <jbeulich@suse.com>
Thank you.

> albeit ...
> 
>> --- a/xen/drivers/pci/pci.c
>> +++ b/xen/drivers/pci/pci.c
>> @@ -55,6 +55,9 @@ unsigned int pci_find_next_cap_ttl(pci_sbdf_t sbdf, unsigned int pos,
>>  
>>          if ( id == 0xff )
>>              break;
>> +        if ( n == 0 )
>> +            return pos;
>> +        ASSERT(caps);
>>          for ( i = 0; i < n; i++ )
>>          {
>>              if ( id == caps[i] )
> 
> ... blank lines around you insertion might have been nice. I may take the
> liberty of adding them while committing.
That's fine, please add.

> 
> Jan

-- 
Best regards,
Jiqian Chen.