Spdk/module/bdev/nvme
Nick Connolly e7c019874c module/bdev/nvme: improve portability
In nvme_bdev_ctrlr_create, calloc will be called with a zero size
allocation request if the number of namespaces is zero. The behaviour
is implementation defined if the size of the space requested is zero -
calloc will either return a pointer that mustn't be dereferenced, or
NULL. If NULL is returned, the nvme_bdev_ctrlr_create will fail.

Only call calloc if there are a non-zero number of namespaces.
Otherwise, leave the namespaces pointer with a NULL value. All
references to namespaces[] are either known to be safe, or occur
in the context of looping through the namespaces which will be
skipped if the count is zero. The exception to this is in
vbdev_opal_create, where an assert has been added to match
equivalent code in bdev_ocssd_create_bdev.

Tested by running unit tests on a system that returns a null pointer
for a zero size allocation.

Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
Change-Id: I058b0683fd9b3a20bf90e54db93ca48b9bb4e40e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6551
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: sunshihao <sunshihao@huawei.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
2021-02-25 10:25:20 +00:00
..
bdev_nvme_cuse_rpc.c lib/jsonrpc: Add a new API to send response for writing bool result. 2020-11-16 15:08:47 +00:00
bdev_nvme_rpc.c bdev/nvme/rpc: Add params to enable TCP hdgst and ddgst 2021-02-09 11:26:51 +00:00
bdev_nvme.c module/bdev/nvme: improve portability 2021-02-25 10:25:20 +00:00
bdev_nvme.h bdev/nvme/rpc: Add params to enable TCP hdgst and ddgst 2021-02-09 11:26:51 +00:00
bdev_ocssd_rpc.c bdev/ocssd: Remove range parameter from bdev_ocssd_create RPC 2021-02-19 11:28:53 +00:00
bdev_ocssd.c bdev/nvme: Get nvme_bdev from standard ns via helper function for configuration 2021-02-24 13:01:44 +00:00
bdev_ocssd.h bdev/ocssd: Remove range from struct ocssd_bdev 2021-02-24 13:01:44 +00:00
common.c bdev/nvme: Inline detach_bdev_from_ns() and attach_bdev_to_ns() 2021-01-05 09:43:09 +00:00
common.h bdev/nvme: Get nvme_bdev from standard ns via helper function for configuration 2021-02-24 13:01:44 +00:00
Makefile so_ver: increase all major versions 2021-02-05 14:43:47 +00:00
nvme_rpc.c module/nvme: Fix warning about scanbuild. 2020-10-27 08:42:32 +00:00
vbdev_opal_rpc.c lib/jsonrpc: Add a new API to send response for writing bool result. 2020-11-16 15:08:47 +00:00
vbdev_opal.c module/bdev/nvme: improve portability 2021-02-25 10:25:20 +00:00
vbdev_opal.h module/bdev_nvme: remove spdk prefix from static/internal functions. 2020-05-15 07:58:03 +00:00