public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: platform-driver-x86@vger.kernel.org,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Lukas Wunner" <lukas@wunner.de>,
	linux-pci@vger.kernel.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH v3] platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe
Date: Tue, 26 Dec 2023 18:34:58 -0600	[thread overview]
Message-ID: <20231227003458.GA1485669@bhelgaas> (raw)
In-Reply-To: <20231225092656.2153894-1-shinichiro.kawasaki@wdc.com>

On Mon, Dec 25, 2023 at 06:26:56PM +0900, Shin'ichiro Kawasaki wrote:
> ...

> +static int p2sb_valid_resource(struct resource *res)
> +{
> +	return res->flags ? 0 : -ENOENT;
> +}

This got worse because it's *named* like a boolean, but the return
value can't be used like a boolean, which makes callers really hard to
read, e.g., this:

  if (p2sb_valid_resource(res))
    /* do something */

does exactly the opposite of what the reader expects.

I see that you want to use this -ENOENT return value in the callers:

> +static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn)
> +{
> + ...
> +	return p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res);
> +}

> + * 0 on success or appropriate errno value on error.
> + */
> +int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem)
> +{
> + ...
> +	ret = p2sb_valid_resource(&cache->res);
> +	if (ret)
> +		return ret;

But I think these would be much clearer as something like this:

  static bool p2sb_valid_resource(struct resource *res)
  {
    if (res->flags)
      return true;

    return false;
  }

  static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn)
  {
    ...
    if (!p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res))
      return -ENOENT;

    return 0;
  }

Bjorn

  reply	other threads:[~2023-12-27  0:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-25  9:26 [PATCH v3] platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe Shin'ichiro Kawasaki
2023-12-27  0:34 ` Bjorn Helgaas [this message]
2023-12-27  1:09   ` Shinichiro Kawasaki
2023-12-27 13:14     ` Bjorn Helgaas
2023-12-27 16:45       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231227003458.GA1485669@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=shinichiro.kawasaki@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox