hwrng: drivers - Use device-managed registration API
authorChuhong Yuan <hslester96@gmail.com>
Thu, 25 Jul 2019 08:01:55 +0000 (16:01 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 2 Aug 2019 04:44:33 +0000 (14:44 +1000)
Use devm_hwrng_register to simplify the implementation.
Manual unregistration and some remove functions can be
removed now.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
Acked-by: Ɓukasz Stelmach <l.stelmach@samsung.com>
Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/char/hw_random/atmel-rng.c
drivers/char/hw_random/cavium-rng-vf.c
drivers/char/hw_random/exynos-trng.c
drivers/char/hw_random/n2-drv.c
drivers/char/hw_random/nomadik-rng.c
drivers/char/hw_random/omap-rng.c
drivers/char/hw_random/powernv-rng.c
drivers/char/hw_random/st-rng.c
drivers/char/hw_random/xgene-rng.c

index 433426242b875c7297573e7985afabcdb569d25c..e55705745d5e42bf2b368ae231cfa5247bf2e628 100644 (file)
@@ -86,7 +86,7 @@ static int atmel_trng_probe(struct platform_device *pdev)
        trng->rng.name = pdev->name;
        trng->rng.read = atmel_trng_read;
 
-       ret = hwrng_register(&trng->rng);
+       ret = devm_hwrng_register(&pdev->dev, &trng->rng);
        if (ret)
                goto err_register;
 
@@ -103,7 +103,6 @@ static int atmel_trng_remove(struct platform_device *pdev)
 {
        struct atmel_trng *trng = platform_get_drvdata(pdev);
 
-       hwrng_unregister(&trng->rng);
 
        atmel_trng_disable(trng);
        clk_disable_unprepare(trng->clk);
index 2d1352b67168b96fb70fe13729f8dfb84262828e..3de4a6a443ef98ac3369228593147afd7cd1b862 100644 (file)
@@ -67,7 +67,7 @@ static int cavium_rng_probe_vf(struct pci_dev         *pdev,
 
        pci_set_drvdata(pdev, rng);
 
-       ret = hwrng_register(&rng->ops);
+       ret = devm_hwrng_register(&pdev->dev, &rng->ops);
        if (ret) {
                dev_err(&pdev->dev, "Error registering device as HWRNG.\n");
                return ret;
@@ -76,14 +76,6 @@ static int cavium_rng_probe_vf(struct        pci_dev         *pdev,
        return 0;
 }
 
-/* Remove the VF */
-static void  cavium_rng_remove_vf(struct pci_dev *pdev)
-{
-       struct cavium_rng *rng;
-
-       rng = pci_get_drvdata(pdev);
-       hwrng_unregister(&rng->ops);
-}
 
 static const struct pci_device_id cavium_rng_vf_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa033), 0, 0, 0},
@@ -95,7 +87,6 @@ static struct pci_driver cavium_rng_vf_driver = {
        .name           = "cavium_rng_vf",
        .id_table       = cavium_rng_vf_id_table,
        .probe          = cavium_rng_probe_vf,
-       .remove         = cavium_rng_remove_vf,
 };
 module_pci_driver(cavium_rng_vf_driver);
 
index 94235761955cea743952d6b8cd49ec87d57a0bfc..b4b52ab23b6b1cea2a77acc07ce6c0d1b647183a 100644 (file)
@@ -153,7 +153,7 @@ static int exynos_trng_probe(struct platform_device *pdev)
                goto err_clock;
        }
 
-       ret = hwrng_register(&trng->rng);
+       ret = devm_hwrng_register(&pdev->dev, &trng->rng);
        if (ret) {
                dev_err(&pdev->dev, "Could not register hwrng device.\n");
                goto err_register;
@@ -179,7 +179,6 @@ static int exynos_trng_remove(struct platform_device *pdev)
 {
        struct exynos_trng_dev *trng =  platform_get_drvdata(pdev);
 
-       hwrng_unregister(&trng->rng);
        clk_disable_unprepare(trng->clk);
 
        pm_runtime_put_sync(&pdev->dev);
index d4cab105796facc0ff31207e77883bc4560a0eef..2d256b3470db8595f7998552dbe9cf5ce3041c5e 100644 (file)
@@ -768,7 +768,7 @@ static int n2rng_probe(struct platform_device *op)
        np->hwrng.data_read = n2rng_data_read;
        np->hwrng.priv = (unsigned long) np;
 
-       err = hwrng_register(&np->hwrng);
+       err = devm_hwrng_register(&pdev->dev, &np->hwrng);
        if (err)
                goto out_hvapi_unregister;
 
@@ -793,8 +793,6 @@ static int n2rng_remove(struct platform_device *op)
 
        cancel_delayed_work_sync(&np->work);
 
-       hwrng_unregister(&np->hwrng);
-
        sun4v_hvapi_unregister(HV_GRP_RNG);
 
        return 0;
index fc0f6b0cb80da04e1bea95c653f60b89013a9b68..74ed29f42e4fe70eafa0f2e58df3922f1b26dc29 100644 (file)
@@ -57,7 +57,7 @@ static int nmk_rng_probe(struct amba_device *dev, const struct amba_id *id)
        if (!base)
                goto out_release;
        nmk_rng.priv = (unsigned long)base;
-       ret = hwrng_register(&nmk_rng);
+       ret = devm_hwrng_register(&dev->dev, &nmk_rng);
        if (ret)
                goto out_release;
        return 0;
@@ -71,7 +71,6 @@ out_clk:
 
 static int nmk_rng_remove(struct amba_device *dev)
 {
-       hwrng_unregister(&nmk_rng);
        amba_release_regions(dev);
        clk_disable(rng_clk);
        return 0;
index e9b6ac61fb7f64953e988c130d53f518ca3e7ab0..b27f39688b5e71de16650bb7a67c29a54b7539dd 100644 (file)
@@ -500,7 +500,7 @@ static int omap_rng_probe(struct platform_device *pdev)
        if (ret)
                goto err_register;
 
-       ret = hwrng_register(&priv->rng);
+       ret = devm_hwrng_register(&pdev->dev, &priv->rng);
        if (ret)
                goto err_register;
 
@@ -525,7 +525,6 @@ static int omap_rng_remove(struct platform_device *pdev)
 {
        struct omap_rng_dev *priv = platform_get_drvdata(pdev);
 
-       hwrng_unregister(&priv->rng);
 
        priv->pdata->cleanup(priv);
 
index f2e8272e276a23bf28a4c1db82e2f8e0dafbebcd..8da1d7917bdc45d78f2b0afef6c69cd31a6c2746 100644 (file)
@@ -33,18 +33,11 @@ static struct hwrng powernv_hwrng = {
        .read = powernv_rng_read,
 };
 
-static int powernv_rng_remove(struct platform_device *pdev)
-{
-       hwrng_unregister(&powernv_hwrng);
-
-       return 0;
-}
-
 static int powernv_rng_probe(struct platform_device *pdev)
 {
        int rc;
 
-       rc = hwrng_register(&powernv_hwrng);
+       rc = devm_hwrng_register(&pdev->dev, &powernv_hwrng);
        if (rc) {
                /* We only register one device, ignore any others */
                if (rc == -EEXIST)
@@ -70,7 +63,6 @@ static struct platform_driver powernv_rng_driver = {
                .of_match_table = powernv_rng_match,
        },
        .probe  = powernv_rng_probe,
-       .remove = powernv_rng_remove,
 };
 module_platform_driver(powernv_rng_driver);
 
index bd6a98b3479b79fea87d1c10fd774e4754da87a6..863448360a7dacf4bb6076ab5347a6a3280ac6ed 100644 (file)
@@ -102,7 +102,7 @@ static int st_rng_probe(struct platform_device *pdev)
 
        dev_set_drvdata(&pdev->dev, ddata);
 
-       ret = hwrng_register(&ddata->ops);
+       ret = devm_hwrng_register(&pdev->dev, &ddata->ops);
        if (ret) {
                dev_err(&pdev->dev, "Failed to register HW RNG\n");
                clk_disable_unprepare(clk);
@@ -118,8 +118,6 @@ static int st_rng_remove(struct platform_device *pdev)
 {
        struct st_rng_data *ddata = dev_get_drvdata(&pdev->dev);
 
-       hwrng_unregister(&ddata->ops);
-
        clk_disable_unprepare(ddata->clk);
 
        return 0;
index 8c6f9f63da5e8e6805e8b3b90f0cf65bbcdb867b..7e568db87ae29a782dffc84c3dece7ee6a291004 100644 (file)
@@ -361,7 +361,7 @@ static int xgene_rng_probe(struct platform_device *pdev)
 
        xgene_rng_func.priv = (unsigned long) ctx;
 
-       rc = hwrng_register(&xgene_rng_func);
+       rc = devm_hwrng_register(&pdev->dev, &xgene_rng_func);
        if (rc) {
                dev_err(&pdev->dev, "RNG registering failed error %d\n", rc);
                if (!IS_ERR(ctx->clk))
@@ -375,7 +375,6 @@ static int xgene_rng_probe(struct platform_device *pdev)
                        rc);
                if (!IS_ERR(ctx->clk))
                        clk_disable_unprepare(ctx->clk);
-               hwrng_unregister(&xgene_rng_func);
                return rc;
        }
 
@@ -392,7 +391,6 @@ static int xgene_rng_remove(struct platform_device *pdev)
                dev_err(&pdev->dev, "RNG init wakeup failed error %d\n", rc);
        if (!IS_ERR(ctx->clk))
                clk_disable_unprepare(ctx->clk);
-       hwrng_unregister(&xgene_rng_func);
 
        return rc;
 }