Commit 37039565 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/408117


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 0f99e7ab
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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");
+0 −7
Original line number Diff line number Diff line
@@ -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);