Skip to contentSkip to conversation

spi: pca2xx-pci: Fix an issue about missing call to 'pci_free_irq_vectors()'

PATCH Superseded Dejin Zheng 5 participants 8 messages Feb 14, 2021 – Feb 15, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: pca2xx-pci: Fix an issue about missing call to 'pci_free_irq_vectors()'

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")
---
 drivers/spi/spi-pxa2xx-pci.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/spi/spi-pxa2xx-pci.c +10 -3
index 14fc41ed2361..1ec840e78ff4 100644
@@ -254,8 +254,10 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
 	snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
 	ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
 					   c->max_clk_rate);
-	 if (IS_ERR(ssp->clk))
-		return PTR_ERR(ssp->clk);
+	if (IS_ERR(ssp->clk)) {
+		ret = PTR_ERR(ssp->clk);
+		goto err_irq;
+	}
 
 	memset(&pi, 0, sizeof(pi));
 	pi.fwnode = dev->dev.fwnode;
@@ -268,12 +270,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
 	pdev = platform_device_register_full(&pi);
 	if (IS_ERR(pdev)) {
 		clk_unregister(ssp->clk);
-		return PTR_ERR(pdev);
+		ret = PTR_ERR(pdev);
+		goto err_irq;
 	}
 
 	pci_set_drvdata(dev, pdev);
 
 	return 0;
+err_irq:
+	pci_free_irq_vectors(dev);
+	return ret;
 }
 
 static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
@@ -283,6 +289,7 @@ static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
 
 	spi_pdata = dev_get_platdata(&pdev->dev);
 
+	pci_free_irq_vectors(dev);
 	platform_device_unregister(pdev);
 	clk_unregister(spi_pdata->ssp.clk);
 }
Signature · 1 line
2.25.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 46 lines · Dejin Zheng

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")
---
 drivers/spi/spi-pxa2xx-pci.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/spi/spi-pxa2xx-pci.c +9 -3
index 14fc41ed2361..1ec840e78ff4 100644
@@ -254,8 +254,10 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
 	snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
 	ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
 					   c->max_clk_rate);
-	 if (IS_ERR(ssp->clk))
-		return PTR_ERR(ssp->clk);
+	if (IS_ERR(ssp->clk)) {
+		ret = PTR_ERR(ssp->clk);
+		goto err_irq;
+	}
 
 	memset(&pi, 0, sizeof(pi));
 	pi.fwnode = dev->dev.fwnode;
@@ -268,12 +270,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
 	pdev = platform_device_register_full(&pi);
 	if (IS_ERR(pdev)) {
 		clk_unregister(ssp->clk);
-		return PTR_ERR(pdev);
+		ret = PTR_ERR(pdev);
+		goto err_irq;
 	}
 
 	pci_set_drvdata(dev, pdev);
 
 	return 0;
+err_irq:
+	pci_free_irq_vectors(dev);
+	return ret;
 }
 
 static void pxa2xx_spi_pci_remove(struct pci_dev *dev)

drivers/spi/spi-pxa2xx-pci.c static void pxa2xx_spi_pci_remove(struct pci_dev *dev) · line 295

Quoted 7 lines
drivers/spi/spi-pxa2xx-pci.c +1 -0
@@ -283,6 +289,7 @@ static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
 
 	spi_pdata = dev_get_platdata(&pdev->dev);
 
+	pci_free_irq_vectors(dev);
 	platform_device_unregister(pdev);
 	clk_unregister(spi_pdata->ssp.clk);
 }

Thanks!
Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
Reviewed-by
#2 lore raw
Quoted 49 lines · Jan Kiszka
Quoted 48 lines · Dejin Zheng

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")
---
  drivers/spi/spi-pxa2xx-pci.c | 13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
drivers/spi/spi-pxa2xx-pci.c +9 -3
index 14fc41ed2361..1ec840e78ff4 100644
@@ -254,8 +254,10 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
  	snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
  	ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
  					   c->max_clk_rate);
-	 if (IS_ERR(ssp->clk))
-		return PTR_ERR(ssp->clk);
+	if (IS_ERR(ssp->clk)) {
+		ret = PTR_ERR(ssp->clk);
+		goto err_irq;
+	}
 
  	memset(&pi, 0, sizeof(pi));
  	pi.fwnode = dev->dev.fwnode;
@@ -268,12 +270,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
  	pdev = platform_device_register_full(&pi);
  	if (IS_ERR(pdev)) {
  		clk_unregister(ssp->clk);
-		return PTR_ERR(pdev);
+		ret = PTR_ERR(pdev);
+		goto err_irq;
  	}
 
  	pci_set_drvdata(dev, pdev);
 
  	return 0;
+err_irq:
+	pci_free_irq_vectors(dev);
+	return ret;
  }
 
  static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
