Skip to contentSkip to conversation

PCI: Use pci_dev_id() to simplify the code

PATCH Applied Xiongfeng Wang 2 participants 6 messages Aug 7, 2023 – Aug 8, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover PCI: Use pci_dev_id() to simplify the code

PCI core API pci_dev_id() can be used to get the BDF number for a pci device. We don't need to compose it mannually. Use pci_dev_id() to simplify the code and make the code more readable.

Xiongfeng Wang (3):
PCI: apple: use pci_dev_id() to simplify the code PCI/AER: Use pci_dev_id() to simplify the code PCI/IOV: Use pci_dev_id() to simplify the code

 drivers/pci/controller/pcie-apple.c | 4 ++--
 drivers/pci/iov.c                   | 3 +--
 drivers/pci/pcie/aer.c              | 4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 PCI: apple: use pci_dev_id() to simplify the code

PCI core API pci_dev_id() can be used to get the BDF number for a pci device. We don't need to compose it mannually using PCI_DEVID(). Use pci_dev_id() to simplify the code a little bit.

---
 drivers/pci/controller/pcie-apple.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-apple.c +2 -2
index 66f37e403a09..2abca318e22a 100644
@@ -670,7 +670,7 @@ static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev)
 static int apple_pcie_add_device(struct apple_pcie_port *port,
 				 struct pci_dev *pdev)
 {
-	u32 sid, rid = PCI_DEVID(pdev->bus->number, pdev->devfn);
+	u32 sid, rid = pci_dev_id(pdev);
 	int idx, err;
 
 	dev_dbg(&pdev->dev, "added to bus %s, index %d\n",
@@ -701,7 +701,7 @@ static int apple_pcie_add_device(struct apple_pcie_port *port,
 static void apple_pcie_release_device(struct apple_pcie_port *port,
 				      struct pci_dev *pdev)
 {
-	u32 rid = PCI_DEVID(pdev->bus->number, pdev->devfn);
+	u32 rid = pci_dev_id(pdev);
 	int idx;
 
 	mutex_lock(&port->pcie->lock);
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/3 PCI/AER: Use pci_dev_id() to simplify the code

In reply to Xiongfeng Wang

PCI core API pci_dev_id() can be used to get the BDF number for a pci device. We don't need to compose it mannually. Use pci_dev_id() to simplify the code a little bit.

---
 drivers/pci/pcie/aer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pcie/aer.c +2 -2
index f6c24ded134c..2bc03937452b 100644
@@ -712,7 +712,7 @@ static void __aer_print_error(struct pci_dev *dev,
 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
 {
 	int layer, agent;
-	int id = ((dev->bus->number << 8) | dev->devfn);
+	int id = pci_dev_id(dev);
 	const char *level;
 
 	if (!info->status) {
@@ -847,7 +847,7 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
 	if ((PCI_BUS_NUM(e_info->id) != 0) &&
 	    !(dev->bus->bus_flags & PCI_BUS_FLAGS_NO_AERSID)) {
 		/* Device ID match? */
-		if (e_info->id == ((dev->bus->number << 8) | dev->devfn))
+		if (e_info->id == pci_dev_id(dev))
 			return true;
 
 		/* Continue id comparing if there is no multiple error */
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/3 PCI/IOV: Use pci_dev_id() to simplify the code

In reply to Xiongfeng Wang

PCI core API pci_dev_id() can be used to get the BDF number for a pci device. We don't need to compose it mannually. Use pci_dev_id() to simplify the code a little bit.

---
 drivers/pci/iov.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pci/iov.c +1 -2
index b2e8322755c1..25dbe85c4217 100644
@@ -41,8 +41,7 @@ int pci_iov_vf_id(struct pci_dev *dev)
 		return -EINVAL;
 
 	pf = pci_physfn(dev);
-	return (((dev->bus->number << 8) + dev->devfn) -
-		((pf->bus->number << 8) + pf->devfn + pf->sriov->offset)) /
+	return (pci_dev_id(dev) - (pci_dev_id(pf) + pf->sriov->offset)) /
 	       pf->sriov->stride;
 }
 EXPORT_SYMBOL_GPL(pci_iov_vf_id);
Signature · 1 line
2.20.1
#4 lore raw
In reply to Xiongfeng Wang
Quoted 9 lines · Xiongfeng Wang

PCI core API pci_dev_id() can be used to get the BDF number for a pci device. We don't need to compose it mannually. Use pci_dev_id() to simplify the code and make the code more readable.

Xiongfeng Wang (3):
PCI: apple: use pci_dev_id() to simplify the code PCI/AER: Use pci_dev_id() to simplify the code PCI/IOV: Use pci_dev_id() to simplify the code

Quoted 4 lines
 drivers/pci/controller/pcie-apple.c | 4 ++--
 drivers/pci/iov.c                   | 3 +--
 drivers/pci/pcie/aer.c              | 4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)

Applied to pci/misc for v6.6, thanks!

There are several similar cases outside drivers/pci/ that it would be nice to clean up as well.

Bjorn

#5 lore raw
Quoted 15 lines · Bjorn Helgaas
Quoted 9 lines · Xiongfeng Wang

PCI core API pci_dev_id() can be used to get the BDF number for a pci device. We don't need to compose it mannually. Use pci_dev_id() to simplify the code and make the code more readable.

Xiongfeng Wang (3):
PCI: apple: use pci_dev_id() to simplify the code PCI/AER: Use pci_dev_id() to simplify the code PCI/IOV: Use pci_dev_id() to simplify the code

Quoted 4 lines
 drivers/pci/controller/pcie-apple.c | 4 ++--
 drivers/pci/iov.c                   | 3 +--
 drivers/pci/pcie/aer.c              | 4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)
Quoted 4 lines

Applied to pci/misc for v6.6, thanks!

There are several similar cases outside drivers/pci/ that it would be nice to clean up as well.

Sure, I will do that. Thanks !

Thanks,
Xiongfeng

Quoted 4 lines

Bjorn
.