Skip to contentSkip to conversation

vdpa: solidrun: Replace deprecated PCI functions

PATCH Superseded Philipp Stanner 2 participants 2 messages Dec 2, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vdpa: solidrun: Replace deprecated PCI functions

The PCI functions

pcim_iomap_regions()
pcim_iounmap_regions()
pcim_iomap_table()

have been deprecated by the PCI subsystem.

Replace these functions with their successors pcim_iomap_region() and pcim_iounmap_region().

---
 drivers/vdpa/solidrun/snet_main.c | 55 ++++++++++++++-----------------
 1 file changed, 25 insertions(+), 30 deletions(-)
drivers/vdpa/solidrun/snet_main.c +25 -30
index c8b74980dbd1..679c1c7dabf5 100644
@@ -556,59 +556,57 @@ static const struct vdpa_config_ops snet_config_ops = {
 static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 {
 	char *name;
-	int ret, i, mask = 0;
+	int ret;
+	unsigned short i, bars_found = 0;
+	void __iomem *io;
+
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-bars", pci_name(pdev));
+	if (!name)
+		return -ENOMEM;
+
 	/* We don't know which BAR will be used to communicate..
 	 * We will map every bar with len > 0.
 	 *
 	 * Later, we will discover the BAR and unmap all other BARs.
 	 */
 	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
-		if (pci_resource_len(pdev, i))
-			mask |= (1 << i);
+		if (pci_resource_len(pdev, i) == 0)
+			continue;
+
+		io = pcim_iomap_region(pdev, i, name);
+		if (IS_ERR(io)) {
+			SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
+			return PTR_ERR(io);
+		}
+
+		psnet->bars[i] = io;
+		bars_found++;
 	}
 
 	/* No BAR can be used.. */
-	if (!mask) {
+	if (bars_found == 0) {
 		SNET_ERR(pdev, "Failed to find a PCI BAR\n");
 		return -ENODEV;
 	}
 
-	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-bars", pci_name(pdev));
-	if (!name)
-		return -ENOMEM;
-
-	ret = pcim_iomap_regions(pdev, mask, name);
-	if (ret) {
-		SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
-		return ret;
-	}
-
-	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
-		if (mask & (1 << i))
-			psnet->bars[i] = pcim_iomap_table(pdev)[i];
-	}
-
 	return 0;
 }
 
 static int snet_open_vf_bar(struct pci_dev *pdev, struct snet *snet)
 {
 	char *name;
-	int ret;
 
 	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "snet[%s]-bars", pci_name(pdev));
 	if (!name)
 		return -ENOMEM;
 
 	/* Request and map BAR */
-	ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
-	if (ret) {
+	snet->bar = pcim_iomap_region(pdev, snet->psnet->cfg.vf_bar, name);
+	if (IS_ERR(snet->bar)) {
 		SNET_ERR(pdev, "Failed to request and map PCI BAR for a VF\n");
-		return ret;
+		return PTR_ERR(snet->bar);
 	}
 
-	snet->bar = pcim_iomap_table(pdev)[snet->psnet->cfg.vf_bar];
-
 	return 0;
 }
 
@@ -656,15 +654,12 @@ static int psnet_detect_bar(struct psnet *psnet, u32 off)
 
 static void psnet_unmap_unused_bars(struct pci_dev *pdev, struct psnet *psnet)
 {
-	int i, mask = 0;
+	unsigned short i;
 
 	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
 		if (psnet->bars[i] && i != psnet->barno)
-			mask |= (1 << i);
+			pcim_iounmap_region(pdev, i);
 	}
-
-	if (mask)
-		pcim_iounmap_regions(pdev, mask);
 }
 
 /* Read SNET config from PCI BAR */
Signature · 1 line
2.47.0
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Philipp,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.13-rc1 next-20241128]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Philipp-Stanner/vdpa-solidrun-Replace-deprecated-PCI-functions/20241202-202728
base:   linus/master
patch link:    https://lore.kernel.org/r/20241202122353.9793-2-pstanner%40redhat.com
patch subject: [PATCH] vdpa: solidrun: Replace deprecated PCI functions
config: loongarch-allyesconfig (https://download.01.org/0day-ci/archive/20241203/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241203/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/vdpa/solidrun/snet_main.c: In function 'psnet_open_pf_bar':

>> drivers/vdpa/solidrun/snet_main.c:559:13: warning: unused variable 'ret' [-Wunused-variable]
     559 |         int ret;
         |             ^~~

vim +/ret +559 drivers/vdpa/solidrun/snet_main.c

555
556 static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
557 {
558 char *name;

 > 559		int ret;

560 unsigned short i, bars_found = 0;
561 void __iomem *io;
562
563 name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-bars", pci_name(pdev));
564 if (!name)
565 return -ENOMEM;
566
567 /* We don't know which BAR will be used to communicate..
568 * We will map every bar with len > 0.
569 *
570 * Later, we will discover the BAR and unmap all other BARs.
571 */
572 for (i = 0; i < PCI_STD_NUM_BARS; i++) {
573 if (pci_resource_len(pdev, i) == 0)
574 continue;
575
576 io = pcim_iomap_region(pdev, i, name);
577 if (IS_ERR(io)) {
578 SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
579 return PTR_ERR(io);
580 }
581
582 psnet->bars[i] = io;
583 bars_found++;
584 }
585
586 /* No BAR can be used.. */
587 if (bars_found == 0) {
588 SNET_ERR(pdev, "Failed to find a PCI BAR\n");
589 return -ENODEV;
590 }
591
592 return 0;
593 }
594

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki