* [PATCH 3/14 v3] ath9k: Check the return value of pcie_capability_read_*()
[not found] <20200713175529.29715-1-refactormyself@gmail.com>
@ 2020-07-13 17:55 ` Saheed O. Bolarinwa
2020-07-20 17:09 ` Kalle Valo
2020-07-13 17:55 ` [PATCH 4/14 v3] iwlegacy: " Saheed O. Bolarinwa
1 sibling, 1 reply; 6+ messages in thread
From: Saheed O. Bolarinwa @ 2020-07-13 17:55 UTC (permalink / raw)
To: skhan, linux-pci, linux-kernel-mentees, linux-kernel,
QCA ath9k Development, linux-wireless, netdev
Cc: Bolarinwa Olayemi Saheed, Kalle Valo
From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
On failure pcie_capability_read_dword() sets it's last parameter, val
to 0. However, with Patch 14/14, it is possible that val is set to ~0 on
failure. This would introduce a bug because (x & x) == (~0 & x).
This bug can be avoided without changing the function's behaviour if the
return value of pcie_capability_read_dword is checked to confirm success.
Check the return value of pcie_capability_read_dword() to ensure success.
Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
---
drivers/net/wireless/ath/ath9k/pci.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index f3461b193c7a..cff9af3af38d 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -825,6 +825,7 @@ static void ath_pci_aspm_init(struct ath_common *common)
struct pci_dev *pdev = to_pci_dev(sc->dev);
struct pci_dev *parent;
u16 aspm;
+ int ret;
if (!ah->is_pciexpress)
return;
@@ -866,8 +867,8 @@ static void ath_pci_aspm_init(struct ath_common *common)
if (AR_SREV_9462(ah))
pci_read_config_dword(pdev, 0x70c, &ah->config.aspm_l1_fix);
- pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm);
- if (aspm & (PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1)) {
+ ret = pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm);
+ if (!ret && (aspm & (PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1))) {
ah->aspm_enabled = true;
/* Initialize PCIe PM and SERDES registers. */
ath9k_hw_configpcipowersave(ah, false);
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 3/14 v3] ath9k: Check the return value of pcie_capability_read_*()
2020-07-13 17:55 ` [PATCH 3/14 v3] ath9k: Check the return value of pcie_capability_read_*() Saheed O. Bolarinwa
@ 2020-07-20 17:09 ` Kalle Valo
0 siblings, 0 replies; 6+ messages in thread
From: Kalle Valo @ 2020-07-20 17:09 UTC (permalink / raw)
To: Saheed O. Bolarinwa
Cc: skhan, linux-pci, linux-kernel-mentees, linux-kernel,
QCA ath9k Development, linux-wireless, netdev,
Bolarinwa Olayemi Saheed
"Saheed O. Bolarinwa" <refactormyself@gmail.com> wrote:
> On failure pcie_capability_read_dword() sets it's last parameter, val
> to 0. However, with Patch 14/14, it is possible that val is set to ~0 on
> failure. This would introduce a bug because (x & x) == (~0 & x).
>
> This bug can be avoided without changing the function's behaviour if the
> return value of pcie_capability_read_dword is checked to confirm success.
>
> Check the return value of pcie_capability_read_dword() to ensure success.
>
> Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
> Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Patch applied to ath-next branch of ath.git, thanks.
9a8ab2bfb678 ath9k: Check the return value of pcie_capability_read_*()
--
https://patchwork.kernel.org/patch/11660731/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/14 v3] iwlegacy: Check the return value of pcie_capability_read_*()
[not found] <20200713175529.29715-1-refactormyself@gmail.com>
2020-07-13 17:55 ` [PATCH 3/14 v3] ath9k: Check the return value of pcie_capability_read_*() Saheed O. Bolarinwa
@ 2020-07-13 17:55 ` Saheed O. Bolarinwa
2020-07-15 16:47 ` Kalle Valo
1 sibling, 1 reply; 6+ messages in thread
From: Saheed O. Bolarinwa @ 2020-07-13 17:55 UTC (permalink / raw)
To: skhan, linux-pci, linux-kernel-mentees, linux-kernel,
Stanislaw Gruszka, linux-wireless, netdev
Cc: Bolarinwa Olayemi Saheed, Kalle Valo
From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
On failure pcie_capability_read_dword() sets it's last parameter, val
to 0. However, with Patch 14/14, it is possible that val is set to ~0 on
failure. This would introduce a bug because (x & x) == (~0 & x).
This bug can be avoided without changing the function's behaviour if the
return value of pcie_capability_read_dword is checked to confirm success.
Check the return value of pcie_capability_read_dword() to ensure success.
Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
---
drivers/net/wireless/intel/iwlegacy/common.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/intel/iwlegacy/common.c b/drivers/net/wireless/intel/iwlegacy/common.c
index 348c17ce72f5..f78e062df572 100644
--- a/drivers/net/wireless/intel/iwlegacy/common.c
+++ b/drivers/net/wireless/intel/iwlegacy/common.c
@@ -4286,8 +4286,8 @@ il_apm_init(struct il_priv *il)
* power savings, even without L1.
*/
if (il->cfg->set_l0s) {
- pcie_capability_read_word(il->pci_dev, PCI_EXP_LNKCTL, &lctl);
- if (lctl & PCI_EXP_LNKCTL_ASPM_L1) {
+ ret = pcie_capability_read_word(il->pci_dev, PCI_EXP_LNKCTL, &lctl);
+ if (!ret && (lctl & PCI_EXP_LNKCTL_ASPM_L1)) {
/* L1-ASPM enabled; disable(!) L0S */
il_set_bit(il, CSR_GIO_REG,
CSR_GIO_REG_VAL_L0S_ENABLED);
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 4/14 v3] iwlegacy: Check the return value of pcie_capability_read_*()
2020-07-13 17:55 ` [PATCH 4/14 v3] iwlegacy: " Saheed O. Bolarinwa
@ 2020-07-15 16:47 ` Kalle Valo
0 siblings, 0 replies; 6+ messages in thread
From: Kalle Valo @ 2020-07-15 16:47 UTC (permalink / raw)
To: Saheed O. Bolarinwa
Cc: skhan, linux-pci, linux-kernel-mentees, linux-kernel,
Stanislaw Gruszka, linux-wireless, netdev,
Bolarinwa Olayemi Saheed
"Saheed O. Bolarinwa" <refactormyself@gmail.com> wrote:
> From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
>
> On failure pcie_capability_read_dword() sets it's last parameter, val
> to 0. However, with Patch 14/14, it is possible that val is set to ~0 on
> failure. This would introduce a bug because (x & x) == (~0 & x).
>
> This bug can be avoided without changing the function's behaviour if the
> return value of pcie_capability_read_dword is checked to confirm success.
>
> Check the return value of pcie_capability_read_dword() to ensure success.
>
> Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
> Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
Patch applied to wireless-drivers-next.git, thanks.
9018fd7f2a73 iwlegacy: Check the return value of pcie_capability_read_*()
--
https://patchwork.kernel.org/patch/11660739/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 0/14 v3] PCI: Remove '*val = 0' from pcie_capability_read_*()
@ 2020-07-10 21:20 Saheed Olayemi Bolarinwa
[not found] ` <20200710212026.27136-5-refactormyself@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Saheed Olayemi Bolarinwa @ 2020-07-10 21:20 UTC (permalink / raw)
To: helgaas
Cc: Bolarinwa Olayemi Saheed, bjorn, skhan, linux-pci,
linux-kernel-mentees, linux-kernel, Russell Currey, Sam Bobroff,
Oliver O'Halloran, linuxppc-dev, Rafael J. Wysocki, Len Brown,
Lukas Wunner, linux-acpi, Mike Marciniszyn, Dennis Dalessandro,
Doug Ledford, Jason Gunthorpe, linux-rdma, Arnd Bergmann,
Greg Kroah-Hartman, David S. Miller, Kalle Valo, Jakub Kicinski,
QCA ath9k Development, linux-wireless, netdev, Stanislaw Gruszka
From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
v3 CHANGES:
- Split previous PATCH 6/13 into two : PATCH 6/14 and PATCH 7/14
- Fix commit message of PATCH 5/14
- Update Patch numbering and Commit messages
- Add 'Acked by Greg KH' to PATCH 2/14
- Add PATCH version
v2 CHANGES:
- Fix missing comma, causing the email cc error
- Fix typos and numbering errors in commit messages
- Add commit message to 13/13
- Add two more patches: PATCH 3/13 and PATCH 4/13
MERGING:
Patch 7/14 depends on Patch 6/14. However Patch 6/14 has no dependency.
Please, merge PATCH 7/14 only after Patch 6/14.
Patch 14/14 depend on all preceeding patchs. Except for Patch 6/14 and
Patch 7/14, all other patches are independent of one another. Hence,
please merge Patch 14/14 only after other patches in this series have
been merged.
PATCH 6/14:
Make the function set status to "Power On" by default and only set to
Set "Power Off" only if pcie_capability_read_word() is successful and
(slot_ctrl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_OFF.
PATCH 1/14 to 13/14:
Check the return value of pcie_capability_read_*() to ensure success or
confirm failure. While maintaining these functions, this ensures that the
changes in PATCH 14/14 does not introduce any bug.
PATCH 14/14:
There are several reasons why a PCI capability read may fail whether the
device is present or not. If this happens, pcie_capability_read_*() will
return -EINVAL/PCIBIOS_BAD_REGISTER_NUMBER or PCIBIOS_DEVICE_NOT_FOUND
and *val is set to 0.
This behaviour if further ensured by this code inside
pcie_capability_read_*()
ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val);
/*
* Reset *val to 0 if pci_read_config_dword() fails, it may
* have been written as 0xFFFFFFFF if hardware error happens
* during pci_read_config_dword().
*/
if (ret)
*val = 0;
return ret;
a) Since all pci_generic_config_read() does is read a register value,
it may return success after reading a ~0 which *may* have been fabricated
by the PCI host bridge due to a read timeout. Hence pci_read_config_*()
will return success with a fabricated ~0 in *val, indicating a problem.
In this case, the assumed behaviour of pcie_capability_read_*() will be
wrong. To avoid error slipping through, more checks are necessary.
b) pci_read_config_*() will return PCIBIOS_DEVICE_NOT_FOUND only if
dev->error_state = pci_channel_io_perm_failure (i.e.
pci_dev_is_disconnected()) or if pci_generic_config_read() can't find the
device. In both cases *val is initially set to ~0 but as shown in the code
above pcie_capability_read_*() resets it back to 0. Even with this effort,
drivers still have to perform validation checks more so if 0 is a valid
value.
Most drivers only consider the case (b) and in some cases, there is the
expectation that on timeout *val has a fabricated value of ~0, which *may*
not always be true as explained in (a).
In any case, checks need to be done to validate the value read and maybe
confirm which error has occurred. It is better left to the drivers to do.
Check the return value of pcie_capability_read_dword() to ensure success
and avoid bug as a result of Patch 14/14.
Remove the reset of *val to 0 when pci_read_config_*() fails.
Bolarinwa Olayemi Saheed (14):
IB/hfi1: Check the return value of pcie_capability_read_*()
misc: rtsx: Check the return value of pcie_capability_read_*()
ath9k: Check the return value of pcie_capability_read_*()
iwlegacy: Check the return value of pcie_capability_read_*()
PCI: pciehp: Check the return value of pcie_capability_read_*()
PCI: pciehp: Make "Power On" the default
PCI: pciehp: Check the return value of pcie_capability_read_*()
PCI/ACPI: Check the return value of pcie_capability_read_*()
PCI: pciehp: Check the return value of pcie_capability_read_*()
PCI: Check the return value of pcie_capability_read_*()
PCI/PM: Check return value of pcie_capability_read_*()
PCI/AER: Check the return value of pcie_capability_read_*()
PCI/ASPM: Check the return value of pcie_capability_read_*()
PCI: Remove '*val = 0' from pcie_capability_read_*()
drivers/net/wireless/ath/ath9k/pci.c | 5 +++--
drivers/net/wireless/intel/iwlegacy/common.c | 4 ++--
drivers/infiniband/hw/hfi1/aspm.c | 7 ++++---
drivers/misc/cardreader/rts5227.c | 5 +++--
drivers/misc/cardreader/rts5249.c | 5 +++--
drivers/misc/cardreader/rts5260.c | 5 +++--
drivers/misc/cardreader/rts5261.c | 5 +++--
drivers/pci/pcie/aer.c | 5 +++--
drivers/pci/pcie/aspm.c | 33 +++++++++++++++++----------------
drivers/pci/hotplug/pciehp_hpc.c | 47 ++++++++++++++++----------------
drivers/pci/pci-acpi.c | 10 ++++---
drivers/pci/probe.c | 29 ++++++++++++--------
drivers/pci/access.c | 14 --------------
13 files changed, 87 insertions(+), 87 deletions(-)
--
2.18.2
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-20 17:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20200713175529.29715-1-refactormyself@gmail.com>
2020-07-13 17:55 ` [PATCH 3/14 v3] ath9k: Check the return value of pcie_capability_read_*() Saheed O. Bolarinwa
2020-07-20 17:09 ` Kalle Valo
2020-07-13 17:55 ` [PATCH 4/14 v3] iwlegacy: " Saheed O. Bolarinwa
2020-07-15 16:47 ` Kalle Valo
2020-07-10 21:20 [PATCH 0/14 v3] PCI: Remove '*val = 0' from pcie_capability_read_*() Saheed Olayemi Bolarinwa
[not found] ` <20200710212026.27136-5-refactormyself@gmail.com>
2020-07-13 13:44 ` [PATCH 4/14 v3] iwlegacy: Check the return value of pcie_capability_read_*() Kalle Valo
2020-07-13 18:02 ` Saheed Bolarinwa
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).