From: Simon Marchi Date: Sat, 5 Oct 2019 05:01:34 +0000 (-0400) Subject: flt.lttng-utils.debug-info: tidy up component initialization X-Git-Tag: v2.0.0-rc1~35 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=629d19044c43b195498d0a4e002906c54b6186d5 flt.lttng-utils.debug-info: tidy up component initialization Assign add_port_status to status directly, as has been the accepted pattern in the rest of the project for a while. This is less verbose than using a switch-case. Make init_from_params return a bt_component_class_initialize_method_status, since it's only used in the context of component initialization. The alert reader will notice that this function can't fail, making it pointless to have it return a status. However, it will be able to fail in the next patch, so I chose to leave a non-void return type. Change-Id: I41c1f6dc9dea5cbda4ef33f336d4b2cff216a568 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2141 Tested-by: jenkins --- diff --git a/src/plugins/lttng-utils/debug-info/debug-info.c b/src/plugins/lttng-utils/debug-info/debug-info.c index 2eebc19b..426f50c6 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.c +++ b/src/plugins/lttng-utils/debug-info/debug-info.c @@ -1684,11 +1684,12 @@ const bt_message *handle_message(struct debug_info_msg_iter *debug_it, } static -int init_from_params(struct debug_info_component *debug_info_component, +bt_component_class_initialize_method_status init_from_params( + struct debug_info_component *debug_info_component, const bt_value *params) { - const bt_value *value = NULL; - int ret = 0; + const bt_value *value; + bt_component_class_initialize_method_status status; BT_ASSERT(params); @@ -1726,7 +1727,9 @@ int init_from_params(struct debug_info_component *debug_info_component, debug_info_component->arg_full_path = BT_FALSE; } - return ret; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; + + return status; } BT_HIDDEN @@ -1735,7 +1738,6 @@ bt_component_class_initialize_method_status debug_info_comp_init( bt_self_component_filter_configuration *config, const bt_value *params, __attribute__((unused)) void *init_method_data) { - int ret; struct debug_info_component *debug_info_comp; bt_component_class_initialize_method_status status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; @@ -1745,7 +1747,6 @@ bt_component_class_initialize_method_status debug_info_comp_init( bt_logging_level log_level = bt_component_get_logging_level( bt_self_component_as_component(self_comp)); - BT_COMP_LOGI("Initializing debug_info component: " "comp-addr=%p, params-addr=%p", self_comp, params); @@ -1761,32 +1762,20 @@ bt_component_class_initialize_method_status debug_info_comp_init( add_port_status = bt_self_component_filter_add_input_port( self_comp_flt, "in", NULL, NULL); - switch (add_port_status) { - case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR: - status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; - goto error; - case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR: - status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; + if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) { + status = (int) add_port_status; goto error; - default: - break; } add_port_status = bt_self_component_filter_add_output_port( - self_comp_flt, "out", NULL, NULL); - switch (add_port_status) { - case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR: - status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; - goto error; - case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR: - status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; + self_comp_flt, "out", NULL, NULL); + if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) { + status = (int) add_port_status; goto error; - default: - break; } - ret = init_from_params(debug_info_comp, params); - if (ret) { + status = init_from_params(debug_info_comp, params); + if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { BT_COMP_LOGE("Cannot configure debug_info component: " "debug_info-comp-addr=%p, params-addr=%p", debug_info_comp, params);