linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] PCI: tegra: tegra194: fix phy_count less than zero check
@ 2019-08-21 12:01 Colin King
  2019-08-21 12:43 ` Thierry Reding
  2019-08-21 14:05 ` Lorenzo Pieralisi
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2019-08-21 12:01 UTC (permalink / raw)
  To: Vidya Sagar, Lorenzo Pieralisi, Bjorn Helgaas, Thierry Reding,
	Jonathan Hunter, linux-pci, linux-tegra
  Cc: kernel-janitors, linux-kernel

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(-)

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] PCI: tegra: tegra194: fix phy_count less than zero check
  2019-08-21 12:01 [PATCH][next] PCI: tegra: tegra194: fix phy_count less than zero check Colin King
@ 2019-08-21 12:43 ` Thierry Reding
  2019-08-21 14:05 ` Lorenzo Pieralisi
  1 sibling, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2019-08-21 12:43 UTC (permalink / raw)
  To: Colin King
  Cc: Vidya Sagar, Lorenzo Pieralisi, Bjorn Helgaas, Jonathan Hunter,
	linux-pci, linux-tegra, kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 717 bytes --]

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>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] PCI: tegra: tegra194: fix phy_count less than zero check
  2019-08-21 12:01 [PATCH][next] PCI: tegra: tegra194: fix phy_count less than zero check Colin King
  2019-08-21 12:43 ` Thierry Reding
@ 2019-08-21 14:05 ` Lorenzo Pieralisi
  2019-08-21 15:01   ` Vidya Sagar
  1 sibling, 1 reply; 4+ messages in thread
From: Lorenzo Pieralisi @ 2019-08-21 14:05 UTC (permalink / raw)
  To: Colin King
  Cc: Vidya Sagar, Bjorn Helgaas, Thierry Reding, Jonathan Hunter,
	linux-pci, linux-tegra, kernel-janitors, linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] PCI: tegra: tegra194: fix phy_count less than zero check
  2019-08-21 14:05 ` Lorenzo Pieralisi
@ 2019-08-21 15:01   ` Vidya Sagar
  0 siblings, 0 replies; 4+ messages in thread
From: Vidya Sagar @ 2019-08-21 15:01 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Colin King
  Cc: Bjorn Helgaas, Thierry Reding, Jonathan Hunter, linux-pci,
	linux-tegra, kernel-janitors, linux-kernel

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
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-21 15:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21 12:01 [PATCH][next] PCI: tegra: tegra194: fix phy_count less than zero check Colin King
2019-08-21 12:43 ` Thierry Reding
2019-08-21 14:05 ` Lorenzo Pieralisi
2019-08-21 15:01   ` Vidya Sagar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).