All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: Re: [PATCH] PCI/VPD: Add helper pci_get_func0_dev
Date: Fri, 16 Apr 2021 16:22:09 -0500	[thread overview]
Message-ID: <20210416212209.GA2758189@bjorn-Precision-5520> (raw)
In-Reply-To: <75d1f619-8a35-690d-8fc8-e851264a4bbb@gmail.com>

On Fri, Apr 16, 2021 at 09:52:07PM +0200, Heiner Kallweit wrote:
> The combined use of the PCI_DEVFN() and PCI_SLOT() macros in several
> places is unnecessarily complex. Use a simplified version and add
> a helper for it.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

Applied with pci_get_func0_dev() as follows to pci/vpd for v5.13.
It's true that "devfn & 0xf8" is simpler, but it also exposes
implementation details that need not be exposed here.

  diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
  index b23bbab6802d..03a02af5a6a7 100644
  --- a/drivers/pci/vpd.c
  +++ b/drivers/pci/vpd.c
  @@ -28,6 +28,11 @@ struct pci_vpd {
	  unsigned int	valid:1;
   };
   
  +static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev)
  +{
  +	return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
  +}
  +

> ---
>  drivers/pci/vpd.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
> index 42f762ab0..60573f27a 100644
> --- a/drivers/pci/vpd.c
> +++ b/drivers/pci/vpd.c
> @@ -28,6 +28,12 @@ struct pci_vpd {
>  	unsigned int	valid:1;
>  };
>  
> +static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev)
> +{
> +	/* bits 2:0 in devfn is the device function */
> +	return pci_get_slot(dev->bus, dev->devfn & 0xf8);
> +}
> +
>  /**
>   * pci_read_vpd - Read one entry from Vital Product Data
>   * @dev:	pci device struct
> @@ -305,8 +311,7 @@ static const struct pci_vpd_ops pci_vpd_ops = {
>  static ssize_t pci_vpd_f0_read(struct pci_dev *dev, loff_t pos, size_t count,
>  			       void *arg)
>  {
> -	struct pci_dev *tdev = pci_get_slot(dev->bus,
> -					    PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
> +	struct pci_dev *tdev = pci_get_func0_dev(dev);
>  	ssize_t ret;
>  
>  	if (!tdev)
> @@ -320,8 +325,7 @@ static ssize_t pci_vpd_f0_read(struct pci_dev *dev, loff_t pos, size_t count,
>  static ssize_t pci_vpd_f0_write(struct pci_dev *dev, loff_t pos, size_t count,
>  				const void *arg)
>  {
> -	struct pci_dev *tdev = pci_get_slot(dev->bus,
> -					    PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
> +	struct pci_dev *tdev = pci_get_func0_dev(dev);
>  	ssize_t ret;
>  
>  	if (!tdev)
> @@ -414,7 +418,7 @@ static void quirk_f0_vpd_link(struct pci_dev *dev)
>  	if (!PCI_FUNC(dev->devfn))
>  		return;
>  
> -	f0 = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
> +	f0 = pci_get_func0_dev(dev);
>  	if (!f0)
>  		return;
>  
> -- 
> 2.31.1
> 

      reply	other threads:[~2021-04-16 21:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 19:52 [PATCH] PCI/VPD: Add helper pci_get_func0_dev Heiner Kallweit
2021-04-16 21:22 ` Bjorn Helgaas [this message]

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=20210416212209.GA2758189@bjorn-Precision-5520 \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux-pci@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.