Skip to content

Commit

Permalink
Changes to resolve coverity issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Yogaraj Alamenda <yogarajx.alamenda@intel.com>
  • Loading branch information
paulturx authored and Yogaraj-Alamenda committed Jun 23, 2020
1 parent 244ecec commit c125c64
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 57 deletions.
48 changes: 25 additions & 23 deletions e_qat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,29 @@ QAT_R_SECRET_KEY_MALLOC_FAILURE:264:secret key malloc failure
QAT_R_SECRET_KEY_PDATA_MALLOC_FAILURE:265:secret key pdata malloc failure
QAT_R_SETUP_ASYNC_EVENT_FAILURE:266:setup async event failure
QAT_R_SET_ADDRESS_TRANSLATION_FAILURE:267:set address translation failure
QAT_R_SET_INSTANCE_FAILURE:268:set instance failure
QAT_R_SET_MULTIBUFF_RSA_METH_FAILURE:269:set multibuff rsa meth failure
QAT_R_SET_NOTIFICATION_CALLBACK_FAILURE:270:set notification callback failure
QAT_R_SET_POLLING_THREAD_AFFINITY_FAILURE:271:\
QAT_R_SET_FILE_DESCRIPTOR_NONBLOCKING_FAILURE:268:\
set file descriptor nonblocking failure
QAT_R_SET_INSTANCE_FAILURE:269:set instance failure
QAT_R_SET_MULTIBUFF_RSA_METH_FAILURE:270:set multibuff rsa meth failure
QAT_R_SET_NOTIFICATION_CALLBACK_FAILURE:271:set notification callback failure
QAT_R_SET_POLLING_THREAD_AFFINITY_FAILURE:272:\
set polling thread affinity failure
QAT_R_SET_PRIV_KEY_FAILURE:272:set priv key failure
QAT_R_SET_QAT_DSA_METH_FAILURE:273:set qat dsa meth failure
QAT_R_SET_QAT_RSA_METH_FAILURE:274:set qat rsa meth failure
QAT_R_SIG_GET_R_S_FAILURE:275:sig get r s failure
QAT_R_SIG_MALLOC_FAILURE:276:sig malloc failure
QAT_R_START_INSTANCE_FAILURE:277:start instance failure
QAT_R_STOP_INSTANCE_FAILURE:278:stop instance failure
QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL:279:sw get compute key pfunc null
QAT_R_SW_GET_KEYGEN_PFUNC_NULL:280:sw get keygen pfunc null
QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL:281:sw get sign sig pfunc null
QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL:282:sw get verify sig pfunc null
QAT_R_SW_METHOD_NULL:283:sw method null
QAT_R_S_NULL:284:s null
QAT_R_S_Q_COMPARE_FAILURE:285:s q compare failure
QAT_R_UNKNOWN_PADDING:286:unknown padding
QAT_R_UNKNOWN_PADDING_TYPE:287:unknown padding type
QAT_R_WAKE_PAUSE_JOB_FAILURE:288:wake pause job failure
QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE:289:x y tx ty bn malloc failure
QAT_R_Z_ALLOCATE_FAILURE:290:z allocate failure
QAT_R_SET_PRIV_KEY_FAILURE:273:set priv key failure
QAT_R_SET_QAT_DSA_METH_FAILURE:274:set qat dsa meth failure
QAT_R_SET_QAT_RSA_METH_FAILURE:275:set qat rsa meth failure
QAT_R_SIG_GET_R_S_FAILURE:276:sig get r s failure
QAT_R_SIG_MALLOC_FAILURE:277:sig malloc failure
QAT_R_START_INSTANCE_FAILURE:278:start instance failure
QAT_R_STOP_INSTANCE_FAILURE:279:stop instance failure
QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL:280:sw get compute key pfunc null
QAT_R_SW_GET_KEYGEN_PFUNC_NULL:281:sw get keygen pfunc null
QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL:282:sw get sign sig pfunc null
QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL:283:sw get verify sig pfunc null
QAT_R_SW_METHOD_NULL:284:sw method null
QAT_R_S_NULL:285:s null
QAT_R_S_Q_COMPARE_FAILURE:286:s q compare failure
QAT_R_UNKNOWN_PADDING:287:unknown padding
QAT_R_UNKNOWN_PADDING_TYPE:288:unknown padding type
QAT_R_WAKE_PAUSE_JOB_FAILURE:289:wake pause job failure
QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE:290:x y tx ty bn malloc failure
QAT_R_Z_ALLOCATE_FAILURE:291:z allocate failure
2 changes: 2 additions & 0 deletions e_qat_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ static ERR_STRING_DATA QAT_str_reasons[] = {
"setup async event failure"},
{ERR_PACK(0, 0, QAT_R_SET_ADDRESS_TRANSLATION_FAILURE),
"set address translation failure"},
{ERR_PACK(0, 0, QAT_R_SET_FILE_DESCRIPTOR_NONBLOCKING_FAILURE),
"set file descriptor nonblocking failure"},
{ERR_PACK(0, 0, QAT_R_SET_INSTANCE_FAILURE), "set instance failure"},
{ERR_PACK(0, 0, QAT_R_SET_MULTIBUFF_RSA_METH_FAILURE),
"set multibuff rsa meth failure"},
Expand Down
47 changes: 24 additions & 23 deletions e_qat_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,28 +273,29 @@ void ERR_QAT_error(int function, int reason, char *file, int line);
# define QAT_R_SECRET_KEY_PDATA_MALLOC_FAILURE 265
# define QAT_R_SETUP_ASYNC_EVENT_FAILURE 266
# define QAT_R_SET_ADDRESS_TRANSLATION_FAILURE 267
# define QAT_R_SET_INSTANCE_FAILURE 268
# define QAT_R_SET_MULTIBUFF_RSA_METH_FAILURE 269
# define QAT_R_SET_NOTIFICATION_CALLBACK_FAILURE 270
# define QAT_R_SET_POLLING_THREAD_AFFINITY_FAILURE 271
# define QAT_R_SET_PRIV_KEY_FAILURE 272
# define QAT_R_SET_QAT_DSA_METH_FAILURE 273
# define QAT_R_SET_QAT_RSA_METH_FAILURE 274
# define QAT_R_SIG_GET_R_S_FAILURE 275
# define QAT_R_SIG_MALLOC_FAILURE 276
# define QAT_R_START_INSTANCE_FAILURE 277
# define QAT_R_STOP_INSTANCE_FAILURE 278
# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 279
# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 280
# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 281
# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 282
# define QAT_R_SW_METHOD_NULL 283
# define QAT_R_S_NULL 284
# define QAT_R_S_Q_COMPARE_FAILURE 285
# define QAT_R_UNKNOWN_PADDING 286
# define QAT_R_UNKNOWN_PADDING_TYPE 287
# define QAT_R_WAKE_PAUSE_JOB_FAILURE 288
# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 289
# define QAT_R_Z_ALLOCATE_FAILURE 290
# define QAT_R_SET_FILE_DESCRIPTOR_NONBLOCKING_FAILURE 268
# define QAT_R_SET_INSTANCE_FAILURE 269
# define QAT_R_SET_MULTIBUFF_RSA_METH_FAILURE 270
# define QAT_R_SET_NOTIFICATION_CALLBACK_FAILURE 271
# define QAT_R_SET_POLLING_THREAD_AFFINITY_FAILURE 272
# define QAT_R_SET_PRIV_KEY_FAILURE 273
# define QAT_R_SET_QAT_DSA_METH_FAILURE 274
# define QAT_R_SET_QAT_RSA_METH_FAILURE 275
# define QAT_R_SIG_GET_R_S_FAILURE 276
# define QAT_R_SIG_MALLOC_FAILURE 277
# define QAT_R_START_INSTANCE_FAILURE 278
# define QAT_R_STOP_INSTANCE_FAILURE 279
# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 280
# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 281
# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 282
# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 283
# define QAT_R_SW_METHOD_NULL 284
# define QAT_R_S_NULL 285
# define QAT_R_S_Q_COMPARE_FAILURE 286
# define QAT_R_UNKNOWN_PADDING 287
# define QAT_R_UNKNOWN_PADDING_TYPE 288
# define QAT_R_WAKE_PAUSE_JOB_FAILURE 289
# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 290
# define QAT_R_Z_ALLOCATE_FAILURE 291

