* [PATCH][next] PCI: Fix ternary operator that never returns 0
@ 2025-01-16 17:20 Colin Ian King
2025-01-16 18:06 ` Bjorn Helgaas
2025-01-16 22:49 ` David Laight
0 siblings, 2 replies; 4+ messages in thread
From: Colin Ian King @ 2025-01-16 17:20 UTC (permalink / raw)
To: Bjorn Helgaas, Ilpo Järvinen, Jonathan Cameron, linux-pci
Cc: kernel-janitors, linux-kernel
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.
Fixes: 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
drivers/pci/pcie/tlp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pcie/tlp.c b/drivers/pci/pcie/tlp.c
index 9b9e348fb1a0..0860b5da837f 100644
--- a/drivers/pci/pcie/tlp.c
+++ b/drivers/pci/pcie/tlp.c
@@ -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
--
2.47.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH][next] PCI: Fix ternary operator that never returns 0
2025-01-16 17:20 [PATCH][next] PCI: Fix ternary operator that never returns 0 Colin Ian King
@ 2025-01-16 18:06 ` Bjorn Helgaas
2025-01-16 22:49 ` David Laight
1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2025-01-16 18:06 UTC (permalink / raw)
To: Colin Ian King
Cc: Bjorn Helgaas, Ilpo Järvinen, Jonathan Cameron, linux-pci,
kernel-janitors, linux-kernel
On Thu, Jan 16, 2025 at 05:20:19PM +0000, Colin Ian King wrote:
> 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.
>
> Fixes: 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Squashed into the 00048c2d5f11 ("PCI: Add TLP Prefix reading to
pcie_read_tlp_log()") commit, headed for v6.14, thanks!
> ---
> drivers/pci/pcie/tlp.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/pcie/tlp.c b/drivers/pci/pcie/tlp.c
> index 9b9e348fb1a0..0860b5da837f 100644
> --- a/drivers/pci/pcie/tlp.c
> +++ b/drivers/pci/pcie/tlp.c
> @@ -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
> --
> 2.47.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH][next] PCI: Fix ternary operator that never returns 0
2025-01-16 17:20 [PATCH][next] PCI: Fix ternary operator that never returns 0 Colin Ian King
2025-01-16 18:06 ` Bjorn Helgaas
@ 2025-01-16 22:49 ` David Laight
2025-01-17 5:25 ` Dan Carpenter
1 sibling, 1 reply; 4+ messages in thread
From: David Laight @ 2025-01-16 22:49 UTC (permalink / raw)
To: Colin Ian King
Cc: Bjorn Helgaas, Ilpo Järvinen, Jonathan Cameron, linux-pci,
kernel-janitors, linux-kernel
On Thu, 16 Jan 2025 17:20:19 +0000
Colin Ian King <colin.i.king@gmail.com> wrote:
> 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.
>
> Fixes: 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
> drivers/pci/pcie/tlp.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/pcie/tlp.c b/drivers/pci/pcie/tlp.c
> index 9b9e348fb1a0..0860b5da837f 100644
> --- a/drivers/pci/pcie/tlp.c
> +++ b/drivers/pci/pcie/tlp.c
> @@ -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
> + dev->eetlp_prefix_max : 0);
> }
>
> #ifdef CONFIG_PCIE_DPC
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH][next] PCI: Fix ternary operator that never returns 0
2025-01-16 22:49 ` David Laight
@ 2025-01-17 5:25 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2025-01-17 5:25 UTC (permalink / raw)
To: David Laight
Cc: Colin Ian King, Bjorn Helgaas, Ilpo Järvinen,
Jonathan Cameron, linux-pci, kernel-janitors, linux-kernel
On Thu, Jan 16, 2025 at 10:49:44PM +0000, David Laight wrote:
> On Thu, 16 Jan 2025 17:20:19 +0000
> Colin Ian King <colin.i.king@gmail.com> wrote:
>
> > 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.
> >
> > Fixes: 00048c2d5f11 ("PCI: Add TLP Prefix reading to pcie_read_tlp_log()")
> > Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> > ---
> > drivers/pci/pcie/tlp.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/pci/pcie/tlp.c b/drivers/pci/pcie/tlp.c
> > index 9b9e348fb1a0..0860b5da837f 100644
> > --- a/drivers/pci/pcie/tlp.c
> > +++ b/drivers/pci/pcie/tlp.c
> > @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-17 5:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16 17:20 [PATCH][next] PCI: Fix ternary operator that never returns 0 Colin Ian King
2025-01-16 18:06 ` Bjorn Helgaas
2025-01-16 22:49 ` David Laight
2025-01-17 5:25 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox