From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E59AC433E2 for ; Tue, 7 Jul 2020 23:03:48 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 311C62065D for ; Tue, 7 Jul 2020 23:03:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E+virPP7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 311C62065D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E5B7D226C2; Tue, 7 Jul 2020 23:03:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nStl1BaRbyjU; Tue, 7 Jul 2020 23:03:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 8010322610; Tue, 7 Jul 2020 23:03:46 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 67DBEC0893; Tue, 7 Jul 2020 23:03:46 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 95054C016F for ; Tue, 7 Jul 2020 23:03:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8D25E89413 for ; Tue, 7 Jul 2020 23:03:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0tqGwfzSBayL for ; Tue, 7 Jul 2020 23:03:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by whitealder.osuosl.org (Postfix) with ESMTPS id 4A39789387 for ; Tue, 7 Jul 2020 23:03:42 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id d15so40116064edm.10 for ; Tue, 07 Jul 2020 16:03:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=kTq/VH/p4TyQ5wPRzJwyOD8JsPzalLXL/D+9ThOBTJk=; b=E+virPP7R0DNmaCjVGtSUu/QcvSxTf4R7sOk6VcFsmCvGe0J84CcBd5HeNBiHdEGFF JmZI2QMdJ3elJ5MqdzZR/53PLHZyXBiuCFyv35oO8MHG9CZxR2Iq5EhY68cQJh6tS3FM 8criJyFHjuNIStjyC28tRfZTtvROoXe7nu6rzuI3busfBGfKDruR6mMoncEkVbIcPRMU 3N/NxjKHK7cc70B3dsJJ2bJ/tFj3dVtUDJmcxY3vtXJ/MTH3h7iZdQ/G7oUXSqNkMlnJ ECGvJ/Ssb2a2O9P/PsgcX12j0Sc5qUzPp+C5ZZ0LsYvGa3vZu43Jj4nfAT10J0pBwVjO sZhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kTq/VH/p4TyQ5wPRzJwyOD8JsPzalLXL/D+9ThOBTJk=; b=suDaJU/+/UKYohxL7bAoBbLRShQKIKzGmgVBaaP7Ax/2z1vX0RRt3JKhD5LlpOjzmN KtLaBQjd7tKS6gYJseMSaPeBwdFO3rMOh6r6cGRs8cjDB8AL372cPwDDJIkli3ibyNLn yUSvyiDTmBeFGKhiKNPvl3Ictlql+o6w2Ncb+GYtxapPFi3Cwasv7BjtCKqCJ0aPZRhj ni/P3f1B27Cjx1TOMXWZcIlAeMTE/yf77qp4JWokQnl31UYRy0YEt3mQn0ddlMQc77FE 6Jqd9k0eJfwr8LRxuuNnDcPoLGyWTdCWAhyXZbvCZXqcQmMhEgYziqFfdLfoR28CDdfp Wosw== X-Gm-Message-State: AOAM53213vlmxZUxVrIijfDJOP1pqYZ6vG9/F6JrjMnfuGBQkjBE3LXH xXDSSLPdmZIHl2HUky10c2Q= X-Google-Smtp-Source: ABdhPJyCkNHIU7Mg/3LR3/ROH8pv8slqj90hjhE3e1+AdXgWeG9fxZ5hQsBoE731r/kg9QH8KEcJqA== X-Received: by 2002:aa7:d989:: with SMTP id u9mr46087113eds.85.1594163020678; Tue, 07 Jul 2020 16:03:40 -0700 (PDT) Received: from net.saheed (54007186.dsl.pool.telekom.hu. [84.0.113.134]) by smtp.gmail.com with ESMTPSA id f10sm27096310edx.5.2020.07.07.16.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 16:03:39 -0700 (PDT) From: Saheed Olayemi Bolarinwa To: helgaas@kernel.org Date: Wed, 8 Jul 2020 00:03:11 +0200 Message-Id: <20200707220324.8425-1-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 Cc: linux-wireless@vger.kernel.org, linux-pci@vger.kernel.org, QCA ath9k Development , netdev@vger.kernel.org, Oliver O'Halloran , Russell Currey , Stanislaw Gruszka , linux-acpi@vger.kernel.org, linux-rdma@vger.kernel.org, Jason Gunthorpe , Doug Ledford , Jakub Kicinski , linux-kernel-mentees@lists.linuxfoundation.org, Len Brown , Arnd Bergmann , Kalle Valo , Mike Marciniszyn , Sam Bobroff , Dennis Dalessandro , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Lukas Wunner , Bolarinwa Olayemi Saheed , linuxppc-dev@lists.ozlabs.org, "David S. Miller" Subject: [Linux-kernel-mentees] [PATCH 0/13] PCI: Remove '*val = 0' from pcie_capability_read_*() X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" From: Bolarinwa Olayemi Saheed MERGING: Only Patch 13/13 depend on all preceeding patchs. All other patches are independent of one another. Hence, please merge PATCH 13/13 only after other patches in this series have been merged. PATCH 6/13: 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/13 to 12/13: 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 13/13 does not introduce any bug. PATCH 13/13: 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 13/13. Remove the reset of *val to 0 when pci_read_config_*() fails. Bolarinwa Olayemi Saheed (13): 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/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 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees