Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3351271pxa; Tue, 18 Aug 2020 13:01:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoCZHKQ/3fWFbFo9/VC7RHzAzBUp4Fgv6MzInBz8f9l5XUhw5imFIDVn6ljh7mLjSEsULj X-Received: by 2002:a05:6402:3193:: with SMTP id di19mr21896922edb.224.1597780904170; Tue, 18 Aug 2020 13:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597780904; cv=none; d=google.com; s=arc-20160816; b=JFqivS5pMH2isQlJ2dF/H5bseO4NfTDdt4PMgXGnIZ05gCTQXzDLHi1aVq6BxIIYsj AldiJ0nljOqVswffy4oMvXyuk+L2zEkb14zhehAViOjmpuWR1xtJ9jeKWf6mgTZVKeI0 ZgXm9g4hEOTuokA/Xv855YXS71hpBS1EhnHP2hAiRiZuqb8jiiDMB0PiygVGouClTOs3 h9mtFTsOPqs7/Qus3kiBzgW0a02Ry2eSX8eWnPftSjaciE1rkf9tLMijNQp1N24tee9t cRP+fBNXYplhwrggF/XFWhAVNB77abxmynDCH06nYTBEJnNZSuvLyJBu6dGx1ZEbnyD+ vD7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=/ZDCPDwW9euB1yf1r32n/nOxApA5CLlHLcrrfHIoPe0=; b=OoL2S38NkrcBlGJGC0W1AX4cUsqEO+o/5DfhHV9VcBrKD31fStRzfvcJQyM1mILgf5 rnbf9HI1XujvBsOYpQ4j5ngsLwQ26caV5qT6CxCBZTg+sP44wUhNAiJsPvPYIf/Po/1p OR2dPCRihe/oIuIgTUvgITva1WFgQnJaidbQ/4mMwLyhe6vdDHXeRkYCVDR7EYfkGvwi LXTB/fC8S7xXLaIjEJw8JmYjZ3ezYuN62cmQNHISXfJfjdt2eslEYl/SOQwWDB5wlI7D BJWYI4Am/6i6RzjL64CSsBwcO73jJFSOOGxN2ujI1vI6m/BKUml7YhpDzurveR+K6ECV Mpfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="mY9/qM2M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bc16si13790146edb.161.2020.08.18.13.01.20; Tue, 18 Aug 2020 13:01:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="mY9/qM2M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgHRUAG (ORCPT + 99 others); Tue, 18 Aug 2020 16:00:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726739AbgHRUAC (ORCPT ); Tue, 18 Aug 2020 16:00:02 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08CEFC061343 for ; Tue, 18 Aug 2020 13:00:02 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id g26so19510753qka.3 for ; Tue, 18 Aug 2020 13:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/ZDCPDwW9euB1yf1r32n/nOxApA5CLlHLcrrfHIoPe0=; b=mY9/qM2MC8h80QmH/L2o3ebU+oUQNUCW63wm7YBmbeK4YBE5Xe3Rjqtwof4g90Gl5j Nashil2BSJxW/GC+DcTms+MTs3zm8+LkClOf/U2jUP/YJlxAmvLXG+Y1SxzjQuQdOmRe FaeRrNHm7nBp0Ire6IgS6r1s0gdLxjr1afa0E+smJ3xN4nEInrIvlWBT7CW0TEmor1mO FIgviwqTSYceSMveg047w1orQVPvufjnGz94qi/TKhCr8AbTj6GPs3BxF/aFHmnO4n+M XlWMZtYVdzdVxOkWy4H/ual/TZMNFFmE2xwQGOV4ybgkF4mcBltQ5wgUueSnWH61nlUt zm4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/ZDCPDwW9euB1yf1r32n/nOxApA5CLlHLcrrfHIoPe0=; b=lV8vTQDxxhZueq9pTKIyU0rmcusokq1No6F/2k1l8aL4h2friqp/CjstSZx5I8OCpK NXfGXTwSS9Ftfb4oPXRXg+BBtXS7OOX4Povuxagn+VgnnymEqp1+G4luuUB7/nlSFStU DFzbxcY0ngLBJCCUFeawFVeJiLrDaEUOpygefc2pXr0X1AHkTK42wOFVZD+OvBi39uQ+ 1QGOzfjlZzbY9XFHMRM5XnxgLdeTKL5muwwWR3tVxDyLc17/8tuErfk2uJLIN35ebd/S TyJxrJg3tsgt4KRAhhe5ns9wAyMkDn2bmQVWTs3UamHWxOGZHA2gQEmvmm7XRrHFGvPW 6YsQ== X-Gm-Message-State: AOAM530WUymeh9v+dZE39oh4F6ZFrMgUjGUPKzQqnFdk6AD0orSwRmCU SKhmZ9gAMJLN0qCDLJR5OCu9AoIUeN4GL2oByttYHA== X-Received: by 2002:a37:a495:: with SMTP id n143mr19146148qke.330.1597780801253; Tue, 18 Aug 2020 13:00:01 -0700 (PDT) MIME-Version: 1.0 References: <20200801112446.149549-1-refactormyself@gmail.com> <20200801112446.149549-9-refactormyself@gmail.com> In-Reply-To: <20200801112446.149549-9-refactormyself@gmail.com> From: Bartosz Golaszewski Date: Tue, 18 Aug 2020 21:59:50 +0200 Message-ID: Subject: Re: [RFC PATCH 08/17] gpio: Drop uses of pci_read_config_*() return value To: Bjorn Helgaas Cc: Linus Walleij , "Saheed O. Bolarinwa" , bjorn@helgaas.com, Shuah Khan , linux-kernel-mentees@lists.linuxfoundation.org, linux-pci@vger.kernel.org, LKML , linux-gpio Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 1, 2020 at 2:24 PM Saheed O. Bolarinwa wrote: > > The return value of pci_read_config_*() may not indicate a device error. > However, the value read by these functions is more likely to indicate > this kind of error. This presents two overlapping ways of reporting > errors and complicates error checking. > > It is possible to move to one single way of checking for error if the > dependency on the return value of these functions is removed, then it > can later be made to return void. > > Remove all uses of the return value of pci_read_config_*(). > Check the actual value read for ~0. In this case, ~0 is an invalid > value thus it indicates some kind of error. > > Suggested-by: Bjorn Helgaas > Signed-off-by: Saheed O. Bolarinwa > --- > drivers/gpio/gpio-amd8111.c | 7 +++++-- > drivers/gpio/gpio-rdc321x.c | 21 ++++++++++++--------- > 2 files changed, 17 insertions(+), 11 deletions(-) > > diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c > index fdcebe59510d..7b9882380cbc 100644 > --- a/drivers/gpio/gpio-amd8111.c > +++ b/drivers/gpio/gpio-amd8111.c > @@ -198,9 +198,12 @@ static int __init amd_gpio_init(void) > goto out; > > found: > - err = pci_read_config_dword(pdev, 0x58, &gp.pmbase); > - if (err) > + pci_read_config_dword(pdev, 0x58, &gp.pmbase); > + if (gp.pmbase == (u32)~0) { > + err = -ENODEV; > goto out; > + } > + > err = -EIO; > gp.pmbase &= 0x0000FF00; > if (gp.pmbase == 0) > diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c > index 01ed2517e9fd..03f1ff07b844 100644 > --- a/drivers/gpio/gpio-rdc321x.c > +++ b/drivers/gpio/gpio-rdc321x.c > @@ -85,10 +85,13 @@ static int rdc_gpio_config(struct gpio_chip *chip, > gpch = gpiochip_get_data(chip); > > spin_lock(&gpch->lock); > - err = pci_read_config_dword(gpch->sb_pdev, gpio < 32 ? > - gpch->reg1_ctrl_base : gpch->reg2_ctrl_base, ®); > - if (err) > + pci_read_config_dword(gpch->sb_pdev, > + (gpio < 32) ? gpch->reg1_ctrl_base > + : gpch->reg2_ctrl_base, ®); > + if (reg == (u32)~0) { > + err = -ENODEV; > goto unlock; > + } > > reg |= 1 << (gpio & 0x1f); > > @@ -166,17 +169,17 @@ static int rdc321x_gpio_probe(struct platform_device *pdev) > /* This might not be, what others (BIOS, bootloader, etc.) > wrote to these registers before, but it's a good guess. Still > better than just using 0xffffffff. */ > - err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev, > + pci_read_config_dword(rdc321x_gpio_dev->sb_pdev, > rdc321x_gpio_dev->reg1_data_base, > &rdc321x_gpio_dev->data_reg[0]); > - if (err) > - return err; > + if (rdc321x_gpio_dev->data_reg[0] == (u32)~0) > + return -ENODEV; > > - err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev, > + pci_read_config_dword(rdc321x_gpio_dev->sb_pdev, > rdc321x_gpio_dev->reg2_data_base, > &rdc321x_gpio_dev->data_reg[1]); > - if (err) > - return err; > + if (rdc321x_gpio_dev->data_reg[1] == (u32)~0) > + return -ENODEV; > > dev_info(&pdev->dev, "registering %d GPIOs\n", > rdc321x_gpio_dev->chip.ngpio); > -- > 2.18.4 > Bjorn, I don't know the pci sub-system at all. Does this look good to you? Bartosz