Skip to content

Commit

Permalink
hwrng: geode - Migrate to managed API
Browse files Browse the repository at this point in the history
Use devm_ioremap and devm_hwrng_register instead of ioremap and
hwrng_register. This removes error handling code. Also moved code around
by removing goto statements. This improves code readability.

Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
PrasannaKumar Muralidharan authored and Herbert Xu committed Sep 13, 2016
1 parent 94879fa commit 6e9b5e7
Showing 1 changed file with 15 additions and 35 deletions.
50 changes: 15 additions & 35 deletions drivers/char/hw_random/geode-rng.c
Original file line number Diff line number Diff line change
@@ -31,9 +31,6 @@
#include <linux/delay.h>
#include <asm/io.h>


#define PFX KBUILD_MODNAME ": "

#define GEODE_RNG_DATA_REG 0x50
#define GEODE_RNG_STATUS_REG 0x54

@@ -85,51 +82,34 @@ static struct hwrng geode_rng = {

static int __init mod_init(void)
{
int err = -ENODEV;
struct pci_dev *pdev = NULL;
const struct pci_device_id *ent;
void __iomem *mem;
unsigned long rng_base;

for_each_pci_dev(pdev) {
ent = pci_match_id(pci_tbl, pdev);
if (ent)
goto found;
}
/* Device not found. */
goto out;

found:
rng_base = pci_resource_start(pdev, 0);
if (rng_base == 0)
goto out;
err = -ENOMEM;
mem = ioremap(rng_base, 0x58);
if (!mem)
goto out;
geode_rng.priv = (unsigned long)mem;

pr_info("AMD Geode RNG detected\n");
err = hwrng_register(&geode_rng);
if (err) {
pr_err(PFX "RNG registering failed (%d)\n",
err);
goto err_unmap;
if (ent) {
rng_base = pci_resource_start(pdev, 0);
if (rng_base == 0)
return -ENODEV;

mem = devm_ioremap(&pdev->dev, rng_base, 0x58);
if (IS_ERR(mem))
return PTR_ERR(mem);
geode_rng.priv = (unsigned long)mem;

pr_info("AMD Geode RNG detected\n");
return devm_hwrng_register(&pdev->dev, &geode_rng);
}
}
out:
return err;

err_unmap:
iounmap(mem);
goto out;
/* Device not found. */
return -ENODEV;
}

static void __exit mod_exit(void)
{
void __iomem *mem = (void __iomem *)geode_rng.priv;

hwrng_unregister(&geode_rng);
iounmap(mem);
}

module_init(mod_init);

0 comments on commit 6e9b5e7

Please sign in to comment.