#endif
2 changes: 1 addition & 1 deletion qat_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ int qat_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
}
ret = qat_ecdsa_do_verify(dgst, dgst_len, s, eckey);
err:
OPENSSL_clear_free(der, derlen);
OPENSSL_free(der);
ECDSA_SIG_free(s);
return ret;
}
Expand Down
19 changes: 15 additions & 4 deletions qat_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include "qat_utils.h"
#include "qat_evp.h"
#include "qat_parseconf.h"
#include "qat_sys_call.h"
#include "e_qat_err.h"

/* OpenSSL Includes */
Expand Down Expand Up @@ -542,8 +543,15 @@ int qat_engine_init(ENGINE *e)
eng_poll_st[instNum].eng_fd = engine_fd;
eng_poll_st[instNum].inst_index = instNum;

flags = fcntl(engine_fd, F_GETFL, 0);
fcntl(engine_fd, F_SETFL, flags | O_NONBLOCK);
flags = qat_fcntl(engine_fd, F_GETFL, 0);
if (qat_fcntl(engine_fd, F_SETFL, flags | O_NONBLOCK) == -1) {
WARN("Failed to set engine_fd as NON BLOCKING\n");
QATerr(QAT_F_QAT_ENGINE_INIT,
QAT_R_SET_FILE_DESCRIPTOR_NONBLOCKING_FAILURE);
pthread_mutex_unlock(&qat_engine_mutex);
qat_engine_finish(e);
return 0;
}

