uio/uio_pci_generic: use device-managed function equivalents

This driver can be easily converted to use the device-managed allocator
function and the PCI managed enable function.

With these conversions the probe error paths are no longer needed and
neither is the remove function.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20201111113828.64992-1-alexandru.ardelean@analog.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Alexandru Ardelean 2020-11-11 13:38:28 +02:00 committed by Greg Kroah-Hartman
parent 667aef00f3
commit ef84928cff

View File

@ -74,23 +74,19 @@ static int probe(struct pci_dev *pdev,
struct uio_pci_generic_dev *gdev; struct uio_pci_generic_dev *gdev;
int err; int err;
err = pci_enable_device(pdev); err = pcim_enable_device(pdev);
if (err) { if (err) {
dev_err(&pdev->dev, "%s: pci_enable_device failed: %d\n", dev_err(&pdev->dev, "%s: pci_enable_device failed: %d\n",
__func__, err); __func__, err);
return err; return err;
} }
if (pdev->irq && !pci_intx_mask_supported(pdev)) { if (pdev->irq && !pci_intx_mask_supported(pdev))
err = -ENODEV; return -ENOMEM;
goto err_verify;
}
gdev = kzalloc(sizeof(struct uio_pci_generic_dev), GFP_KERNEL); gdev = devm_kzalloc(&pdev->dev, sizeof(struct uio_pci_generic_dev), GFP_KERNEL);
if (!gdev) { if (!gdev)
err = -ENOMEM; return -ENOMEM;
goto err_alloc;
}
gdev->info.name = "uio_pci_generic"; gdev->info.name = "uio_pci_generic";
gdev->info.version = DRIVER_VERSION; gdev->info.version = DRIVER_VERSION;
@ -105,34 +101,19 @@ static int probe(struct pci_dev *pdev,
"no support for interrupts?\n"); "no support for interrupts?\n");
} }
err = uio_register_device(&pdev->dev, &gdev->info); err = devm_uio_register_device(&pdev->dev, &gdev->info);
if (err) if (err)
goto err_register; return err;
pci_set_drvdata(pdev, gdev); pci_set_drvdata(pdev, gdev);
return 0; return 0;
err_register:
kfree(gdev);
err_alloc:
err_verify:
pci_disable_device(pdev);
return err;
}
static void remove(struct pci_dev *pdev)
{
struct uio_pci_generic_dev *gdev = pci_get_drvdata(pdev);
uio_unregister_device(&gdev->info);
pci_disable_device(pdev);
kfree(gdev);
} }
static struct pci_driver uio_pci_driver = { static struct pci_driver uio_pci_driver = {
.name = "uio_pci_generic", .name = "uio_pci_generic",
.id_table = NULL, /* only dynamic id's */ .id_table = NULL, /* only dynamic id's */
.probe = probe, .probe = probe,
.remove = remove,
}; };
module_pci_driver(uio_pci_driver); module_pci_driver(uio_pci_driver);