From 37039565d0ad9c18fad358d10e998aae8b1ce391 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 17 Apr 2018 16:46:16 -0700 Subject: [PATCH] io_channel: add asserts in spdk_io_device_register spdk_io_device_register() doesn't have a return value, but we can at least catch trivial mistakes like neglecting to pass a valid io_device or create/delete callback in debug builds. One invalid unit test case that passed NULL for all parameters is removed, since there's no way to make that work without adding a return value instead of asserts. Change-Id: I3dd4c850bdb14957d2dc03209ea9ea44bbe4e616 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/408117 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker --- lib/util/io_channel.c | 4 ++++ test/unit/lib/util/io_channel.c/io_channel_ut.c | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/util/io_channel.c b/lib/util/io_channel.c index 6898d67e3..97681c560 100644 --- a/lib/util/io_channel.c +++ b/lib/util/io_channel.c @@ -303,6 +303,10 @@ spdk_io_device_register(void *io_device, spdk_io_channel_create_cb create_cb, { struct io_device *dev, *tmp; + assert(io_device != NULL); + assert(create_cb != NULL); + assert(destroy_cb != NULL); + dev = calloc(1, sizeof(struct io_device)); if (dev == NULL) { SPDK_ERRLOG("could not allocate io_device\n"); diff --git a/test/unit/lib/util/io_channel.c/io_channel_ut.c b/test/unit/lib/util/io_channel.c/io_channel_ut.c index efda52d8f..0febd151d 100644 --- a/test/unit/lib/util/io_channel.c/io_channel_ut.c +++ b/test/unit/lib/util/io_channel.c/io_channel_ut.c @@ -353,12 +353,6 @@ destroy_cb_2(void *io_device, void *ctx_buf) g_destroy_cb_calls++; } -static int -create_cb_null(void *io_device, void *ctx_buf) -{ - return -1; -} - static void channel(void) { @@ -368,7 +362,6 @@ channel(void) spdk_allocate_thread(_send_msg, NULL, NULL, NULL, "thread0"); spdk_io_device_register(&device1, create_cb_1, destroy_cb_1, sizeof(ctx1)); spdk_io_device_register(&device2, create_cb_2, destroy_cb_2, sizeof(ctx2)); - spdk_io_device_register(&device3, create_cb_null, NULL, 0); g_create_cb_calls = 0; ch1 = spdk_get_io_channel(&device1);