From a052cb5d3c29133dc988dd6b62ffd258366e5c9e Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 7 Oct 2014 15:07:15 +0300 Subject: [PATCH] hwsim: Radio id was not parsed properly When a new radio is created, the kernel returns the new radio id in the error code. If the error < 0, then that means a real error and other values are used as a radio id. When a radio is destroyed, the error code 0 means a success and other values indicate an error. --- tools/hwsim.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/tools/hwsim.c b/tools/hwsim.c index 32c5c462..f9cf6723 100644 --- a/tools/hwsim.c +++ b/tools/hwsim.c @@ -80,26 +80,26 @@ static void create_callback(struct l_genl_msg *msg, void *user_data) const void *data; uint32_t radio_id = 0; + /* Note that the radio id is returned in the error field of + * the returned message. + */ + if (!l_genl_attr_init(&attr, msg)) { - l_warn("Failed to initialize create return attributes"); + int err = l_genl_msg_get_error(msg); + if (err < 0) { + l_warn("Failed to initialize create return attributes" + " [%d/%s]", -err, strerror(-err)); + goto done; + } + + radio_id = err; + + l_info("Created new radio with id %u", radio_id); + } else { + l_warn("Failed to get create return value"); goto done; } - while (l_genl_attr_next(&attr, &type, &len, &data)) { - switch (type) { - case HWSIM_ATTR_RADIO_ID: - if (len != sizeof(uint32_t)) { - l_warn("Invalid radio id attribute"); - return; - } - - radio_id = *((uint32_t *) data); - break; - } - } - - l_info("Created new radio with id %u", radio_id); - done: l_main_quit(); } @@ -111,14 +111,19 @@ static void destroy_callback(struct l_genl_msg *msg, void *user_data) const void *data; if (!l_genl_attr_init(&attr, msg)) { - l_warn("Failed to initialize destroy return attributes"); - goto done; + int err = l_genl_msg_get_error(msg); + if (err < 0) { + l_warn("Failed to destroy radio [%d/%s]", + -err, strerror(-err)); + goto done; + } + + l_info("Destroyed radio"); } while (l_genl_attr_next(&attr, &type, &len, &data)) { } - l_info("Destroyed radio"); done: l_main_quit();