pci_endpoint_test: Fix module removal/insertion cycle
Subsystems (3)
cover pci_endpoint_test: Fix module removal/insertion cycle
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(-)
Signature · 1 line
2.11.0
PATCH 1/3 misc: pci_endpoint_test: Fix failure path return values in probe
Return value of pci_endpoint_test_probe is not set properly in a couple of failure cases. Fix it here.
--- drivers/misc/pci_endpoint_test.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/misc/pci_endpoint_test.c +2 -0
@@ -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; }
Signature · 1 line
2.11.0
PATCH 2/3 misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources on remove
In reply to Kishon Vijay Abraham Isscanf(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.
--- drivers/misc/pci_endpoint_test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/misc/pci_endpoint_test.c +10 -2
@@ -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])
Signature · 1 line
2.11.0
PATCH 3/3 misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi
In reply to Kishon Vijay Abraham Ipci_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.
--- drivers/misc/pci_endpoint_test.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/misc/pci_endpoint_test.c +8 -0
@@ -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);
Signature · 1 line
2.11.0
Bjorn Helgaas
AppliedQuoted 9 lines · Kishon Vijay Abraham I
This series fixes module removal/insertion cycle of
pci_endpoint_test.Without this series, when trying to modprobe
pci_endpoint_testafter rmmodpci_endpoint_testresults 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
Quoted 8 lines
Kishon Vijay Abraham I (3):
misc:pci_endpoint_test: Fix failure path return values in probe
misc:pci_endpoint_test: Fixpci_endpoint_testnot releasing resources
on remove
misc:pci_endpoint_test: FixBUG_ONerror duringpci_disable_msidrivers/misc/pci_endpoint_test.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
Applied to pci/endpoint for v4.15, thanks!