Linux PCI subsystem development
 help / color / mirror / Atom feed
* re: PCI: Add TLP Prefix reading to pcie_read_tlp_log()
@ 2025-01-16 15:57 Colin King (gmail)
  2025-01-16 16:18 ` Ilpo Järvinen
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King (gmail) @ 2025-01-16 15:57 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Bjorn Helgaas, Mahesh J Salgaonkar, Oliver O'Halloran,
	Jonathan Cameron, linux-pci, linux-kernel@vger.kernel.org


[-- Attachment #1.1.1: Type: text/plain, Size: 1027 bytes --]

Hi,

Static analysis shows there is a potential issue in the following commit:

commit 00048c2d5f113bb4e82a0a30dfc4ee12590b81f5
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Tue Jan 14 19:08:39 2025 +0200

     PCI: Add TLP Prefix reading to pcie_read_tlp_log()


The issue is described as follows:

unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc)
{
         return PCIE_STD_NUM_TLP_HEADERLOG +
                (aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?
                dev->eetlp_prefix_max : 0;
}


static analysis is warning that the left hand size of the ? operator is 
always true and so dev->eetlp_prefix_max is always being returned and 
the 0 is never returned (dead code).

I suspect the expected behaviour is as follows:

         return PCIE_STD_NUM_TLP_HEADERLOG +
                ((aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?
                dev->eetlp_prefix_max : 0);

..I'm reluctant to send a fix in case this is not the original intention.

Colin

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 4901 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* re: PCI: Add TLP Prefix reading to pcie_read_tlp_log()
  2025-01-16 15:57 PCI: Add TLP Prefix reading to pcie_read_tlp_log() Colin King (gmail)
@ 2025-01-16 16:18 ` Ilpo Järvinen
  2025-01-16 16:27   ` Colin King (gmail)
  0 siblings, 1 reply; 3+ messages in thread
From: Ilpo Järvinen @ 2025-01-16 16:18 UTC (permalink / raw)
  To: Colin King (gmail), Krzysztof Wilczyński, Bjorn Helgaas
  Cc: Mahesh J Salgaonkar, Oliver O'Halloran, Jonathan Cameron,
	linux-pci, linux-kernel@vger.kernel.org

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

On Thu, 16 Jan 2025, Colin King (gmail) wrote:

> Hi,
> 
> Static analysis shows there is a potential issue in the following commit:
> 
> commit 00048c2d5f113bb4e82a0a30dfc4ee12590b81f5
> Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Date:   Tue Jan 14 19:08:39 2025 +0200
> 
>     PCI: Add TLP Prefix reading to pcie_read_tlp_log()
> 
> 
> The issue is described as follows:
> 
> unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc)
> {
>         return PCIE_STD_NUM_TLP_HEADERLOG +
>                (aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?
>                dev->eetlp_prefix_max : 0;
> }
> 
> 
> static analysis is warning that the left hand size of the ? operator is always
> true and so dev->eetlp_prefix_max is always being returned and the 0 is never
> returned (dead code).
> 
> I suspect the expected behaviour is as follows:
> 
>         return PCIE_STD_NUM_TLP_HEADERLOG +
>                ((aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?
>                dev->eetlp_prefix_max : 0);
> 
> ..I'm reluctant to send a fix in case this is not the original intention.

Your fix looks correct, it should have the parenthesis due to operator 
precedence rules. The intention is to calculate 4 DWs + optionally n E-E 
TLP prefixes.

-- 
 i.

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

* Re: PCI: Add TLP Prefix reading to pcie_read_tlp_log()
  2025-01-16 16:18 ` Ilpo Järvinen
@ 2025-01-16 16:27   ` Colin King (gmail)
  0 siblings, 0 replies; 3+ messages in thread
From: Colin King (gmail) @ 2025-01-16 16:27 UTC (permalink / raw)
  To: Ilpo Järvinen, Krzysztof Wilczyński, Bjorn Helgaas
  Cc: Mahesh J Salgaonkar, Oliver O'Halloran, Jonathan Cameron,
	linux-pci, linux-kernel@vger.kernel.org


[-- Attachment #1.1.1: Type: text/plain, Size: 1421 bytes --]

On 16/01/2025 16:18, Ilpo Järvinen wrote:
> On Thu, 16 Jan 2025, Colin King (gmail) wrote:
> 
>> Hi,
>>
>> Static analysis shows there is a potential issue in the following commit:
>>
>> commit 00048c2d5f113bb4e82a0a30dfc4ee12590b81f5
>> Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>> Date:   Tue Jan 14 19:08:39 2025 +0200
>>
>>      PCI: Add TLP Prefix reading to pcie_read_tlp_log()
>>
>>
>> The issue is described as follows:
>>
>> unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc)
>> {
>>          return PCIE_STD_NUM_TLP_HEADERLOG +
>>                 (aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?
>>                 dev->eetlp_prefix_max : 0;
>> }
>>
>>
>> static analysis is warning that the left hand size of the ? operator is always
>> true and so dev->eetlp_prefix_max is always being returned and the 0 is never
>> returned (dead code).
>>
>> I suspect the expected behaviour is as follows:
>>
>>          return PCIE_STD_NUM_TLP_HEADERLOG +
>>                 ((aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?
>>                 dev->eetlp_prefix_max : 0);
>>
>> ..I'm reluctant to send a fix in case this is not the original intention.
> 
> Your fix looks correct, it should have the parenthesis due to operator
> precedence rules. The intention is to calculate 4 DWs + optionally n E-E
> TLP prefixes.
> 

OK, I'll send a patch later today.

Colin

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 4901 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

end of thread, other threads:[~2025-01-16 16:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16 15:57 PCI: Add TLP Prefix reading to pcie_read_tlp_log() Colin King (gmail)
2025-01-16 16:18 ` Ilpo Järvinen
2025-01-16 16:27   ` Colin King (gmail)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox