diff mbox series

[next] PCI: tegra: tegra194: fix phy_count less than zero check

Message ID 20190821120123.14223-1-colin.king@canonical.com
State Accepted
Headers show
Series [next] PCI: tegra: tegra194: fix phy_count less than zero check | expand

Commit Message

Colin Ian King Aug. 21, 2019, 12:01 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The check for pcie->phy_count < 0 is always false because phy_count
is an unsigned int and can never be less than zero. Fix this by
assigning ret to the return from of_property_count_strings and
checking if this is less than zero instead.

Addresses-Coverity: ("Dead code")
Fixes: 6404441c8e13 ("PCI: tegra: Add Tegra194 PCIe support")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Thierry Reding Aug. 21, 2019, 12:43 p.m. UTC | #1
On Wed, Aug 21, 2019 at 01:01:23PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The check for pcie->phy_count < 0 is always false because phy_count
> is an unsigned int and can never be less than zero. Fix this by
> assigning ret to the return from of_property_count_strings and
> checking if this is less than zero instead.
> 
> Addresses-Coverity: ("Dead code")
> Fixes: 6404441c8e13 ("PCI: tegra: Add Tegra194 PCIe support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/pci/controller/dwc/pcie-tegra194.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Good catch!

Acked-by: Thierry Reding <treding@nvidia.com>
Lorenzo Pieralisi Aug. 21, 2019, 2:05 p.m. UTC | #2
On Wed, Aug 21, 2019 at 01:01:23PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The check for pcie->phy_count < 0 is always false because phy_count
> is an unsigned int and can never be less than zero. Fix this by
> assigning ret to the return from of_property_count_strings and
> checking if this is less than zero instead.
> 
> Addresses-Coverity: ("Dead code")
> Fixes: 6404441c8e13 ("PCI: tegra: Add Tegra194 PCIe support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/pci/controller/dwc/pcie-tegra194.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Squashed in the original commit (it is not merged yet), thanks
for reporting it.

Lorenzo

> diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
> index fc0dbeb31d78..b47ea3e68303 100644
> --- a/drivers/pci/controller/dwc/pcie-tegra194.c
> +++ b/drivers/pci/controller/dwc/pcie-tegra194.c
> @@ -969,12 +969,13 @@ static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie)
>  		return ret;
>  	}
>  
> -	pcie->phy_count = of_property_count_strings(np, "phy-names");
> -	if (pcie->phy_count < 0) {
> +	ret = of_property_count_strings(np, "phy-names");
> +	if (ret < 0) {
>  		dev_err(pcie->dev, "Failed to find PHY entries: %d\n",
> -			pcie->phy_count);
> -		return pcie->phy_count;
> +			ret);
> +		return ret;
>  	}
> +	pcie->phy_count = ret;
>  
>  	if (of_property_read_bool(np, "nvidia,update-fc-fixup"))
>  		pcie->update_fc_fixup = true;
> -- 
> 2.20.1
>
Vidya Sagar Aug. 21, 2019, 3:01 p.m. UTC | #3
On 8/21/2019 7:35 PM, Lorenzo Pieralisi wrote:
> On Wed, Aug 21, 2019 at 01:01:23PM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The check for pcie->phy_count < 0 is always false because phy_count
>> is an unsigned int and can never be less than zero. Fix this by
>> assigning ret to the return from of_property_count_strings and
>> checking if this is less than zero instead.
>>
>> Addresses-Coverity: ("Dead code")
>> Fixes: 6404441c8e13 ("PCI: tegra: Add Tegra194 PCIe support")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>   drivers/pci/controller/dwc/pcie-tegra194.c | 9 +++++----
>>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> Squashed in the original commit (it is not merged yet), thanks
> for reporting it.
Thanks Colin for catching it and pushing a fix also.
Thanks Lorenzo for merging it.
Apologies for missing this in my patch series.

> 
> Lorenzo
> 
>> diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
>> index fc0dbeb31d78..b47ea3e68303 100644
>> --- a/drivers/pci/controller/dwc/pcie-tegra194.c
>> +++ b/drivers/pci/controller/dwc/pcie-tegra194.c
>> @@ -969,12 +969,13 @@ static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie)
>>   		return ret;
>>   	}
>>   
>> -	pcie->phy_count = of_property_count_strings(np, "phy-names");
>> -	if (pcie->phy_count < 0) {
>> +	ret = of_property_count_strings(np, "phy-names");
>> +	if (ret < 0) {
>>   		dev_err(pcie->dev, "Failed to find PHY entries: %d\n",
>> -			pcie->phy_count);
>> -		return pcie->phy_count;
>> +			ret);
>> +		return ret;
>>   	}
>> +	pcie->phy_count = ret;
>>   
>>   	if (of_property_read_bool(np, "nvidia,update-fc-fixup"))
>>   		pcie->update_fc_fixup = true;
>> -- 
>> 2.20.1
>>
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
index fc0dbeb31d78..b47ea3e68303 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -969,12 +969,13 @@  static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie)
 		return ret;
 	}
 
-	pcie->phy_count = of_property_count_strings(np, "phy-names");
-	if (pcie->phy_count < 0) {
+	ret = of_property_count_strings(np, "phy-names");
+	if (ret < 0) {
 		dev_err(pcie->dev, "Failed to find PHY entries: %d\n",
-			pcie->phy_count);
-		return pcie->phy_count;
+			ret);
+		return ret;
 	}
+	pcie->phy_count = ret;
 
 	if (of_property_read_bool(np, "nvidia,update-fc-fixup"))
 		pcie->update_fc_fixup = true;