* [PATCH] PCI/VPD: Add helper pci_get_func0_dev
@ 2021-04-16 19:52 Heiner Kallweit
2021-04-16 21:22 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Heiner Kallweit @ 2021-04-16 19:52 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci
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>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI/VPD: Add helper pci_get_func0_dev
2021-04-16 19:52 [PATCH] PCI/VPD: Add helper pci_get_func0_dev Heiner Kallweit
@ 2021-04-16 21:22 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2021-04-16 21:22 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: Bjorn Helgaas, linux-pci
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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-16 21:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 19:52 [PATCH] PCI/VPD: Add helper pci_get_func0_dev Heiner Kallweit
2021-04-16 21:22 ` Bjorn Helgaas
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.