linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle
@ 2017-10-11  8:44 Kishon Vijay Abraham I
  2017-10-11  8:44 ` [PATCH 1/3] misc: pci_endpoint_test: Fix failure path return values in probe Kishon Vijay Abraham I
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Kishon Vijay Abraham I @ 2017-10-11  8:44 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Kishon Vijay Abraham I
  Cc: linux-pci, linux-omap, linux-kernel, nsekhar

This series fixes module removal/insertion cycle of pci_endpoint_test.

Without this series, when trying to modprobe pci_endpoint_test after
rmmod pci_endpoint_test results in the following errors.

pci-endpoint-test 0000:01:00.0: BAR 0: can't reserve [mem 0x20204600-0x202046ff]
pci-endpoint-test 0000:01:00.0: Cannot obtain PCI resources
pci-endpoint-test: probe of 0000:01:00.0 failed with error -16

Kishon Vijay Abraham I (3):
  misc: pci_endpoint_test: Fix failure path return values in probe
  misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources
    on remove
  misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi

 drivers/misc/pci_endpoint_test.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] misc: pci_endpoint_test: Fix failure path return values in probe
  2017-10-11  8:44 [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Kishon Vijay Abraham I
@ 2017-10-11  8:44 ` Kishon Vijay Abraham I
  2017-10-11  8:44 ` [PATCH 2/3] misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources on remove Kishon Vijay Abraham I
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kishon Vijay Abraham I @ 2017-10-11  8:44 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Kishon Vijay Abraham I
  Cc: linux-pci, linux-omap, linux-kernel, nsekhar

Return value of pci_endpoint_test_probe is not set properly in
a couple of failure cases. Fix it here.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index deb203026496..e787a63a321a 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -533,6 +533,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 
 	test->base = test->bar[test_reg_bar];
 	if (!test->base) {
+		err = -ENOMEM;
 		dev_err(dev, "Cannot perform PCI test without BAR%d\n",
 			test_reg_bar);
 		goto err_iounmap;
@@ -542,6 +543,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 
 	id = ida_simple_get(&pci_endpoint_test_ida, 0, 0, GFP_KERNEL);
 	if (id < 0) {
+		err = id;
 		dev_err(dev, "unable to get id\n");
 		goto err_iounmap;
 	}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources on remove
  2017-10-11  8:44 [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Kishon Vijay Abraham I
  2017-10-11  8:44 ` [PATCH 1/3] misc: pci_endpoint_test: Fix failure path return values in probe Kishon Vijay Abraham I
