mirror of https://github.com/thesofproject/sof.git
logger: make "global_config" truly global
Finish the job that commit 5b29dae9c8
("logger: Create global
convert_config variable to avoid spaghetti code.") started but did not
finish, leaving behind a supposedly "global" variable that is actually a
confusing global pointer to a struct local to the main() function.
This confuses some static analyzer complaining that stack values are
being returned, see #6858 and #6738. This is a false positive
because the main()'s stack lifespan is the same as a global but let's
simplify things anyway.
Also stop using 'extern' in .c files, use a proper .h file instead.
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
parent
80adcdf36a
commit
327a26bf8a
|
@ -65,9 +65,6 @@ static const char *BAD_PTR_STR = "<bad uid ptr 0x%.8x>";
|
|||
#define UUID_LOWER "%s%s%s<%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x>%s%s%s"
|
||||
#define UUID_UPPER "%s%s%s<%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X>%s%s%s"
|
||||
|
||||
/* pointer to config for global context */
|
||||
struct convert_config *global_config;
|
||||
|
||||
static int read_entry_from_ldc_file(struct ldc_entry *entry, uint32_t log_entry_address);
|
||||
|
||||
char *format_uid_raw(const struct sof_uuid_entry *uid_entry, int use_colors, int name_first,
|
||||
|
@ -1037,14 +1034,20 @@ static int dump_ldc_info(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int convert(struct convert_config *config)
|
||||
int convert(void)
|
||||
{
|
||||
struct snd_sof_logs_header snd;
|
||||
struct snd_sof_uids_header uids_hdr;
|
||||
int count, ret = 0;
|
||||
|
||||
/* const pointer initialized at build time */
|
||||
if (!global_config)
|
||||
abort();
|
||||
|
||||
/* just a shorter alias */
|
||||
struct convert_config * const config = global_config;
|
||||
|
||||
config->logs_header = &snd;
|
||||
global_config = config;
|
||||
|
||||
count = fread(&snd, sizeof(snd), 1, config->ldc_fd);
|
||||
if (!count) {
|
||||
|
|
|
@ -47,4 +47,8 @@ struct convert_config {
|
|||
};
|
||||
|
||||
uint32_t get_uuid_key(const struct sof_uuid_entry *entry);
|
||||
int convert(struct convert_config *config);
|
||||
|
||||
/* pointer to config for global context */
|
||||
extern struct convert_config * const global_config;
|
||||
|
||||
int convert(void);
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#define COMPONENTS_SEPARATOR ','
|
||||
#define COMPONENT_NAME_SCAN_STRING_LENGTH 32
|
||||
|
||||
extern struct convert_config *global_config;
|
||||
|
||||
/** map between log level given by user and enum value */
|
||||
static const struct {
|
||||
const char name[16];
|
||||
|
|
|
@ -282,6 +282,8 @@ cleanup:
|
|||
}
|
||||
#endif // HAS_INOTIFY
|
||||
|
||||
static struct convert_config _global_config;
|
||||
struct convert_config * const global_config = &_global_config;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -498,7 +500,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
ret = -convert(&config);
|
||||
_global_config = config;
|
||||
ret = -convert();
|
||||
|
||||
out:
|
||||
/* free memory */
|
||||
|
|
|
@ -41,8 +41,6 @@ char *log_asprintf(const char *format, ...)
|
|||
return result;
|
||||
}
|
||||
|
||||
extern struct convert_config *global_config;
|
||||
|
||||
/** Prints 1. once to stderr. 2. a second time to the global out_fd if
|
||||
* out_fd is neither stderr nor stdout (because the -o option was used).
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue