PCI: Fix ternary operator that never returns 0
Subsystems (2)
PATCH 1/1 PCI: Fix ternary operator that never returns 0
The left hand size of the ? operator is always true because of the addition of PCIE_STD_NUM_TLP_HEADERLOG and so dev->eetlp_prefix_max is always being returned and the 0 is never returned (dead code). Fix this by adding the required parentheses around the ternary operator.
--- drivers/pci/pcie/tlp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pcie/tlp.c +2 -2
@@ -22,8 +22,8 @@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 ; + ((aercc &PCI_ERR_CAP_PREFIX_LOG_PRESENT ) ? + dev->eetlp_prefix_max :0 ); }#ifdef CONFIG_PCIE_DPC
Signature · 1 line
2.47.1
Quoted 7 lines · Colin Ian King
The left hand size of the ? operator is always true because of the addition of
PCIE_STD_NUM_TLP_HEADERLOGand sodev->eetlp_prefix_maxis always being returned and the 0 is never returned (dead code). Fix this by adding the required parentheses around the ternary operator.Fixes 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()")Signed-off-by Colin Ian King <[email protected]>
Squashed into the 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()") commit, headed for v6.14, thanks!
Quoted 22 lines
--- drivers/pci/pcie/tlp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pcie/tlp.c +2
-2@@ -22,8 +22,8 @@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 ; + ((aercc &PCI_ERR_CAP_PREFIX_LOG_PRESENT ) ? + dev->eetlp_prefix_max :0 ); }#ifdef CONFIG_PCIE_DPC Signature · 1 line
2.47.1
Quoted 16 lines · On Thu, 16 Jan 2025 17:20:19 +0000 Colin Ian King <[email protected]>…
The left hand size of the ? operator is always true because of the addition of
PCIE_STD_NUM_TLP_HEADERLOGand sodev->eetlp_prefix_maxis always being returned and the 0 is never returned (dead code). Fix this by adding the required parentheses around the ternary operator.Fixes 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()")Signed-off-by Colin Ian King <[email protected]>--- drivers/pci/pcie/tlp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pcie/tlp.c +0
-0
drivers/pci/pcie/tlp.c line 25
Quoted 6 lines
drivers/pci/pcie/tlp.c +1
-2@@ -22,8 +22,8 @@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 ; + ((aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?
You can remove the extra set around the condition itself as well. They are a good hint the writer doesn't know their operator precedences :-)
David
Quoted 4 lines
drivers/pci/pcie/tlp.c +1
-0+ dev->eetlp_prefix_max : 0); }#ifdef CONFIG_PCIE_DPC
Quoted 14 lines · David Laight
Quoted 11 lines · On Thu, 16 Jan 2025 17:20:19 +0000 Colin Ian King <[email protected]>…
The left hand size of the ? operator is always true because of the addition of
PCIE_STD_NUM_TLP_HEADERLOGand sodev->eetlp_prefix_maxis always being returned and the 0 is never returned (dead code). Fix this by adding the required parentheses around the ternary operator.Fixes 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()")Signed-off-by Colin Ian King <[email protected]>--- drivers/pci/pcie/tlp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 15 lines
drivers/pci/pcie/tlp.c line 25
Quoted 11 lines
drivers/pci/pcie/tlp.c +1
-2@@ -22,8 +22,8 @@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 ; + ((aercc & PCI_ERR_CAP_PREFIX_LOG_PRESENT) ?You can remove the extra set around the condition itself as well. They are a good hint the writer doesn't know their operator precedences :-)
Please leave them as-is... I obsolutely do not remember the operator precedences between & and ? and I have to look it up every time I see it.
regards,
dan carpenter