Skip to content

Commit

Permalink
ddci_init(): submaster_initializer not called if implicit initialization
Browse files Browse the repository at this point in the history
ddci_init() can be called "explicitly" or "implicitly".  An explicit
call is when it is called either from ddca_init() or ddca_init2().
If an API function dependent on initialization is called before
explicit initialization, ddci_init() is called with arguments such
that it can never fail.  This is an implicit call.  In particular,
it is called with option DDCA_INIT_OPTIONS_DISABLE_CONFIG_FILE and
a null libopts string.  Otherwise failure would be possible.

The bug was that some initialization did not occur with this
combination of ddci_init() args.  In particular,
submaster_initializer(), which among other things sets the value of
sys_drm_connectors, was not called.  Also any options in the
ddcutilrc configuration file that turned on tracing were not
processed, making debugging more difficult.

PowerDevil calls API functions requiring initialization before calling
ddca_init(). As a result, there's an implicit call to ddci_init(),
and because of the bug sys_drm_connectors is not set, resulting
in the "assert(sys_drm_connectors)" failure in function i2c_check_bus().
  • Loading branch information
rockowitz committed Jan 20, 2024
1 parent 96f7e66 commit 7f157f6
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/libmain/api_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,20 +660,19 @@ ddci_init(const char * libopts,
*infomsg_loc = g_ptr_array_to_ntsa(infomsgs, /*duplicate=*/true);
}
g_ptr_array_free(infomsgs, true);

if (!master_error) {
if (parsed_cmd->trace_destination) {
DBGF(debug, "Setting library trace file: %s", parsed_cmd->trace_destination);
init_library_trace_file(parsed_cmd->trace_destination, enable_syslog, debug);
}
master_error = init_tracing(parsed_cmd);
requested_stats = parsed_cmd->stats_types;
ptd_api_profiling_enabled = parsed_cmd->flags & CMD_FLAG_PROFILE_API;
per_display_stats = parsed_cmd->flags & CMD_FLAG_VERBOSE_STATS;
dsa_detail_stats = parsed_cmd->flags & CMD_FLAG_INTERNAL_STATS;
if (!submaster_initializer(parsed_cmd))
master_error = ERRINFO_NEW(DDCRC_UNINITIALIZED, "Initialization failed");
}
if (!master_error) {
if (parsed_cmd->trace_destination) {
DBGF(debug, "Setting library trace file: %s", parsed_cmd->trace_destination);
init_library_trace_file(parsed_cmd->trace_destination, enable_syslog, debug);
}
master_error = init_tracing(parsed_cmd);
requested_stats = parsed_cmd->stats_types;
ptd_api_profiling_enabled = parsed_cmd->flags & CMD_FLAG_PROFILE_API;
per_display_stats = parsed_cmd->flags & CMD_FLAG_VERBOSE_STATS;
dsa_detail_stats = parsed_cmd->flags & CMD_FLAG_INTERNAL_STATS;
if (!submaster_initializer(parsed_cmd))
master_error = ERRINFO_NEW(DDCRC_UNINITIALIZED, "Initialization failed");
}
}

Expand Down

0 comments on commit 7f157f6

Please sign in to comment.