bdev/crypto: silence scan-build null dereference false positive

Scan build is really pessimistic and assumes that
mempool functions can dequeue NULL buffers even if they
return success. This is obviously a false possitive, but
the mempool dequeue is done in a DPDK inline function
that we can't decorate with usual assert(buf != NULL).
Instead, under #ifdef __clang_analyzer__ we'll now
preinitialize the dequeued buffer array with some dummy
objects.

Change-Id: I070cfbfd39b6a66d25cd5f9a7c0dfbfadc4cb92a
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463232
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-07-25 20:11:03 +02:00 committed by Ben Walker
parent 0b068f8530
commit 9554bd7326
2 changed files with 21 additions and 3 deletions

View File

@ -120,6 +120,23 @@ spdk_divide_round_up(uint64_t num, uint64_t divisor)
return (num + divisor - 1) / divisor;
}
/**
* Scan build is really pessimistic and assumes that mempool functions can
* dequeue NULL buffers even if they return success. This is obviously a false
* possitive, but the mempool dequeue can be done in a DPDK inline function that
* we can't decorate with usual assert(buf != NULL). Instead, we'll
* preinitialize the dequeued buffer array with some dummy objects.
*/
#define SPDK_CLANG_ANALYZER_PREINIT_PTR_ARRAY(arr, arr_size, buf_size) \
do { \
static char dummy_buf[buf_size]; \
int i; \
for (i = 0; i < arr_size; i++) { \
arr[i] = (void *)dummy_buf; \
} \
} while (0)
#ifdef __cplusplus
}
#endif

View File

@ -630,10 +630,11 @@ _crypto_operation(struct spdk_bdev_io *bdev_io, enum rte_crypto_cipher_operation
}
}
/* Allocate crypto operations. */
#ifdef DEBUG
memset(crypto_ops, 0, sizeof(crypto_ops));
#ifdef __clang_analyzer__
/* silence scan-build false positive */
SPDK_CLANG_ANALYZER_PREINIT_PTR_ARRAY(crypto_ops, MAX_ENQUEUE_ARRAY_SIZE, 0x1000);
#endif
/* Allocate crypto operations. */
allocated = rte_crypto_op_bulk_alloc(g_crypto_op_mp,
RTE_CRYPTO_OP_TYPE_SYMMETRIC,
crypto_ops, cryop_cnt);