@ 2017-10-11  8:44 ` Kishon Vijay Abraham I
  2017-10-11  8:44 ` [PATCH 3/3] misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi Kishon Vijay Abraham I
  2017-10-17 19:16 ` [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Bjorn Helgaas
  3 siblings, 0 replies; 5+ messages in thread
From: Kishon Vijay Abraham I @ 2017-10-11  8:44 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Kishon Vijay Abraham I
  Cc: linux-pci, linux-omap, linux-kernel, nsekhar

sscanf(misc_device->name, DRV_MODULE_NAME ".%d", &id) in
pci_endpoint_test_remove returns '0' which results in
pci_endpoint_test_remove returning early without releasing the resources.
This is as a result of misc_device not having a valid name. Fix it here.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index e787a63a321a..5cb624b6fa0a 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -551,17 +551,24 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	snprintf(name, sizeof(name), DRV_MODULE_NAME ".%d", id);
 	misc_device = &test->miscdev;
 	misc_device->minor = MISC_DYNAMIC_MINOR;
-	misc_device->name = name;
+	misc_device->name = kstrdup(name, GFP_KERNEL);
+	if (!misc_device->name) {
+		err = -ENOMEM;
+		goto err_ida_remove;
+	}
 	misc_device->fops = &pci_endpoint_test_fops,
 
 	err = misc_register(misc_device);
 	if (err) {
 		dev_err(dev, "failed to register device\n");
-		goto err_ida_remove;
+		goto err_kfree_name;
 	}
 
 	return 0;
 
+err_kfree_name:
+	kfree(misc_device->name);
+
 err_ida_remove:
 	ida_simple_remove(&pci_endpoint_test_ida, id);
 
@@ -592,6 +599,7 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev)
 		return;
 
 	misc_deregister(&test->miscdev);
+	kfree(misc_device->name);
 	ida_simple_remove(&pci_endpoint_test_ida, id);
 	for (bar = BAR_0; bar <= BAR_5; bar++) {
 		if (test->bar[bar])
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi
  2017-10-11  8:44 [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Kishon Vijay Abraham I
  2017-10-11  8:44 ` [PATCH 1/3] misc: pci_endpoint_test: Fix failure path return values in probe Kishon Vijay Abraham I
  2017-10-11  8:44 ` [PATCH 2/3] misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources on remove Kishon Vijay Abraham I
@ 2017-10-11  8:44 ` Kishon Vijay Abraham I
  2017-10-17 19:16 ` [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Bjorn Helgaas
  3 siblings, 0 replies; 5+ messages in thread
From: Kishon Vijay Abraham I @ 2017-10-11  8:44 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Kishon Vijay Abraham I
  Cc: linux-pci, linux-omap, linux-kernel, nsekhar

pci_disable_msi throws a Kernel BUG if the driver has
successfully requested an irq and not released it. Fix it here by freeing
irqs before invoking pci_disable_msi.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 5cb624b6fa0a..086a7f85c2c0 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -92,6 +92,7 @@ struct pci_endpoint_test {
 	void __iomem	*bar[6];
 	struct completion irq_raised;
 	int		last_irq;
+	int		num_irqs;
 	/* mutex to protect the ioctls */
 	struct mutex	mutex;
 	struct miscdevice miscdev;
@@ -504,6 +505,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 		irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI);
 		if (irq < 0)
 			dev_err(dev, "failed to get MSI interrupts\n");
+		test->num_irqs = irq;
 	}
 
 	err = devm_request_irq(dev, pdev->irq, pci_endpoint_test_irqhandler,
@@ -578,6 +580,9 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 			pci_iounmap(pdev, test->bar[bar]);
 	}
 
+	for (i = 0; i < irq; i++)
+		devm_free_irq(dev, pdev->irq + i, test);
+
 err_disable_msi:
 	pci_disable_msi(pdev);
 	pci_release_regions(pdev);
@@ -591,6 +596,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 static void pci_endpoint_test_remove(struct pci_dev *pdev)
 {
 	int id;
+	int i;
 	enum pci_barno bar;
 	struct pci_endpoint_test *test = pci_get_drvdata(pdev);
 	struct miscdevice *misc_device = &test->miscdev;
@@ -605,6 +611,8 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev)
 		if (test->bar[bar])
 			pci_iounmap(pdev, test->bar[bar]);
 	}
+	for (i = 0; i < test->num_irqs; i++)
+		devm_free_irq(&pdev->dev, pdev->irq + i, test);
 	pci_disable_msi(pdev);
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle
  2017-10-11  8:44 [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Kishon Vijay Abraham I
                   ` (2 preceding siblings ...)
  2017-10-11  8:44 ` [PATCH 3/3] misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi Kishon Vijay Abraham I
@ 2017-10-17 19:16 ` Bjorn Helgaas
  3 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2017-10-17 19:16 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-pci, linux-omap,
	linux-kernel, nsekhar

On Wed, Oct 11, 2017 at 02:14:35PM +0530, Kishon Vijay Abraham I wrote:
> This series fixes module removal/insertion cycle of pci_endpoint_test.
> 
> Without this series, when trying to modprobe pci_endpoint_test after
> rmmod pci_endpoint_test results in the following errors.
> 
> pci-endpoint-test 0000:01:00.0: BAR 0: can't reserve [mem 0x20204600-0x202046ff]
> pci-endpoint-test 0000:01:00.0: Cannot obtain PCI resources
> pci-endpoint-test: probe of 0000:01:00.0 failed with error -16
> 
> Kishon Vijay Abraham I (3):
>   misc: pci_endpoint_test: Fix failure path return values in probe
>   misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources
>     on remove
>   misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi
> 
>  drivers/misc/pci_endpoint_test.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)

Applied to pci/endpoint for v4.15, thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-17 19:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-11  8:44 [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Kishon Vijay Abraham I
2017-10-11  8:44 ` [PATCH 1/3] misc: pci_endpoint_test: Fix failure path return values in probe Kishon Vijay Abraham I
2017-10-11  8:44 ` [PATCH 2/3] misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources on remove Kishon Vijay Abraham I
2017-10-11  8:44 ` [PATCH 3/3] misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi Kishon Vijay Abraham I
2017-10-17 19:16 ` [PATCH 0/3] pci_endpoint_test: Fix module removal/insertion cycle Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).