mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
Fix wait loop and void cast (#24)
* Simplify EINTR/ECANCEL error handling 1. Add semaphore uninterruptible wait function 2 .Replace semaphore wait loop with a single uninterruptible wait 3. Replace all sem_xxx to nxsem_xxx * Unify the void cast usage 1. Remove void cast for function because many place ignore the returned value witout cast 2. Replace void cast for variable with UNUSED macro
This commit is contained in:
+1
-1
@@ -251,7 +251,7 @@ static void blake2s_compress(FAR blake2s_state *S,
|
||||
#else
|
||||
/* Larger, slightly faster. */
|
||||
|
||||
(void)(round = 0);
|
||||
UNUSED(round);
|
||||
ROUND(0);
|
||||
ROUND(1);
|
||||
ROUND(2);
|
||||
|
||||
+1
-1
@@ -173,5 +173,5 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
|
||||
void devcrypto_register(void)
|
||||
{
|
||||
(void)register_driver("/dev/crypto", &g_cryptodevops, 0666, NULL);
|
||||
register_driver("/dev/crypto", &g_cryptodevops, 0666, NULL);
|
||||
}
|
||||
|
||||
+3
-32
@@ -453,7 +453,7 @@ void up_rngaddentropy(enum rnd_source_t kindof, FAR const uint32_t *buf,
|
||||
* reseeding too fast.
|
||||
*/
|
||||
|
||||
(void)clock_gettime(CLOCK_REALTIME, &ts);
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
tbuf[0] = ROTL_32(ts.tv_nsec, 17) ^ ROTL_32(ts.tv_sec, 3);
|
||||
tbuf[0] += ROTL_32(kindof, 27);
|
||||
tbuf[0] += ROTL_32((uintptr_t)&tbuf[0], 11);
|
||||
@@ -500,21 +500,7 @@ void up_rngaddentropy(enum rnd_source_t kindof, FAR const uint32_t *buf,
|
||||
|
||||
void up_rngreseed(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
do
|
||||
{
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
ret = nxsem_wait(&g_rng.rd_sem);
|
||||
|
||||
/* The only case that an error should occur here is if the wait was
|
||||
* awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == OK || ret == -EINTR);
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
nxsem_wait_uninterruptible(&g_rng.rd_sem);
|
||||
|
||||
if (g_rng.rd_newentr >= MIN_SEED_NEW_ENTROPY_WORDS)
|
||||
{
|
||||
@@ -563,22 +549,7 @@ void up_randompool_initialize(void)
|
||||
|
||||
void getrandom(FAR void *bytes, size_t nbytes)
|
||||
{
|
||||
int ret;
|
||||
|
||||
do
|
||||
{
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
ret = nxsem_wait(&g_rng.rd_sem);
|
||||
|
||||
/* The only case that an error should occur here is if the wait was
|
||||
* awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == OK || ret == -EINTR);
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
|
||||
nxsem_wait_uninterruptible(&g_rng.rd_sem);
|
||||
rng_buf_internal(bytes, nbytes);
|
||||
nxsem_post(&g_rng.rd_sem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user