Skip to content

Commit 98dcf8b

Browse files
marc-hblgirdwood
authored andcommitted
logger: convert.c: move global_config->logs_header to the heap
Finish the job that commit 5b29dae ("logger: Create global convert_config variable to avoid spaghetti code.") started but did not complete, leaving a confusing mix of globals and locals. This confuses some static analyzer complaining that stack values are being returned, see #6858 and #6738. This is a false positive because convert's() stack lifespan is practically the same as a global but let's simplify things anyway. Signed-off-by: Marc Herbert <marc.herbert@intel.com> (cherry picked from commit 2dfaee6) Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 675cb17 commit 98dcf8b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tools/logger/convert.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,55 +1036,58 @@ static int dump_ldc_info(void)
10361036

10371037
int convert(void)
10381038
{
1039-
struct snd_sof_logs_header snd;
1039+
struct snd_sof_logs_header * const logs_hdr = malloc(sizeof(*logs_hdr));
10401040
struct snd_sof_uids_header uids_hdr;
10411041
int count, ret = 0;
10421042

10431043
/* const pointer initialized at build time */
10441044
if (!global_config)
10451045
abort();
10461046

1047+
if (!logs_hdr)
1048+
abort();
1049+
10471050
/* just a shorter alias */
10481051
struct convert_config * const config = global_config;
10491052

1050-
config->logs_header = &snd;
1053+
config->logs_header = logs_hdr;
10511054

1052-
count = fread(&snd, sizeof(snd), 1, config->ldc_fd);
1055+
count = fread(logs_hdr, sizeof(*logs_hdr), 1, config->ldc_fd);
10531056
if (!count) {
10541057
log_err("Error while reading %s.\n", config->ldc_file);
10551058
return -ferror(config->ldc_fd);
10561059
}
10571060

1058-
if (strncmp((char *) snd.sig, SND_SOF_LOGS_SIG, SND_SOF_LOGS_SIG_SIZE)) {
1061+
if (strncmp((char *)logs_hdr->sig, SND_SOF_LOGS_SIG, SND_SOF_LOGS_SIG_SIZE)) {
10591062
log_err("Invalid ldc file signature.\n");
10601063
return -EINVAL;
10611064
}
10621065

10631066
if (global_config->version_fw && /* -n option */
10641067
!global_config->dump_ldc) {
1065-
ret = verify_ldc_checksum(global_config->logs_header->version.src_hash);
1068+
ret = verify_ldc_checksum(logs_hdr->version.src_hash);
10661069
if (ret)
10671070
return ret;
10681071
}
10691072

10701073
/* default logger and ldc_file abi verification */
10711074
if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_DBG_VERSION,
1072-
snd.version.abi_version)) {
1075+
logs_hdr->version.abi_version)) {
10731076
log_err("abi version in %s file does not coincide with abi version used by logger.\n",
10741077
config->ldc_file);
10751078
log_err("logger ABI Version is %d:%d:%d\n",
10761079
SOF_ABI_VERSION_MAJOR(SOF_ABI_DBG_VERSION),
10771080
SOF_ABI_VERSION_MINOR(SOF_ABI_DBG_VERSION),
10781081
SOF_ABI_VERSION_PATCH(SOF_ABI_DBG_VERSION));
10791082
log_err("ldc_file ABI Version is %d:%d:%d\n",
1080-
SOF_ABI_VERSION_MAJOR(snd.version.abi_version),
1081-
SOF_ABI_VERSION_MINOR(snd.version.abi_version),
1082-
SOF_ABI_VERSION_PATCH(snd.version.abi_version));
1083+
SOF_ABI_VERSION_MAJOR(logs_hdr->version.abi_version),
1084+
SOF_ABI_VERSION_MINOR(logs_hdr->version.abi_version),
1085+
SOF_ABI_VERSION_PATCH(logs_hdr->version.abi_version));
10831086
return -EINVAL;
10841087
}
10851088

10861089
/* read uuid section header */
1087-
fseek(config->ldc_fd, snd.data_offset + snd.data_length, SEEK_SET);
1090+
fseek(config->ldc_fd, logs_hdr->data_offset + logs_hdr->data_length, SEEK_SET);
10881091
count = fread(&uids_hdr, sizeof(uids_hdr), 1, config->ldc_fd);
10891092
if (!count) {
10901093
log_err("Error while reading uuids header from %s.\n", config->ldc_file);

0 commit comments

Comments
 (0)