A RNG driver for Armada 3720 boards running the Turris Mox rWTM firmware
from CZ.NIC in the secure processor.

Signed-off-by: Max Resch <[email protected]>
---

Changes in v3:
 - More meaningful variable names in accordance with review

Changes in v2:
 - Removed ring buffer implementation

 drivers/rng/turris_rwtm_rng.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/rng/turris_rwtm_rng.c b/drivers/rng/turris_rwtm_rng.c
index 143fe0b47f..ec2cb0bca3 100644
--- a/drivers/rng/turris_rwtm_rng.c
+++ b/drivers/rng/turris_rwtm_rng.c
@@ -41,18 +41,19 @@ static int turris_rwtm_rng_fill_entropy(phys_addr_t 
entropy, size_t size)
 
 static int turris_rwtm_rng_random_read(struct udevice *dev, void *data, size_t 
count)
 {
-       phys_addr_t p;
+       struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
+       phys_addr_t phys;
        size_t size;
        int ret;
 
-       p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
+       phys = priv->buffer;
 
        while (count) {
                size = min_t(size_t, RNG_BUFFER_SIZE, count);
 
-               ret = turris_rwtm_rng_fill_entropy(p, size);
+               ret = turris_rwtm_rng_fill_entropy(phys, size);
 
-               memcpy(data, (void *)p, size);
+               memcpy(data, (void *)phys, size);
                count -= size;
                data = (u8 *)data + size;
        }
@@ -62,7 +63,7 @@ static int turris_rwtm_rng_random_read(struct udevice *dev, 
void *data, size_t c
 
 static int turris_rwtm_rng_probe(struct udevice *dev)
 {
-       struct turris_rwtm_rng_priv *priv;
+       struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
        u32 args[] = { 0 };
        int ret;
 
@@ -76,7 +77,6 @@ static int turris_rwtm_rng_probe(struct udevice *dev)
                return ret;
 
        /* entropy buffer */
-       priv = (struct turris_rwtm_rng_priv *)dev_get_priv(dev);
        priv->buffer = 0;
 
        /* buffer address need to be aligned */
@@ -89,10 +89,10 @@ static int turris_rwtm_rng_probe(struct udevice *dev)
 
 static int turris_rwtm_rng_remove(struct udevice *dev)
 {
-       phys_addr_t p;
+       struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
+       phys_addr_t phys = priv->buffer;
 
-       p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
-       dma_free_coherent((void *)p);
+       dma_free_coherent((void *)phys);
 
        return 0;
 }
-- 
2.43.0

Reply via email to