Skip to contentSkip to conversation

fpga: altera-cvp: fix 'bad IO access' on x86_64

PATCH In review Anatolij Gustschin 3 participants 3 messages Oct 30, 2018 – Nov 2, 2018 FPGA manager framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fpga: altera-cvp: fix 'bad IO access' on x86_64

If mapping the CvP BAR fails, we still can configure the FPGA via PCI config space access. In this case the iomap pointer is NULL. On x86_64, passing NULL address to pci_iounmap() generates "Bad IO access at port 0x0" output with stack call trace. Fix it.

---
 drivers/fpga/altera-cvp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/fpga/altera-cvp.c +4 -2
index 610a1558e0ed..144fa2a4d4cc 100644
@@ -477,7 +477,8 @@ static int altera_cvp_probe(struct pci_dev *pdev,
 	return 0;
 
 err_unmap:
-	pci_iounmap(pdev, conf->map);
+	if (conf->map)
+		pci_iounmap(pdev, conf->map);
 	pci_release_region(pdev, CVP_BAR);
 err_disable:
 	cmd &= ~PCI_COMMAND_MEMORY;
@@ -493,7 +494,8 @@ static void altera_cvp_remove(struct pci_dev *pdev)
 
 	driver_remove_file(&altera_cvp_driver.driver, &driver_attr_chkcfg);
 	fpga_mgr_unregister(mgr);
-	pci_iounmap(pdev, conf->map);
+	if (conf->map)
+		pci_iounmap(pdev, conf->map);
 	pci_release_region(pdev, CVP_BAR);
 	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
 	cmd &= ~PCI_COMMAND_MEMORY;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw

On Mon, Oct 29, 2018 at 11:08 AM Anatolij Gustschin <[email protected]> wrote:

Hi Anatolij,

Quoted 7 lines

If mapping the CvP BAR fails, we still can configure the FPGA via PCI config space access. In this case the iomap pointer is NULL. On x86_64, passing NULL address to pci_iounmap() generates "Bad IO access at port 0x0" output with stack call trace. Fix it.

Thanks for fixing this!

Alan

Quoted 31 lines
---
 drivers/fpga/altera-cvp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/fpga/altera-cvp.c +4 -3
index 610a1558e0ed..144fa2a4d4cc 100644
@@ -477,7 +477,8 @@ static int altera_cvp_probe(struct pci_dev *pdev,
        return 0;
 
 err_unmap:
-       pci_iounmap(pdev, conf->map);
+       if (conf->map)
+               pci_iounmap(pdev, conf->map);
        pci_release_region(pdev, CVP_BAR);
 err_disable:
        cmd &= ~PCI_COMMAND_MEMORY;
@@ -493,7 +494,8 @@ static void altera_cvp_remove(struct pci_dev *pdev)
 
        driver_remove_file(&altera_cvp_driver.driver, &driver_attr_chkcfg);
        fpga_mgr_unregister(mgr);
-       pci_iounmap(pdev, conf->map);
+       if (conf->map)
+               pci_iounmap(pdev, conf->map);
        pci_release_region(pdev, CVP_BAR);
        pci_read_config_word(pdev, PCI_COMMAND, &cmd);
        cmd &= ~PCI_COMMAND_MEMORY;
--

2.17.1

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Anatolij Gustschin

Hi Anatolij,

Quoted 6 lines · Anatolij Gustschin

If mapping the CvP BAR fails, we still can configure the FPGA via PCI config space access. In this case the iomap pointer is NULL. On x86_64, passing NULL address to pci_iounmap() generates "Bad IO access at port 0x0" output with stack call trace. Fix it.

Quoted 31 lines
---
 drivers/fpga/altera-cvp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/fpga/altera-cvp.c +4 -2
index 610a1558e0ed..144fa2a4d4cc 100644
@@ -477,7 +477,8 @@ static int altera_cvp_probe(struct pci_dev *pdev,
 	return 0;
 
 err_unmap:
-	pci_iounmap(pdev, conf->map);
+	if (conf->map)
+		pci_iounmap(pdev, conf->map);
 	pci_release_region(pdev, CVP_BAR);
 err_disable:
 	cmd &= ~PCI_COMMAND_MEMORY;
@@ -493,7 +494,8 @@ static void altera_cvp_remove(struct pci_dev *pdev)
 
 	driver_remove_file(&altera_cvp_driver.driver, &driver_attr_chkcfg);
 	fpga_mgr_unregister(mgr);
-	pci_iounmap(pdev, conf->map);
+	if (conf->map)
+		pci_iounmap(pdev, conf->map);
 	pci_release_region(pdev, CVP_BAR);
 	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
 	cmd &= ~PCI_COMMAND_MEMORY;
Signature · 1 line
2.17.1

Thanks for the patch,

Moritz