Commit ef0a1b26 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Herbert Xu

hwrng: iproc-rng200 - do not use static structure

Instead of using static hwrng structure that is reused between
binds/unbinds of the device let's embed it into driver's private
structure that we allocate. This way we are guaranteed not to stumble
onto something left from previous bind attempt.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 9052b0dd
...@@ -48,9 +48,12 @@ ...@@ -48,9 +48,12 @@
#define RNG_FIFO_COUNT_RNG_FIFO_COUNT_MASK 0x000000FF #define RNG_FIFO_COUNT_RNG_FIFO_COUNT_MASK 0x000000FF
struct iproc_rng200_dev { struct iproc_rng200_dev {
struct hwrng rng;
void __iomem *base; void __iomem *base;
}; };
#define to_rng_priv(rng) container_of(rng, struct iproc_rng200_dev, rng)
static void iproc_rng200_restart(void __iomem *rng_base) static void iproc_rng200_restart(void __iomem *rng_base)
{ {
uint32_t val; uint32_t val;
...@@ -91,9 +94,9 @@ static void iproc_rng200_restart(void __iomem *rng_base) ...@@ -91,9 +94,9 @@ static void iproc_rng200_restart(void __iomem *rng_base)
static int iproc_rng200_read(struct hwrng *rng, void *buf, size_t max, static int iproc_rng200_read(struct hwrng *rng, void *buf, size_t max,
bool wait) bool wait)
{ {
uint32_t status; struct iproc_rng200_dev *priv = to_rng_priv(rng);
uint32_t num_remaining = max; uint32_t num_remaining = max;
struct iproc_rng200_dev *priv = (struct iproc_rng200_dev *)rng->priv; uint32_t status;
#define MAX_RESETS_PER_READ 1 #define MAX_RESETS_PER_READ 1
uint32_t num_resets = 0; uint32_t num_resets = 0;
...@@ -151,10 +154,8 @@ static int iproc_rng200_read(struct hwrng *rng, void *buf, size_t max, ...@@ -151,10 +154,8 @@ static int iproc_rng200_read(struct hwrng *rng, void *buf, size_t max,
static int iproc_rng200_init(struct hwrng *rng) static int iproc_rng200_init(struct hwrng *rng)
{ {
struct iproc_rng200_dev *priv = to_rng_priv(rng);
uint32_t val; uint32_t val;
struct iproc_rng200_dev *priv;
priv = (struct iproc_rng200_dev *)rng->priv;
/* Setup RNG. */ /* Setup RNG. */
val = ioread32(priv->base + RNG_CTRL_OFFSET); val = ioread32(priv->base + RNG_CTRL_OFFSET);
...@@ -167,10 +168,8 @@ static int iproc_rng200_init(struct hwrng *rng) ...@@ -167,10 +168,8 @@ static int iproc_rng200_init(struct hwrng *rng)
static void iproc_rng200_cleanup(struct hwrng *rng) static void iproc_rng200_cleanup(struct hwrng *rng)
{ {
struct iproc_rng200_dev *priv = to_rng_priv(rng);
uint32_t val; uint32_t val;
struct iproc_rng200_dev *priv;
priv = (struct iproc_rng200_dev *)rng->priv;
/* Disable RNG hardware */ /* Disable RNG hardware */
val = ioread32(priv->base + RNG_CTRL_OFFSET); val = ioread32(priv->base + RNG_CTRL_OFFSET);
...@@ -179,13 +178,6 @@ static void iproc_rng200_cleanup(struct hwrng *rng) ...@@ -179,13 +178,6 @@ static void iproc_rng200_cleanup(struct hwrng *rng)
iowrite32(val, priv->base + RNG_CTRL_OFFSET); iowrite32(val, priv->base + RNG_CTRL_OFFSET);
} }
static struct hwrng iproc_rng200_ops = {
.name = "iproc-rng200",
.read = iproc_rng200_read,
.init = iproc_rng200_init,
.cleanup = iproc_rng200_cleanup,
};
static int iproc_rng200_probe(struct platform_device *pdev) static int iproc_rng200_probe(struct platform_device *pdev)
{ {
struct iproc_rng200_dev *priv; struct iproc_rng200_dev *priv;
...@@ -193,13 +185,10 @@ static int iproc_rng200_probe(struct platform_device *pdev) ...@@ -193,13 +185,10 @@ static int iproc_rng200_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
int ret; int ret;
priv = devm_kzalloc(dev, sizeof(struct iproc_rng200_dev), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
iproc_rng200_ops.priv = (unsigned long)priv;
platform_set_drvdata(pdev, priv);
/* Map peripheral */ /* Map peripheral */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res) {
...@@ -213,13 +202,20 @@ static int iproc_rng200_probe(struct platform_device *pdev) ...@@ -213,13 +202,20 @@ static int iproc_rng200_probe(struct platform_device *pdev)
return PTR_ERR(priv->base); return PTR_ERR(priv->base);
} }
priv->rng.name = "iproc-rng200",
priv->rng.read = iproc_rng200_read,
priv->rng.init = iproc_rng200_init,
priv->rng.cleanup = iproc_rng200_cleanup,
/* Register driver */ /* Register driver */
ret = hwrng_register(&iproc_rng200_ops); ret = hwrng_register(&priv->rng);
if (ret) { if (ret) {
dev_err(dev, "hwrng registration failed\n"); dev_err(dev, "hwrng registration failed\n");
return ret; return ret;
} }
platform_set_drvdata(pdev, priv);
dev_info(dev, "hwrng registered\n"); dev_info(dev, "hwrng registered\n");
return 0; return 0;
...@@ -227,8 +223,10 @@ static int iproc_rng200_probe(struct platform_device *pdev) ...@@ -227,8 +223,10 @@ static int iproc_rng200_probe(struct platform_device *pdev)
static int iproc_rng200_remove(struct platform_device *pdev) static int iproc_rng200_remove(struct platform_device *pdev)
{ {
struct iproc_rng200_dev *priv = platform_get_drvdata(pdev);
/* Unregister driver */ /* Unregister driver */
hwrng_unregister(&iproc_rng200_ops); hwrng_unregister(&priv->rng);
return 0; return 0;
} }
......
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