@@ -283,6 +289,7 @@ static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
 
  	spi_pdata = dev_get_platdata(&pdev->dev);
 
Quoted 8 lines

drivers/spi/spi-pxa2xx-pci.c static void pxa2xx_spi_pci_remove(struct pci_dev *dev) · line 295

Quoted 5 lines
drivers/spi/spi-pxa2xx-pci.c +1 -0
+	pci_free_irq_vectors(dev);
  	platform_device_unregister(pdev);
  	clk_unregister(spi_pdata->ssp.clk);
  }

Please fix pca2xx-pci -> pxa2xx-pci in the subject line. With that change you may add:

#3 lore raw
Quoted 52 lines · Jarkko Nikula
Quoted 42 lines · Jan Kiszka
Quoted 41 lines · Dejin Zheng

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")
---
  drivers/spi/spi-pxa2xx-pci.c | 13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
drivers/spi/spi-pxa2xx-pci.c +9 -3
index 14fc41ed2361..1ec840e78ff4 100644
@@ -254,8 +254,10 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
  	snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
  	ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
  					   c->max_clk_rate);
-	 if (IS_ERR(ssp->clk))
-		return PTR_ERR(ssp->clk);
+	if (IS_ERR(ssp->clk)) {
+		ret = PTR_ERR(ssp->clk);
+		goto err_irq;
+	}
  	memset(&pi, 0, sizeof(pi));
  	pi.fwnode = dev->dev.fwnode;
@@ -268,12 +270,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
  	pdev = platform_device_register_full(&pi);
  	if (IS_ERR(pdev)) {
  		clk_unregister(ssp->clk);
-		return PTR_ERR(pdev);
+		ret = PTR_ERR(pdev);
+		goto err_irq;
  	}
  	pci_set_drvdata(dev, pdev);
  	return 0;
+err_irq:
+	pci_free_irq_vectors(dev);
+	return ret;
  }
  static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
@@ -283,6 +289,7 @@ static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
Quoted 9 lines

drivers/spi/spi-pxa2xx-pci.c static void pxa2xx_spi_pci_remove(struct pci_dev *dev)

Quoted 6 lines
drivers/spi/spi-pxa2xx-pci.c +1 -0
  	spi_pdata = dev_get_platdata(&pdev->dev);
+	pci_free_irq_vectors(dev);
  	platform_device_unregister(pdev);
  	clk_unregister(spi_pdata->ssp.clk);
  }
 
Quoted 2 lines

Please fix pca2xx-pci -> pxa2xx-pci in the subject line. With that change you may add:

Jan and Jarkko, Thanks very much for your review. I will modify the subject name in patch v2, Thanks again!

Dejin

Quoted 2 lines
#4 lore raw
In reply to Dejin Zheng
Quoted 2 lines · Dejin Zheng

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

I'm wondering if you noticed that it's done by pcim_* API. Perhaps you can introduce pcim_alloc_irq_vectors() or so and do not add these calls at all?

Quoted 1 line
Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")

No, it doesn't fix anything.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Dejin Zheng

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

I'm wondering if you noticed that it's done by pcim_* API. Perhaps you can introduce pcim_alloc_irq_vectors() or so and do not add these calls at all?

You mean as plain wrapper for pci_alloc_irq_vectors, just to document it's managed?

Quoted 5 lines
Quoted 2 lines
Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")

No, it doesn't fix anything.

Ah, now I recall: imbalanced APIs.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#6 lore raw
Quoted 11 lines · Jan Kiszka
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Dejin Zheng

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

I'm wondering if you noticed that it's done by pcim_* API. Perhaps you can introduce pcim_alloc_irq_vectors() or so and do not add these calls at all?

You mean as plain wrapper for pci_alloc_irq_vectors, just to document it's managed?

Last time we discussed that with Christoph Hellwig he was on the side that naming is problematic. So he insisted that it's pure luck that it works like this. And IIUC his point, we need to create an explicit managed version of pci_alloc_irq_vectorrs() that the caller will have clear understanding what it does.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")

No, it doesn't fix anything.

Ah, now I recall: imbalanced APIs.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
In reply to Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Dejin Zheng

Call to 'pci_free_irq_vectors()' are missing both in the error handling path of the probe function, and in the remove function. So add them.

I'm wondering if you noticed that it's done by pcim_* API. Perhaps you can introduce pcim_alloc_irq_vectors() or so and do not add these calls at all?

Andy, Thanks for your reminder, You mean introduce pcim_alloc_irq_vectors() as like pcim_set_mwi() and free irq vectors by pcim_release()?

Quoted 10 lines
Quoted 2 lines
Fixes 64e02cb0bdfc7c ("spi: pca2xx-pci: Allow MSI")

No, it doesn't fix anything.

Signature · 2 lines
With Best Regards,
Andy Shevchenko