nvme/identify: use calloc to allocate zone report buffer

When support for printing the zone report was added,
the zone report buffer was allocated using calloc().

This was intentionally changed to a malloc in commit
5ef79a17ecab ("examples/nvme/identify: add an option to dump
the full zns zone report").

While we shouldn't need to zero the buffer, since the drive
should write  the "Number of Zones" field in zone report header,
and we should never read zone descriptors beyond this value,
the ZNS spec also states that reading beyond the last zone
descriptor has undefined results.

Considering that "Number of Zones" field in the zone report
header will only represent the number of zone descriptors
in the buffer when the partial bit was set to true,
always use calloc(), to avoid the chance that someone might
copy this code and call spdk_nvme_zns_report_zones() with the
partial bit set to false.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Change-Id: Ia39c5235aa5c62a4ec42285f53f4bc80f7ec370f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7004
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Niklas Cassel 2021-03-23 08:38:26 +00:00 committed by Tomasz Zawadzki
parent f6bbec8ba9
commit 7ce5dd62f7

View File

@ -811,7 +811,7 @@ get_and_print_zns_zone_report(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *q
outstanding_commands = 0;
report_bufsize = spdk_nvme_ns_get_max_io_xfer_size(ns);
report_buf = malloc(report_bufsize);
report_buf = calloc(1, report_bufsize);
if (!report_buf) {
printf("Zone report allocation failed!\n");
exit(1);