Commit 31b2a73c authored by PrasannaKumar Muralidharan's avatar PrasannaKumar Muralidharan Committed by Herbert Xu

hwrng: amd - Migrate to managed API

Managed API eliminates error handling code, thus reduces several lines
of code.
Signed-off-by: default avatarPrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 58b022ac
...@@ -55,7 +55,6 @@ MODULE_DEVICE_TABLE(pci, pci_tbl); ...@@ -55,7 +55,6 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
struct amd768_priv { struct amd768_priv {
void __iomem *iobase; void __iomem *iobase;
struct pci_dev *pcidev; struct pci_dev *pcidev;
u32 pmbase;
}; };
static int amd_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) static int amd_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
...@@ -149,58 +148,33 @@ static int __init mod_init(void) ...@@ -149,58 +148,33 @@ static int __init mod_init(void)
if (pmbase == 0) if (pmbase == 0)
return -EIO; return -EIO;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (IS_ERR(priv))
return -ENOMEM; return PTR_ERR(priv);
if (!request_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE, DRV_NAME)) { if (!devm_request_region(&pdev->dev, pmbase + PMBASE_OFFSET,
PMBASE_SIZE, DRV_NAME)) {
dev_err(&pdev->dev, DRV_NAME " region 0x%x already in use!\n", dev_err(&pdev->dev, DRV_NAME " region 0x%x already in use!\n",
pmbase + 0xF0); pmbase + 0xF0);
err = -EBUSY; return -EBUSY;
goto out;
} }
priv->iobase = ioport_map(pmbase + PMBASE_OFFSET, PMBASE_SIZE); priv->iobase = devm_ioport_map(&pdev->dev, pmbase + PMBASE_OFFSET,
if (!priv->iobase) { PMBASE_SIZE);
if (IS_ERR(priv->iobase)) {
pr_err(DRV_NAME "Cannot map ioport\n"); pr_err(DRV_NAME "Cannot map ioport\n");
err = -EINVAL; return PTR_ERR(priv->iobase);
goto err_iomap;
} }
amd_rng.priv = (unsigned long)priv; amd_rng.priv = (unsigned long)priv;
priv->pmbase = pmbase;
priv->pcidev = pdev; priv->pcidev = pdev;
pr_info(DRV_NAME " detected\n"); pr_info(DRV_NAME " detected\n");
err = hwrng_register(&amd_rng); return devm_hwrng_register(&pdev->dev, &amd_rng);
if (err) {
pr_err(DRV_NAME " registering failed (%d)\n", err);
goto err_hwrng;
}
return 0;
err_hwrng:
ioport_unmap(priv->iobase);
err_iomap:
release_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE);
out:
kfree(priv);
return err;
} }
static void __exit mod_exit(void) static void __exit mod_exit(void)
{ {
struct amd768_priv *priv;
priv = (struct amd768_priv *)amd_rng.priv;
hwrng_unregister(&amd_rng);
ioport_unmap(priv->iobase);
release_region(priv->pmbase + PMBASE_OFFSET, PMBASE_SIZE);
kfree(priv);
} }
module_init(mod_init); module_init(mod_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment