Skip to content

Commit 4b7c26b

Browse files
haoxian2pcolberg
authored andcommitted
Fixed coverity in acl_hostch.cpp: Dereference before null check (REVERSE_INULL)
Function was accessing pipe->host_pipe_info->m_lock before checking that pipe->host_pipe_info is NULL. If pipe->host_pipe_info is NULL, then it cannot be dereferenced.
1 parent d3e898f commit 4b7c26b

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/acl_hostch.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,14 @@ CL_API_ENTRY cl_int CL_API_CALL clReadPipeIntelFPGA(cl_mem pipe, void *ptr) {
248248
acl_idle_update(pipe->context);
249249
}
250250

251-
acl_mutex_lock(&(pipe->host_pipe_info->m_lock));
252-
253-
// Error checking
254251
if (pipe->host_pipe_info == NULL) {
255-
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
256252
ERR_RET(CL_INVALID_MEM_OBJECT, pipe->context,
257253
"This pipe is not a host pipe");
258254
}
255+
256+
acl_mutex_lock(&(pipe->host_pipe_info->m_lock));
257+
258+
// Error checking
259259
if (!(pipe->flags & CL_MEM_HOST_READ_ONLY)) {
260260
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
261261
ERR_RET(CL_INVALID_MEM_OBJECT, pipe->context,
@@ -349,14 +349,14 @@ CL_API_ENTRY cl_int CL_API_CALL clWritePipeIntelFPGA(cl_mem pipe, void *ptr) {
349349
acl_idle_update(pipe->context);
350350
}
351351

352-
acl_mutex_lock(&(pipe->host_pipe_info->m_lock));
353-
354352
// Error checking
355353
if (pipe->host_pipe_info == NULL) {
356-
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
357354
ERR_RET(CL_INVALID_MEM_OBJECT, pipe->context,
358355
"This pipe is not a host pipe");
359356
}
357+
358+
acl_mutex_lock(&(pipe->host_pipe_info->m_lock));
359+
360360
if (!(pipe->flags & CL_MEM_HOST_WRITE_ONLY)) {
361361
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
362362
ERR_RET(CL_INVALID_MEM_OBJECT, pipe->context,
@@ -465,6 +465,11 @@ CL_API_ENTRY void *CL_API_CALL clMapHostPipeIntelFPGA(cl_mem pipe,
465465
acl_idle_update(pipe->context);
466466
}
467467

468+
if (pipe->host_pipe_info == NULL) {
469+
BAIL_INFO(CL_INVALID_MEM_OBJECT, pipe->context,
470+
"This pipe is not a host pipe");
471+
}
472+
468473
acl_mutex_lock(&(pipe->host_pipe_info->m_lock));
469474

470475
if (errcode_ret) {
@@ -479,12 +484,6 @@ CL_API_ENTRY void *CL_API_CALL clMapHostPipeIntelFPGA(cl_mem pipe,
479484
}
480485
*mapped_size = 0;
481486

482-
if (pipe->host_pipe_info == NULL) {
483-
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
484-
BAIL_INFO(CL_INVALID_MEM_OBJECT, pipe->context,
485-
"This pipe is not a host pipe");
486-
}
487-
488487
if (!pipe->host_pipe_info->m_binded_kernel) {
489488
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
490489
BAIL_INFO(CL_INVALID_KERNEL, pipe->context,
@@ -595,14 +594,14 @@ clUnmapHostPipeIntelFPGA(cl_mem pipe, void *mapped_ptr, size_t size_to_unmap,
595594
acl_idle_update(pipe->context);
596595
}
597596

598-
acl_mutex_lock(&(pipe->host_pipe_info->m_lock));
599-
600-
// Error checking
601597
if (pipe->host_pipe_info == NULL) {
602-
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
603598
ERR_RET(CL_INVALID_MEM_OBJECT, pipe->context,
604599
"This pipe is not a host pipe");
605600
}
601+
602+
acl_mutex_lock(&(pipe->host_pipe_info->m_lock));
603+
604+
// Error checking
606605
if (!pipe->host_pipe_info->m_binded_kernel) {
607606
acl_mutex_unlock(&(pipe->host_pipe_info->m_lock));
608607
ERR_RET(CL_INVALID_KERNEL, pipe->context,

0 commit comments

Comments
 (0)