diff mbox series

net: stmmac: Fix signedness bug in stmmac_probe_config_dt()

Message ID 20200818143952.50752-1-yuehaibing@huawei.com
State Changes Requested
Delegated to: David Miller
Headers show
Series net: stmmac: Fix signedness bug in stmmac_probe_config_dt() | expand

Commit Message

Yue Haibing Aug. 18, 2020, 2:39 p.m. UTC
The "plat->phy_interface" variable is an enum and in this context GCC
will treat it as an unsigned int so the error handling is never
triggered.

Fixes: b9f0b2f634c0 ("net: stmmac: platform: fix probe for ACPI devices")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Schwab Aug. 18, 2020, 2:51 p.m. UTC | #1
On Aug 18 2020, YueHaibing wrote:

> The "plat->phy_interface" variable is an enum and in this context GCC
> will treat it as an unsigned int so the error handling is never
> triggered.
>
> Fixes: b9f0b2f634c0 ("net: stmmac: platform: fix probe for ACPI devices")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index f32317fa75c8..b5b558b02e7d 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -413,7 +413,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>  	}
>  
>  	plat->phy_interface = device_get_phy_mode(&pdev->dev);
> -	if (plat->phy_interface < 0)
> +	if ((int)plat->phy_interface < 0)
>  		return ERR_PTR(plat->phy_interface);

I don't think the conversion to long when passed to ERR_PTR will produce
a negative value either (if long is wider than unsigned int).

Andreas.
Yue Haibing Aug. 18, 2020, 3:15 p.m. UTC | #2
On 2020/8/18 22:51, Andreas Schwab wrote:
> On Aug 18 2020, YueHaibing wrote:
> 
>> The "plat->phy_interface" variable is an enum and in this context GCC
>> will treat it as an unsigned int so the error handling is never
>> triggered.
>>
>> Fixes: b9f0b2f634c0 ("net: stmmac: platform: fix probe for ACPI devices")
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>> ---
>>  drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
>> index f32317fa75c8..b5b558b02e7d 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
>> @@ -413,7 +413,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>>  	}
>>  
>>  	plat->phy_interface = device_get_phy_mode(&pdev->dev);
>> -	if (plat->phy_interface < 0)
>> +	if ((int)plat->phy_interface < 0)
>>  		return ERR_PTR(plat->phy_interface);
> 
> I don't think the conversion to long when passed to ERR_PTR will produce
> a negative value either (if long is wider than unsigned int).

Thanks, will respin.
> 
> Andreas.
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index f32317fa75c8..b5b558b02e7d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -413,7 +413,7 @@  stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 	}
 
 	plat->phy_interface = device_get_phy_mode(&pdev->dev);
-	if (plat->phy_interface < 0)
+	if ((int)plat->phy_interface < 0)
 		return ERR_PTR(plat->phy_interface);
 
 	plat->interface = stmmac_of_get_mac_mode(np);