Skip to content

Commit

Permalink
[host] perform check before locking
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Jun 17, 2016
1 parent 359586f commit 10eb23a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions libknet/host.c
Expand Up @@ -157,7 +157,7 @@ int knet_host_remove(knet_handle_t knet_h, uint16_t host_id)
/*
* if links are configured we cannot release the host
*/

for (link_idx = 0; link_idx < KNET_MAX_LINK; link_idx++) {
if (host->link[link_idx].status.enabled) {
err = -1;
Expand Down Expand Up @@ -331,6 +331,11 @@ int knet_host_get_host_list(knet_handle_t knet_h,
return -1;
}

if ((!host_ids) || (!host_ids_entries)) {
errno = EINVAL;
return -1;
}

savederrno = pthread_rwlock_rdlock(&knet_h->global_rwlock);
if (savederrno) {
log_err(knet_h, KNET_SUB_HOST, "Unable to get read lock: %s",
Expand All @@ -339,14 +344,6 @@ int knet_host_get_host_list(knet_handle_t knet_h,
return -1;
}

if ((!host_ids) || (!host_ids_entries)) {
err = -1;
savederrno = EINVAL;
log_err(knet_h, KNET_SUB_HOST, "Unable to get host list: %s",
strerror(savederrno));
goto exit_unlock;
}

memmove(host_ids, knet_h->host_ids, sizeof(knet_h->host_ids));
*host_ids_entries = knet_h->host_ids_entries;

Expand Down

0 comments on commit 10eb23a

Please sign in to comment.