Skip to content

Commit 7869b48

Browse files
ZheyuMabrgl
authored andcommitted
gpio: ml-ioh: Convert to use managed functions pcim* and devm_*
When removing the module, we will get the following flaw: [ 14.204955] remove_proc_entry: removing non-empty directory 'irq/21', leaking at least 'gpio_ml_ioh' [ 14.205827] WARNING: CPU: 0 PID: 305 at fs/proc/generic.c:717 remove_proc_entry+0x389/0x3f0 ... [ 14.220613] ioh_gpio_remove+0xc5/0xe0 [gpio_ml_ioh] [ 14.221075] pci_device_remove+0x92/0x240 Fix this by using managed functions, this makes the error handling more simpler. Fixes: e971ac9 ("gpio: ml-ioh: use resource management for irqs") Signed-off-by: Zheyu Ma <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent a998ec3 commit 7869b48

File tree

1 file changed

+16
-60
lines changed

1 file changed

+16
-60
lines changed

drivers/gpio/gpio-ml-ioh.c

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -409,29 +409,27 @@ static int ioh_gpio_probe(struct pci_dev *pdev,
409409
void *chip_save;
410410
int irq_base;
411411

412-
ret = pci_enable_device(pdev);
412+
ret = pcim_enable_device(pdev);
413413
if (ret) {
414-
dev_err(dev, "%s : pci_enable_device failed", __func__);
415-
goto err_pci_enable;
414+
dev_err(dev, "%s : pcim_enable_device failed", __func__);
415+
return ret;
416416
}
417417

418-
ret = pci_request_regions(pdev, KBUILD_MODNAME);
418+
ret = pcim_iomap_regions(pdev, BIT(1), KBUILD_MODNAME);
419419
if (ret) {
420-
dev_err(dev, "pci_request_regions failed-%d", ret);
421-
goto err_request_regions;
420+
dev_err(dev, "pcim_iomap_regions failed-%d", ret);
421+
return ret;
422422
}
423423

424-
base = pci_iomap(pdev, 1, 0);
424+
base = pcim_iomap_table(pdev)[1];
425425
if (!base) {
426-
dev_err(dev, "%s : pci_iomap failed", __func__);
427-
ret = -ENOMEM;
428-
goto err_iomap;
426+
dev_err(dev, "%s : pcim_iomap_table failed", __func__);
427+
return -ENOMEM;
429428
}
430429

431-
chip_save = kcalloc(8, sizeof(*chip), GFP_KERNEL);
430+
chip_save = devm_kcalloc(dev, 8, sizeof(*chip), GFP_KERNEL);
432431
if (chip_save == NULL) {
433-
ret = -ENOMEM;
434-
goto err_kzalloc;
432+
return -ENOMEM;
435433
}
436434

437435
chip = chip_save;
@@ -442,10 +440,10 @@ static int ioh_gpio_probe(struct pci_dev *pdev,
442440
chip->ch = i;
443441
spin_lock_init(&chip->spinlock);
444442
ioh_gpio_setup(chip, num_ports[i]);
445-
ret = gpiochip_add_data(&chip->gpio, chip);
443+
ret = devm_gpiochip_add_data(dev, &chip->gpio, chip);
446444
if (ret) {
447445
dev_err(dev, "IOH gpio: Failed to register GPIO\n");
448-
goto err_gpiochip_add;
446+
return ret;
449447
}
450448
}
451449

@@ -456,68 +454,27 @@ static int ioh_gpio_probe(struct pci_dev *pdev,
456454
if (irq_base < 0) {
457455
dev_warn(dev,
458456
"ml_ioh_gpio: Failed to get IRQ base num\n");
459-
ret = irq_base;
460-
goto err_gpiochip_add;
457+
return irq_base;
461458
}
462459
chip->irq_base = irq_base;
463460

464461
ret = ioh_gpio_alloc_generic_chip(chip,
465462
irq_base, num_ports[j]);
466463
if (ret)
467-
goto err_gpiochip_add;
464+
return ret;
468465
}
469466

470467
chip = chip_save;
471468
ret = devm_request_irq(dev, pdev->irq, ioh_gpio_handler,
472469
IRQF_SHARED, KBUILD_MODNAME, chip);
473470
if (ret != 0) {
474471
dev_err(dev, "%s request_irq failed\n", __func__);
475-
goto err_gpiochip_add;
472+
return ret;
476473
}
477474

478475
pci_set_drvdata(pdev, chip);
479476

480477
return 0;
481-
482-
err_gpiochip_add:
483-
chip = chip_save;
484-
while (--i >= 0) {
485-
gpiochip_remove(&chip->gpio);
486-
chip++;
487-
}
488-
kfree(chip_save);
489-
490-
err_kzalloc:
491-
pci_iounmap(pdev, base);
492-
493-
err_iomap:
494-
pci_release_regions(pdev);
495-
496-
err_request_regions:
497-
pci_disable_device(pdev);
498-
499-
err_pci_enable:
500-
501-
dev_err(dev, "%s Failed returns %d\n", __func__, ret);
502-
return ret;
503-
}
504-
505-
static void ioh_gpio_remove(struct pci_dev *pdev)
506-
{
507-
int i;
508-
struct ioh_gpio *chip = pci_get_drvdata(pdev);
509-
void *chip_save;
510-
511-
chip_save = chip;
512-
513-
for (i = 0; i < 8; i++, chip++)
514-
gpiochip_remove(&chip->gpio);
515-
516-
chip = chip_save;
517-
pci_iounmap(pdev, chip->base);
518-
pci_release_regions(pdev);
519-
pci_disable_device(pdev);
520-
kfree(chip);
521478
}
522479

523480
static int __maybe_unused ioh_gpio_suspend(struct device *dev)
@@ -558,7 +515,6 @@ static struct pci_driver ioh_gpio_driver = {
558515
.name = "ml_ioh_gpio",
559516
.id_table = ioh_gpio_pcidev_id,
560517
.probe = ioh_gpio_probe,
561-
.remove = ioh_gpio_remove,
562518
.driver = {
563519
.pm = &ioh_gpio_pm_ops,
564520
},

0 commit comments

Comments
 (0)