eng_epoll_events[instNum].data.ptr = &eng_poll_st[instNum];
eng_epoll_events[instNum].events = EPOLLIN | EPOLLET;
Expand Down Expand Up @@ -694,6 +702,7 @@ int qat_engine_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
CpaStatus status = CPA_STATUS_SUCCESS;
int flags = 0;
int fd = 0;
int fcntl_ret = -1;
#endif


Expand Down Expand Up @@ -742,8 +751,10 @@ int qat_engine_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
BREAK_IF(CPA_STATUS_FAIL == status, \
"GET_EXTERNAL_POLLING_FD failed as there was an error retrieving the fd\n");
/* Make the file descriptor non-blocking */
flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
flags = qat_fcntl(fd, F_GETFL, 0);
fcntl_ret = qat_fcntl(fd, F_SETFL, flags | O_NONBLOCK);
BREAK_IF(fcntl_ret == -1, \
"GET_EXTERNAL_POLLING_FD failed as there was an error in setting the fd as NONBLOCKING\n");

DEBUG("External polling FD for instance[%ld] = %d\n", i, fd);
*(int *)p = fd;
Expand Down
6 changes: 6 additions & 0 deletions qat_polling.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include <pthread.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>

/* Local Includes */
#include "qat_polling.h"
Expand Down Expand Up @@ -174,6 +175,11 @@ int qat_adjust_thread_affinity(pthread_t threadptr)
return 1;
}

int qat_fcntl(int fd, int cmd, int arg)
{
return fcntl(fd, cmd, arg);
}

static void qat_poll_heartbeat_timer_expiry(struct timespec *previous_time)
{
struct timespec current_time = { 0 };
Expand Down
2 changes: 2 additions & 0 deletions qat_polling.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ int qat_adjust_thread_affinity(pthread_t threadptr);
******************************************************************************/
void *timer_poll_func(void *ih);

int qat_fcntl(int fd, int cmd, int arg);

# ifndef __FreeBSD__
void *event_poll_func(void *ih);
# endif
Expand Down
7 changes: 1 addition & 6 deletions qat_prf.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ int qat_tls1_prf_init(EVP_PKEY_CTX *ctx)
int (*sw_init_fn_ptr)(EVP_PKEY_CTX *) = NULL;
int ret = 0;

if (ctx == NULL) {
if (unlikely(ctx == NULL)) {
WARN("ctx (type EVP_PKEY_CTX) is NULL \n");
return 0;
}
Expand All @@ -193,11 +193,6 @@ int qat_tls1_prf_init(EVP_PKEY_CTX *ctx)
}
}

if (unlikely(ctx == NULL)) {
WARN("Invalid input param.\n");
return 0;
}

qat_prf_ctx = OPENSSL_zalloc(sizeof(*qat_prf_ctx));
if (qat_prf_ctx == NULL) {
WARN("Cannot allocate qat_prf_ctx\n");
Expand Down

0 comments on commit c125c64

Please sign in to comment.