From b890bd21cd03556d7c7c4b47f1ade5415e62f5b0 Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Tue, 11 Apr 2023 13:01:57 +0200 Subject: [PATCH] nvme_transport: return NULL if transport does not exist spdk_nvme_ctrlr_get_registers() calls nvme_get_transport() to get a reference for a transport, whose registers should be returned, but nvme_get_transport() explicitly returns NULL, if the transport does not exist. This would result in dereferencing a NULL pointer on line 862. To remedy that, if no transport was found, return NULL. Additionally change "THis" to "This" on line 46. Change-Id: I3944925659991e9424e2177b5c940b2e2626d1f4 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17532 Reviewed-by: Konrad Sztyber Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/nvme/nvme_transport.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/nvme/nvme_transport.c b/lib/nvme/nvme_transport.c index 142e52ee0..5550b6110 100644 --- a/lib/nvme/nvme_transport.c +++ b/lib/nvme/nvme_transport.c @@ -43,7 +43,7 @@ nvme_get_next_transport(const struct spdk_nvme_transport *transport) /* * Unfortunately, due to NVMe PCIe multiprocess support, we cannot store the - * transport object in either the controller struct or the admin qpair. THis means + * transport object in either the controller struct or the admin qpair. This means * that a lot of admin related transport calls will have to call nvme_get_transport * in order to know which functions to call. * In the I/O path, we have the ability to store the transport struct in the I/O @@ -859,6 +859,11 @@ spdk_nvme_ctrlr_get_registers(struct spdk_nvme_ctrlr *ctrlr) { const struct spdk_nvme_transport *transport = nvme_get_transport(ctrlr->trid.trstring); + if (transport == NULL) { + /* Transport does not exist. */ + return NULL; + } + if (transport->ops.ctrlr_get_registers) { return transport->ops.ctrlr_get_registers(ctrlr); }