From 7ce5dd62f7b7b36eabdbe6618155b67d2005cf34 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Tue, 23 Mar 2021 08:38:26 +0000 Subject: [PATCH] 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 Change-Id: Ia39c5235aa5c62a4ec42285f53f4bc80f7ec370f Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7004 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- examples/nvme/identify/identify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index 94257f742..73e343dbd 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -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);