From patchwork Mon May 4 05:18:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 1282191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=g6Uje93L; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Ft2w4VvMz9sRY for ; Mon, 4 May 2020 16:18:32 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbgEDGSa (ORCPT ); Mon, 4 May 2020 02:18:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbgEDGSa (ORCPT ); Mon, 4 May 2020 02:18:30 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06CFCC061A0E for ; Sun, 3 May 2020 23:18:30 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id e16so14308593wra.7 for ; Sun, 03 May 2020 23:18:29 -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:in-reply-to:references; bh=WclkHowIn1eEFLPIX8/qTgQi4T5DsnmjpScbqAksDNM=; b=g6Uje93L2ADOfNq4pmMdT+5ZI0cO7fZeRWCsFL4JIST09bl0B4wnxSWLjB31YSrF6m oPjZMmaJIeT7aan1WWIyhcrVn8MXWefHvPQcSePT3A0X5ZrGcb5zNm2AzCuiUwBYp41w NKggLXoBMW5H/9JiVFHXIAkJoimP9nC4XpTZijwUXJVzK1pE97TfK2eS+Z5B9hMsC0ft dNV00q4lzkEcwGRo9IbOuWCitmYEgEJzuNj5uptz3Nv4AQ4/e8WiInvvWtqnTBkkyRWG A28qs3LvQ2mR1U5Psp9m4L7cmqEQAsBHKDhqELihPXdAp/FYbG24UwqemooSIc+sT/pk 8A6Q== 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:in-reply-to :references; bh=WclkHowIn1eEFLPIX8/qTgQi4T5DsnmjpScbqAksDNM=; b=hlRp+rJAvbGTExkoGm/WjcxcMY0F1I+e8DOdjBgLnv0xm/zbkXELbcmiwOFnnMeGUN 5dPWt1UNUZzwYM1KbGY2GOnDjebINnOk/GdmEwgkKK7dMcEOZ6pgU35argTulPDb7UEv nB4ZsHkR3405k5UIEXxgckA5xq6PgykYnOGVlEijkZBkBNZGoj2/5e8NVtU3beJjGxbe yf/IcPhKtLni8iAv9Is3hLxaA0JRP7z/d6BMgpvzR5ESwa9ROb8fTAPF6cT+EBofMk+K uTa5b58ovRa18GZOtR1t/86lpWKxoed5M+Oo8+YY4uUyG7XmYgzTmXi08pjNFA/zIeMV Fhsg== X-Gm-Message-State: AGi0Puan9SPFFKXZAJqIBALn7/BACsC3txd8qi1Pr1RLovLehD5AGiT9 T/0GjPgXgW6U8QrjMb2QmNTpRBTbMoGltg== X-Google-Smtp-Source: APiQypKyIv0tlwVvPhhyvhsHX7VKgIJcx1piu6dtkImNtCdsR0Wsfb9R/LM8ocur4I0o5TkFilflIQ== X-Received: by 2002:a5d:4b04:: with SMTP id v4mr18388015wrq.358.1588573108741; Sun, 03 May 2020 23:18:28 -0700 (PDT) Received: from net.saheed (540018A9.dsl.pool.telekom.hu. [84.0.24.169]) by smtp.gmail.com with ESMTPSA id k23sm11559004wmi.46.2020.05.03.23.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 23:18:28 -0700 (PDT) From: refactormyself@gmail.com To: helgaas@kernel.org Cc: Bolarinwa Olayemi Saheed , bjorn@helgaas.com, yangyicong@hisilicon.com, skhan@linuxfoundation.org, linux-pci@vger.kernel.org Subject: [PATCH RFC 1/2] pci: Make return value of pcie_capability_*() consistent Date: Mon, 4 May 2020 07:18:11 +0200 Message-Id: <20200504051812.22662-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200504051812.22662-1-refactormyself@gmail.com> References: <20200504051812.22662-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bolarinwa Olayemi Saheed pcie_capability_{read|write}_*() could return 0, -EINVAL, or any of the PCIBIOS_* error codes. This is behaviour is now changed to ONLY return a PCIBIOS_* error code or -ERANGE on error. This has now been made consistent across all accessors. Callers now have a consistent way for checking which error has occurred. An audit of the callers of these functions was made and no contradicting case was found in the examined call chains. Signed-off-by: Bolarinwa Olayemi Saheed Suggested-by: Bjorn Helgaas --- drivers/pci/access.c | 64 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/drivers/pci/access.c b/drivers/pci/access.c index 79c4a2ef269a..10c771079e35 100644 --- a/drivers/pci/access.c +++ b/drivers/pci/access.c @@ -402,6 +402,8 @@ static bool pcie_capability_reg_implemented(struct pci_dev *dev, int pos) * Note that these accessor functions are only for the "PCI Express * Capability" (see PCIe spec r3.0, sec 7.8). They do not apply to the * other "PCI Express Extended Capabilities" (AER, VC, ACS, MFVC, etc.) + * + * Return 0 on success, otherwise a negative value */ int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val) { @@ -409,7 +411,7 @@ int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val) *val = 0; if (pos & 1) - return -EINVAL; + return PCIBIOS_BAD_REGISTER_NUMBER; if (pcie_capability_reg_implemented(dev, pos)) { ret = pci_read_config_word(dev, pci_pcie_cap(dev) + pos, val); @@ -444,7 +446,7 @@ int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val) *val = 0; if (pos & 3) - return -EINVAL; + return PCIBIOS_BAD_REGISTER_NUMBER; if (pcie_capability_reg_implemented(dev, pos)) { ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val); @@ -453,9 +455,9 @@ int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val) * have been written as 0xFFFFFFFF if hardware error happens * during pci_read_config_dword(). */ - if (ret) - *val = 0; - return ret; + if (ret) + *val = 0; + return ret; } if (pci_is_pcie(dev) && pcie_downstream_port(dev) && @@ -469,7 +471,7 @@ EXPORT_SYMBOL(pcie_capability_read_dword); int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val) { if (pos & 1) - return -EINVAL; + return PCIBIOS_BAD_REGISTER_NUMBER; if (!pcie_capability_reg_implemented(dev, pos)) return 0; @@ -481,7 +483,7 @@ EXPORT_SYMBOL(pcie_capability_write_word); int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val) { if (pos & 3) - return -EINVAL; + return PCIBIOS_BAD_REGISTER_NUMBER; if (!pcie_capability_reg_implemented(dev, pos)) return 0; @@ -526,56 +528,92 @@ EXPORT_SYMBOL(pcie_capability_clear_and_set_dword); int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val) { + int ret; if (pci_dev_is_disconnected(dev)) { *val = ~0; return PCIBIOS_DEVICE_NOT_FOUND; } - return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val); + + ret = pci_bus_read_config_byte(dev->bus, dev->devfn, where, val); + + if (ret > 0) + ret = -ERANGE; + return ret; } EXPORT_SYMBOL(pci_read_config_byte); int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val) { + int ret; if (pci_dev_is_disconnected(dev)) { *val = ~0; return PCIBIOS_DEVICE_NOT_FOUND; } - return pci_bus_read_config_word(dev->bus, dev->devfn, where, val); + + ret = pci_bus_read_config_word(dev->bus, dev->devfn, where, val); + + if (ret > 0) + ret = -ERANGE; + return ret; } EXPORT_SYMBOL(pci_read_config_word); int pci_read_config_dword(const struct pci_dev *dev, int where, u32 *val) { + int ret; if (pci_dev_is_disconnected(dev)) { *val = ~0; return PCIBIOS_DEVICE_NOT_FOUND; } - return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val); + + ret = pci_bus_read_config_dword(dev->bus, dev->devfn, where, val); + + if (ret > 0) + ret = -ERANGE; + return ret; } EXPORT_SYMBOL(pci_read_config_dword); int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val) { + int ret; if (pci_dev_is_disconnected(dev)) return PCIBIOS_DEVICE_NOT_FOUND; - return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val); + + ret = pci_bus_write_config_byte(dev->bus, dev->devfn, where, val); + + if (ret > 0) + ret = -ERANGE; + return ret; } EXPORT_SYMBOL(pci_write_config_byte); int pci_write_config_word(const struct pci_dev *dev, int where, u16 val) { + int ret; if (pci_dev_is_disconnected(dev)) return PCIBIOS_DEVICE_NOT_FOUND; - return pci_bus_write_config_word(dev->bus, dev->devfn, where, val); + + ret = pci_bus_write_config_word(dev->bus, dev->devfn, where, val); + + if (ret > 0) + ret = -ERANGE; + return ret; } EXPORT_SYMBOL(pci_write_config_word); int pci_write_config_dword(const struct pci_dev *dev, int where, u32 val) { + int ret; if (pci_dev_is_disconnected(dev)) return PCIBIOS_DEVICE_NOT_FOUND; - return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val); + + ret = pci_bus_write_config_dword(dev->bus, dev->devfn, where, val); + + if (ret > 0) + ret = -ERANGE; + return ret; } EXPORT_SYMBOL(pci_write_config_dword); From patchwork Mon May 4 05:18:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 1282192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Wx/Ea1rp; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Ft3G5XlNz9sRY for ; Mon, 4 May 2020 16:18:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726578AbgEDGSu (ORCPT ); Mon, 4 May 2020 02:18:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbgEDGSt (ORCPT ); Mon, 4 May 2020 02:18:49 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FE25C061A0E for ; Sun, 3 May 2020 23:18:48 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id d17so19384506wrg.11 for ; Sun, 03 May 2020 23:18:48 -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:in-reply-to:references; bh=YDlG0Xw1x/kgXl/YkAa69pkzlhWwY8X9N+5Bs9v5cew=; b=Wx/Ea1rpn6/dIelkYV8bMF7ToJsTIKXw6Vw1nBXW5kLruk0Wm5iH9Kj4JRFs7ScP+t utJfe4Z/iu9XmLtFvAMdE1wvN8O43r8pOi5POyaWVti7HtqwCc204/4HyukBBGe63nlO wG0Kevnm9vzowJB2tW8/xJg6O4ZMd62LDdF8dcvcMPuDqNymyTdkfyIdEDE7je/sg3st FeoHjy88pMvgwteC+xb6UBidfncENcfAaJAvGsWXmZ9+ROUTV4XJkptg9OPGgC931vmz PCyefSolyPlm6cUYRD8I3JkuTrlhphO0K2rp1dZGhIyfeW8mjHdTwgQHwQvO1qbI8Xl0 vXlg== 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:in-reply-to :references; bh=YDlG0Xw1x/kgXl/YkAa69pkzlhWwY8X9N+5Bs9v5cew=; b=QCmvauoH0ocfBwN+C/QU0h7e/lSXBlEkPOYuqSTA1d4Pg8EQPWXFtz/RlqfYA1yMuQ QBgw1muNJQbGbOmyrQVjBAXBhgTLswHl70BSSsZN51FrP2uamgtsWuG9ivA7R63vHQZy 0K3EbJ6HxYDhuP8imJ5aLuCP+HVmZYWN0Y4lDi1P7/gUTefz/TzHHgOzRW69uwUP/ZQa CevaP85UlYw/T1JFWGC9ItG9sE5rCi4bFvuMU4YyDEObvkG261j7ynBDzBWPxBPJ4iDw dmOTxZiMp8/+qrxscPYEBTOnrVHs4kVGqC5QldTkWmbQqKDl2xIOryxBFQbl2Jp2mcjA fbcQ== X-Gm-Message-State: AGi0PuZkBkbcyV2k7hrV32EyuUMf+hduwk2R1RnfIc0F9oqV1W7Cr+wy D1UlHRzya3vRL2K6uSf4ZEk= X-Google-Smtp-Source: APiQypLxeRYL85Yfp7NqvJbDkFX8Zn2rtvi8+uBh0Q7eXtp4iLsVAYK8ybnOjPP+WDnbmJSBysldWw== X-Received: by 2002:a5d:4dcb:: with SMTP id f11mr16966244wru.174.1588573126967; Sun, 03 May 2020 23:18:46 -0700 (PDT) Received: from net.saheed (540018A9.dsl.pool.telekom.hu. [84.0.24.169]) by smtp.gmail.com with ESMTPSA id k23sm11559004wmi.46.2020.05.03.23.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 23:18:46 -0700 (PDT) From: refactormyself@gmail.com To: helgaas@kernel.org Cc: Bolarinwa Olayemi Saheed , bjorn@helgaas.com, yangyicong@hisilicon.com, skhan@linuxfoundation.org, linux-pci@vger.kernel.org Subject: [PATCH RFC 2/2] pci: Set all PCIBIOS_* error codes to generic error codes Date: Mon, 4 May 2020 07:18:12 +0200 Message-Id: <20200504051812.22662-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200504051812.22662-1-refactormyself@gmail.com> References: <20200504051812.22662-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bolarinwa Olayemi Saheed PCIBIOS_* error codes now set to negative value generic codes. pcibios_err_to_errno() is modified to reflect this changes and the function is now marked deprecated. The function now only returns negative error codes. These changes effect the consistency across pci and pcie accessors. Now they all return 0 on success and < 0, otherwise. Signed-off-by: Bolarinwa Olayemi Saheed Suggested-by: Yicong Yang --- include/linux/pci.h | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/include/linux/pci.h b/include/linux/pci.h index 3840a541a9de..ee87def7242a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -661,32 +661,31 @@ static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev) { return false; /* Error values that may be returned by PCI functions */ #define PCIBIOS_SUCCESSFUL 0x00 -#define PCIBIOS_FUNC_NOT_SUPPORTED 0x81 -#define PCIBIOS_BAD_VENDOR_ID 0x83 -#define PCIBIOS_DEVICE_NOT_FOUND 0x86 -#define PCIBIOS_BAD_REGISTER_NUMBER 0x87 -#define PCIBIOS_SET_FAILED 0x88 -#define PCIBIOS_BUFFER_TOO_SMALL 0x89 - -/* Translate above to generic errno for passing back through non-PCI code */ +#define PCIBIOS_FUNC_NOT_SUPPORTED -ENOENT +#define PCIBIOS_BAD_VENDOR_ID -ENOTTY +#define PCIBIOS_DEVICE_NOT_FOUND -ENODEV +#define PCIBIOS_BAD_REGISTER_NUMBER -EFAULT +#define PCIBIOS_SET_FAILED -EIO +#define PCIBIOS_BUFFER_TOO_SMALL -ENOSPC + +/* * + * Translate above to generic errno for passing back through non-PCI code + * + * Deprecated. Use the PCIBIOS_* directly without a translation. + */ static inline int pcibios_err_to_errno(int err) { - if (err <= PCIBIOS_SUCCESSFUL) - return err; /* Assume already errno */ + if (err == PCIBIOS_SUCCESSFUL) + return err; /* preserve success */ switch (err) { case PCIBIOS_FUNC_NOT_SUPPORTED: - return -ENOENT; case PCIBIOS_BAD_VENDOR_ID: - return -ENOTTY; case PCIBIOS_DEVICE_NOT_FOUND: - return -ENODEV; case PCIBIOS_BAD_REGISTER_NUMBER: - return -EFAULT; case PCIBIOS_SET_FAILED: - return -EIO; case PCIBIOS_BUFFER_TOO_SMALL: - return -ENOSPC; + return err; } return -ERANGE;