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: 9743245 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 2AA1D6032B for ; Tue, 23 May 2017 19:37:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AD232835B for ; Tue, 23 May 2017 19:37:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F810287FD; Tue, 23 May 2017 19:37:30 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E86A52835B for ; Tue, 23 May 2017 19:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YNkU7PFtDnL1dKHKSAK2QyWQlG+WEamR470M5j5lvjg=; b=QHuM7yFOH7eFt4 cy3Hfh5LJEre81l75eTIGNWziLd4qh/wnWpHHnTfHr1AL4OCOFwI6UPhHu6LeqM0MvAWz/4bVdkZ9 +alu65X9x6Rrk/wOJhWHCLH8QBxTTW89KFLCeOBqedz1Q7UHxrPfJrM25kERwJ+hjTYFlzq01NBBV 1ErK61SdKHuPP+TZf+Dez+9zWRckWiuNQI0sRmLf9mjfc5PeNMIjP5tviPWSkMXjk0fwyfhz8yTvP Tj9SshWB3fMNsz1emctCycloPv+Jzt4MWJQByKSDKa0gYhaGlOzasL81fJ4MvZpD4DqxAUBUVKRwn JulDMasERe2qfXqIE1Nw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dDFcW-0006LR-K6; Tue, 23 May 2017 19:37:28 +0000 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDFcP-0006A7-WD for linux-rockchip@lists.infradead.org; Tue, 23 May 2017 19:37:27 +0000 Received: by mail-pf0-x231.google.com with SMTP id 9so123884098pfj.1 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=qtv2YV7KKQHdtwW+FUItUYqZe0QqyKSQsnGO3RuW8CDfV+vVi+vTzpQp7I99uJYJCQ lmwZvNRGG+CS93JE5Dn0VKFgxS6EwC9tmfagHESNsL502PUEIHLaGQlHp9uCNHqhu3e6 Wrjl9Qnf48CpZlwB8OH2J87YKvloI8rt7fUislQmPlIVr732Zk6zlNrhzmvAXYBmBSxA oYbI/HTFz8GZcweREWhziswANs2UZMuqf1FQYT6WEmrwszpnegA4hL5DRR1J9ZW3xByr 8Kid+FbxZPm/NAHhJOGoqKLUZ/NjGszt2eqJeWSIrvS1M6Xo1MlbZKXqJlHGhd86QQUd 4mpQ== X-Gm-Message-State: AODbwcAUHINNdGpRirFLOCOEvjXtqUVGgW9NvqfUXwF1v9Sg7KfzQA8d 0kPCOdgKviNQR7W3 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170523_123722_090381_6BF21FE3 X-CRM114-Status: GOOD ( 15.32 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wei Zhang , linux-rockchip@lists.infradead.org, linux-pci@vger.kernel.org, Jeffy Chen , Keith Busch , Krishna Dhulipala , Bjorn Helgaas , Christoph Hellwig Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.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);