[PATCH] xen/arm: pci: fix -Wtype-limits warning in pci-host-common.c

Stewart Hildebrand posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20230503191820.78322-1-stewart.hildebrand@amd.com
xen/arch/arm/pci/pci-host-common.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] xen/arm: pci: fix -Wtype-limits warning in pci-host-common.c
Posted by Stewart Hildebrand 1 year ago
When building with EXTRA_CFLAGS_XEN_CORE="-Wtype-limits", we observe the
following warning:

arch/arm/pci/pci-host-common.c: In function ‘pci_host_common_probe’:
arch/arm/pci/pci-host-common.c:238:26: warning: comparison is always false due to limited range of data type [-Wtype-limits]
  238 |     if ( bridge->segment < 0 )
      |                          ^

This is due to bridge->segment being an unsigned type. Fix it by introducing a
new variable of signed type to use in the condition.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
 xen/arch/arm/pci/pci-host-common.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
index a8ece94303ca..7474d877deb8 100644
--- a/xen/arch/arm/pci/pci-host-common.c
+++ b/xen/arch/arm/pci/pci-host-common.c
@@ -214,6 +214,7 @@ int pci_host_common_probe(struct dt_device_node *dev,
     struct pci_host_bridge *bridge;
     struct pci_config_window *cfg;
     int err;
+    int domain;
 
     if ( dt_device_for_passthrough(dev) )
         return 0;
@@ -234,12 +235,13 @@ int pci_host_common_probe(struct dt_device_node *dev,
     bridge->cfg = cfg;
     bridge->ops = &ops->pci_ops;
 
-    bridge->segment = pci_bus_find_domain_nr(dev);
-    if ( bridge->segment < 0 )
+    domain = pci_bus_find_domain_nr(dev);
+    if ( domain < 0 )
     {
         printk(XENLOG_ERR "Inconsistent \"linux,pci-domain\" property in DT\n");
         BUG();
     }
+    bridge->segment = domain;
     pci_add_host_bridge(bridge);
 
     return 0;
-- 
2.40.1


Re: [PATCH] xen/arm: pci: fix -Wtype-limits warning in pci-host-common.c
Posted by Rahul Singh 1 year ago
Hi Stewart,

On 3 May 2023, at 8:18 pm, Stewart Hildebrand <Stewart.Hildebrand@amd.com> wrote:

When building with EXTRA_CFLAGS_XEN_CORE="-Wtype-limits", we observe the
following warning:

arch/arm/pci/pci-host-common.c: In function ‘pci_host_common_probe’:
arch/arm/pci/pci-host-common.c:238:26: warning: comparison is always false due to limited range of data type [-Wtype-limits]
 238 |     if ( bridge->segment < 0 )
     |                          ^

This is due to bridge->segment being an unsigned type. Fix it by introducing a
new variable of signed type to use in the condition.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>

Reviewed-by: Rahul Singh <rahul.singh@arm.com<mailto:rahul.singh@arm.com>>

Regards,
Rahul

Re: [PATCH] xen/arm: pci: fix -Wtype-limits warning in pci-host-common.c
Posted by Bertrand Marquis 1 year ago
Hi Stewart,

> On 3 May 2023, at 21:18, Stewart Hildebrand <Stewart.Hildebrand@amd.com> wrote:
> 
> When building with EXTRA_CFLAGS_XEN_CORE="-Wtype-limits", we observe the
> following warning:
> 
> arch/arm/pci/pci-host-common.c: In function ‘pci_host_common_probe’:
> arch/arm/pci/pci-host-common.c:238:26: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>  238 |     if ( bridge->segment < 0 )
>      |                          ^
> 
> This is due to bridge->segment being an unsigned type. Fix it by introducing a
> new variable of signed type to use in the condition.
> 
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>

I would see this as a bug fix more than a compiler warning fix as the error code was
ignored before that.

Anyway:
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>

Cheers
Bertrand


> ---
> xen/arch/arm/pci/pci-host-common.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
> index a8ece94303ca..7474d877deb8 100644
> --- a/xen/arch/arm/pci/pci-host-common.c
> +++ b/xen/arch/arm/pci/pci-host-common.c
> @@ -214,6 +214,7 @@ int pci_host_common_probe(struct dt_device_node *dev,
>     struct pci_host_bridge *bridge;
>     struct pci_config_window *cfg;
>     int err;
> +    int domain;
> 
>     if ( dt_device_for_passthrough(dev) )
>         return 0;
> @@ -234,12 +235,13 @@ int pci_host_common_probe(struct dt_device_node *dev,
>     bridge->cfg = cfg;
>     bridge->ops = &ops->pci_ops;
> 
> -    bridge->segment = pci_bus_find_domain_nr(dev);
> -    if ( bridge->segment < 0 )
> +    domain = pci_bus_find_domain_nr(dev);
> +    if ( domain < 0 )
>     {
>         printk(XENLOG_ERR "Inconsistent \"linux,pci-domain\" property in DT\n");
>         BUG();
>     }
> +    bridge->segment = domain;
>     pci_add_host_bridge(bridge);
> 
>     return 0;
> -- 
> 2.40.1
> 

Re: [PATCH] xen/arm: pci: fix -Wtype-limits warning in pci-host-common.c
Posted by Julien Grall 1 year ago
Hi,

On 04/05/2023 09:59, Bertrand Marquis wrote:
> Hi Stewart,
> 
>> On 3 May 2023, at 21:18, Stewart Hildebrand <Stewart.Hildebrand@amd.com> wrote:
>>
>> When building with EXTRA_CFLAGS_XEN_CORE="-Wtype-limits", we observe the
>> following warning:
>>
>> arch/arm/pci/pci-host-common.c: In function ‘pci_host_common_probe’:
>> arch/arm/pci/pci-host-common.c:238:26: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>>   238 |     if ( bridge->segment < 0 )
>>       |                          ^
>>
>> This is due to bridge->segment being an unsigned type. Fix it by introducing a
>> new variable of signed type to use in the condition.
>>
>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
> 
> I would see this as a bug fix more than a compiler warning fix as the error code was
> ignored before that.

+1. Also there is a missing fixes tag. AFAICT this issue was introduced 
by 6ec9176d94ae.

> 
> Anyway:
> Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>

Just to clarify, you are happy with the current commit message? If so, I 
can commit it later on with the Reviewed-by + fixes tag.

Cheers,

-- 
Julien Grall

Re: [PATCH] xen/arm: pci: fix -Wtype-limits warning in pci-host-common.c
Posted by Bertrand Marquis 1 year ago
Hi,

> On 4 May 2023, at 12:10, Julien Grall <julien@xen.org> wrote:
> 
> Hi,
> 
> On 04/05/2023 09:59, Bertrand Marquis wrote:
>> Hi Stewart,
>>> On 3 May 2023, at 21:18, Stewart Hildebrand <Stewart.Hildebrand@amd.com> wrote:
>>> 
>>> When building with EXTRA_CFLAGS_XEN_CORE="-Wtype-limits", we observe the
>>> following warning:
>>> 
>>> arch/arm/pci/pci-host-common.c: In function ‘pci_host_common_probe’:
>>> arch/arm/pci/pci-host-common.c:238:26: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>>>  238 |     if ( bridge->segment < 0 )
>>>      |                          ^
>>> 
>>> This is due to bridge->segment being an unsigned type. Fix it by introducing a
>>> new variable of signed type to use in the condition.
>>> 
>>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
>> I would see this as a bug fix more than a compiler warning fix as the error code was
>> ignored before that.
> 
> +1. Also there is a missing fixes tag. AFAICT this issue was introduced by 6ec9176d94ae.
> 
>> Anyway:
>> Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
> 
> Just to clarify, you are happy with the current commit message? If so, I can commit it later on with the Reviewed-by + fixes tag.

Would be nice to add the proper fixes flag if you can do it on commit :-)

Cheers
Bertrand

> 
> Cheers,
> 
> -- 
> Julien Grall


Re: [PATCH] xen/arm: pci: fix -Wtype-limits warning in pci-host-common.c
Posted by Julien Grall 11 months, 4 weeks ago
Hi,

On 04/05/2023 11:32, Bertrand Marquis wrote:
> Hi,
> 
>> On 4 May 2023, at 12:10, Julien Grall <julien@xen.org> wrote:
>>
>> Hi,
>>
>> On 04/05/2023 09:59, Bertrand Marquis wrote:
>>> Hi Stewart,
>>>> On 3 May 2023, at 21:18, Stewart Hildebrand <Stewart.Hildebrand@amd.com> wrote:
>>>>
>>>> When building with EXTRA_CFLAGS_XEN_CORE="-Wtype-limits", we observe the
>>>> following warning:
>>>>
>>>> arch/arm/pci/pci-host-common.c: In function ‘pci_host_common_probe’:
>>>> arch/arm/pci/pci-host-common.c:238:26: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>>>>   238 |     if ( bridge->segment < 0 )
>>>>       |                          ^
>>>>
>>>> This is due to bridge->segment being an unsigned type. Fix it by introducing a
>>>> new variable of signed type to use in the condition.
>>>>
>>>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
>>> I would see this as a bug fix more than a compiler warning fix as the error code was
>>> ignored before that.
>>
>> +1. Also there is a missing fixes tag. AFAICT this issue was introduced by 6ec9176d94ae.
>>
>>> Anyway:
>>> Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
>>
>> Just to clarify, you are happy with the current commit message? If so, I can commit it later on with the Reviewed-by + fixes tag.
> 
> Would be nice to add the proper fixes flag if you can do it on commit :-)

Sorry for the late. This is now committed.

Cheers,

-- 
Julien Grall