Skip to content

Commit

Permalink
rand32_entropy_device.c: remove atomic_t misuse
Browse files Browse the repository at this point in the history
There is no reason for storing a pointer into an atomic_t variable here.
Not only because this requires a dubious double cast that breaks on
64-bit builds as atomic_t is a 32-bit type, but also because the comment
in the code already admits that the whole operation isn't atomic anyway
and that it is fine. So let's keep things simple.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
  • Loading branch information
Nicolas Pitre authored and nashif committed May 30, 2019
1 parent 4afcc0f commit f94113d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions subsys/random/rand32_entropy_device.c
Expand Up @@ -8,11 +8,11 @@
#include <kernel.h>
#include <entropy.h>

static atomic_t entropy_driver;
static struct device *entropy_driver;

u32_t sys_rand32_get(void)
{
struct device *dev = (struct device *)atomic_get(&entropy_driver);
struct device *dev = entropy_driver;
u32_t random_num;
int ret;

Expand All @@ -25,7 +25,7 @@ u32_t sys_rand32_get(void)
"Device driver for %s (CONFIG_ENTROPY_NAME) not found. "
"Check your build configuration!",
CONFIG_ENTROPY_NAME);
atomic_set(&entropy_driver, (atomic_t)(uintptr_t)dev);
entropy_driver = dev;
}

ret = entropy_get_entropy(dev, (u8_t *)&random_num,
Expand Down

0 comments on commit f94113d

Please sign in to comment.