PCI: Add TLP Prefix reading to pcie_read_tlp_log()
Hi,
Static analysis shows there is a potential issue in the following commit:
commit 00048c2d5f113bb4e82a0a30dfc4ee12590b81f5
Author: Ilpo Järvinen <[email protected]> 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
Quoted 25 lines · Colin King (gmail)
Hi,
Static analysis shows there is a potential issue in the following commit:
commit
00048c2d5f113bb4e82a0a30dfc4ee12590b81f5Author: Ilpo Järvinen <[email protected]> Date: Tue Jan 14 19:08:39 2025 +0200PCI: 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){
returnPCIE_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_maxis always being returned and the 0 is never returned (dead code).
Quoted 7 lines
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.
Signature · 1 line
i.
Quoted 33 lines · Ilpo Järvinen
Quoted 31 lines · Colin King (gmail)
Hi,
Static analysis shows there is a potential issue in the following commit:
commit
00048c2d5f113bb4e82a0a30dfc4ee12590b81f5Author: Ilpo Järvinen <[email protected]> Date: Tue Jan 14 19:08:39 2025 +0200PCI: 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){
returnPCIE_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_maxis 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);
Quoted 6 lines
Quoted 1 line
..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