From patchwork Tue May 23 19:36:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 9743243 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4D1156032B for ; Tue, 23 May 2017 19:37:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 361F4287F8 for ; Tue, 23 May 2017 19:37:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A5D0287FF; Tue, 23 May 2017 19:37:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83000287FD for ; Tue, 23 May 2017 19:37:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934490AbdEWThC (ORCPT ); Tue, 23 May 2017 15:37:02 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:35435 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935397AbdEWThC (ORCPT ); Tue, 23 May 2017 15:37:02 -0400 Received: by mail-pf0-f175.google.com with SMTP id n23so123895697pfb.2 for ; Tue, 23 May 2017 12:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HtfjE6euCM+5DmowTEmLrwmjCGZBsHWXwySXaUBuNbw=; b=IW5afl3EqGYT2TmYiAyUAIGiqw67haIUTrqMgACF5eoBtiTeMOMuXh4Tbn+fHlRvXP CZZnelXGKRUuDFWu0MQGSWs2AllyDdGFbcSzzkcBFUeUgTNSqPhqNkndOmnLLgI+FYhY G2/EoHXc07ZDt0oyRgRLvg0BrghTq7Xj49paw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HtfjE6euCM+5DmowTEmLrwmjCGZBsHWXwySXaUBuNbw=; b=A2yQJlAPXdUlF8WTJwoGnJUkPAaARSIU7o4FViKNoCUO2oqriFe3ug3xFJt/iZFRSn /s60CexXd7GlRwVaxjqNgg9SN66ZBMTuu1ttffllShmS/UREhV80Bl9A+pIJBA3h2Vc9 U+lLb1nhP0uwyWCFRCS7o6nrKNx2tOPEIZE97h3ow+o66bMAjnuenplVq8bRLVF05QRV zl0smu6WlR9oHhe2w70C0DQC1RziO4j+OtCHvt2U2BshPa3pSnbdSrbN/sNzXJik78qm MEAQj4m+Hht+0BQ0mZc2LSgsF0WZQ0wiCc3Ix3yUd23jdFN2WgNbKd4rBhjVMxXaGnjG u/yA== X-Gm-Message-State: AODbwcAHtmPXJ+gfYsvE2SNSZ+p0FQ8WInU9nViEXHyfXKDkZr6VRmu8 VKVrsnlu+9dmCG2k X-Received: by 10.98.89.201 with SMTP id k70mr33454594pfj.196.1495568221265; Tue, 23 May 2017 12:37:01 -0700 (PDT) Received: from google.com ([2620:0:1000:1301:2d91:7dbc:95c4:31df]) by smtp.gmail.com with ESMTPSA id g23sm2378300pfb.54.2017.05.23.12.37.00 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 23 May 2017 12:37:00 -0700 (PDT) Date: Tue, 23 May 2017 12:36:58 -0700 From: Brian Norris To: Shawn Lin , Bjorn Helgaas Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Jeffy Chen , linux-rockchip@lists.infradead.org, Krishna Dhulipala , Keith Busch , Christoph Hellwig , Wei Zhang Subject: [PATCH] PCI: Make error code types consistent in pci_{read,write}_config_* Message-ID: <20170523193655.GA144183@google.com> References: <1495177107-203736-1-git-send-email-shawn.lin@rock-chips.com> <20170523184359.GB115572@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170523184359.GB115572@google.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Callers normally treat the config space accessors as returning PCBIOS_* error codes, not Linux error codes (or they don't look at them at all). We have pcibios_err_to_errno(), in case the error code needs translated. Fixes: 4b1038834739 ("PCI: Don't attempt config access to disconnected devices") Signed-off-by: Brian Norris Reviewed-by: Keith Busch --- + others, change subject On Tue, May 23, 2017 at 11:44:01AM -0700, Brian Norris wrote: > But the high level code doesn't handle this > consistently. See, e.g., pci_read_config_byte() which can return regular > Linux error codes (like -ENODEV), except it also passes up the return > code of pci_read_config_byte() (a PCIBIOS_* code) directly. Apparently this is new (inconsistent) behavior in 4.12-rc1. Seems like an oversight to me. > So callers don't really know whether to treat the value from > pci_read_config_() as a PCIBIOS_* code (which should be translated > with pcibios_err_to_errno()) or as a standard Linux errno. > > But then, there are relatively few callers (less than 10% of > pci_read_config_(); even fewer for writes) that actually check the > error codes... > > Maybe the "fix" is to replace -ENODEV with PCIBIOS_DEVICE_NOT_FOUND for > the inconsistent cases (pci_{read,write}_config_{byte,word,dword}()). Fix implemented in the surrounding patch. drivers/pci/access.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/pci/access.c b/drivers/pci/access.c index 74cf5fffb1e1..c80e37a69305 100644 --- a/drivers/pci/access.c +++ b/drivers/pci/access.c @@ -896,7 +896,7 @@ int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val) { if (pci_dev_is_disconnected(dev)) { *val = ~0; - return -ENODEV; + return PCIBIOS_DEVICE_NOT_FOUND; } return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val); } @@ -906,7 +906,7 @@ int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val) { if (pci_dev_is_disconnected(dev)) { *val = ~0; - return -ENODEV; + return PCIBIOS_DEVICE_NOT_FOUND; } return pci_bus_read_config_word(dev->bus, dev->devfn, where, val); } @@ -917,7 +917,7 @@ int pci_read_config_dword(const struct pci_dev *dev, int where, { if (pci_dev_is_disconnected(dev)) { *val = ~0; - return -ENODEV; + return PCIBIOS_DEVICE_NOT_FOUND; } return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val); } @@ -926,7 +926,7 @@ EXPORT_SYMBOL(pci_read_config_dword); int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val) { if (pci_dev_is_disconnected(dev)) - return -ENODEV; + return PCIBIOS_DEVICE_NOT_FOUND; return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val); } EXPORT_SYMBOL(pci_write_config_byte); @@ -934,7 +934,7 @@ EXPORT_SYMBOL(pci_write_config_byte); int pci_write_config_word(const struct pci_dev *dev, int where, u16 val) { if (pci_dev_is_disconnected(dev)) - return -ENODEV; + return PCIBIOS_DEVICE_NOT_FOUND; return pci_bus_write_config_word(dev->bus, dev->devfn, where, val); } EXPORT_SYMBOL(pci_write_config_word); @@ -943,7 +943,7 @@ int pci_write_config_dword(const struct pci_dev *dev, int where, u32 val) { if (pci_dev_is_disconnected(dev)) - return -ENODEV; + return PCIBIOS_DEVICE_NOT_FOUND; return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val); } EXPORT_SYMBOL(pci_write_config_dword);