Skip to content

Commit

Permalink
Various bug fixes and cleanups
Browse files Browse the repository at this point in the history
    - Do not unlock a mutex before it's locked.
    - Fix two casts.
    - Add braces for if clauses which only contain a macro.

Change-Id: I0b567733046647da71adec4fdc74a2488c6f8968
Co-authored-by: Yogaraj Alamenda <[email protected]>
Signed-off-by: Ismo Puustinen <[email protected]>
Signed-off-by: Yogaraj Alamenda <[email protected]>
Signed-off-by: Steve Linsell <[email protected]>
  • Loading branch information
2 people authored and stevelinsell committed Jun 11, 2019
1 parent 4a28c8d commit f8bc9db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions multi_thread_qaememutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ static void crypto_free_to_slab(void *ptr)
qae_slab_pools_local *tls_ptr =
(qae_slab_pools_local *)pthread_getspecific(qae_key);

qae_slot *slt = (void *)((unsigned char *)ptr - sizeof(qae_slot));
qae_slot *slt = (qae_slot *)((unsigned char *)ptr - sizeof(qae_slot));
if (!slt) {
MEM_WARN("Error freeing memory - unknown address\n");
return;
Expand Down Expand Up @@ -666,7 +666,7 @@ static int crypto_slot_get_size(void *ptr)
MEM_WARN("error can't find %p\n", ptr);
return 0;
}
qae_slot *slt = (void *)((unsigned char *)ptr - sizeof(qae_slot));
qae_slot *slt = (qae_slot *)((unsigned char *)ptr - sizeof(qae_slot));
if (slt->pool_index == (NUM_SLOT_SIZE - 1)) {
return MAX_ALLOC;
} else if (slt->pool_index >= 0 && slt->pool_index <= NUM_SLOT_SIZE - 2) {
Expand Down
12 changes: 7 additions & 5 deletions qae_mem_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ static void *crypto_alloc_from_slab(int size, const char *file, int line)

if (NULL == slb) {
MEM_WARN("error, create_slab failed - memory allocation error\n");
if ((rc = pthread_mutex_unlock(&crypto_bsal)) != 0)
if ((rc = pthread_mutex_unlock(&crypto_bsal)) != 0) {
MEM_WARN("pthread_mutex_unlock: %s\n", strerror(rc));
}
MEM_DEBUG("pthread_mutex_unlock\n");
goto exit;
}
Expand Down Expand Up @@ -549,8 +550,9 @@ static void *crypto_alloc_from_slab(int size, const char *file, int line)

result = (void *)((unsigned char *)slt + sizeof(qae_slot));

if ((rc = pthread_mutex_unlock(&crypto_bsal)) != 0)
if ((rc = pthread_mutex_unlock(&crypto_bsal)) != 0) {
MEM_WARN("pthread_mutex_unlock: %s\n", strerror(rc));
}
MEM_DEBUG("pthread_mutex_unlock\n");

exit:
Expand Down Expand Up @@ -599,10 +601,10 @@ static void crypto_free_slab(qae_slab *slb)
*****************************************************************************/
static void crypto_free_to_slab(void *ptr)
{
qae_slot *slt = (void *)((unsigned char *)ptr - sizeof(qae_slot));
qae_slot *slt = (qae_slot *)((unsigned char *)ptr - sizeof(qae_slot));
if (!slt) {
MEM_WARN("Error freeing memory - unknown address\n");
goto exit;
return;
}

qae_slab *slb = slt->slab;
Expand Down Expand Up @@ -691,7 +693,7 @@ static int crypto_slot_get_size(void *ptr)
MEM_WARN("error can't find %p\n", ptr);
return 0;
}
qae_slot *slt = (void *)((unsigned char *)ptr - sizeof(qae_slot));
qae_slot *slt = (qae_slot *)((unsigned char *)ptr - sizeof(qae_slot));
if (slt->pool_index == (NUM_SLOT_SIZE - 1)) {
return MAX_ALLOC;
} else if (slt->pool_index >= 0 && slt->pool_index <= NUM_SLOT_SIZE - 2) {
Expand Down

0 comments on commit f8bc9db

Please sign in to comment.