Skip to content

Conversation

@marc-hb
Copy link
Collaborator

@marc-hb marc-hb commented Dec 20, 2022

Finish the job that commit 5b29dae ("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

Finish the job that commit 5b29dae ("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 thesofproject#6858 and thesofproject#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>
@marc-hb
Copy link
Collaborator Author

marc-hb commented Dec 20, 2022

Intel CI does not test sof-logger anymore but I have of course tested this locally.

@marc-hb marc-hb marked this pull request as ready for review December 20, 2022 22:46
@marc-hb marc-hb added P1 Blocker bugs or important features and removed P1 Blocker bugs or important features labels Dec 20, 2022
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 thesofproject#6858 and thesofproject#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>
@marc-hb marc-hb added the P1 Blocker bugs or important features label Dec 20, 2022
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the original move to use more global data is a good way to refactor code like this, but agreed, better to use real global object if the design is such.

Copy link
Contributor

@jsarha jsarha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think going from a pointer passed to each function to global variable is an improvement, but that approach was taken before this PR. One nitpick about calling malloc() without symmetric free() call.

int convert(void)
{
struct snd_sof_logs_header snd;
struct snd_sof_logs_header * const logs_hdr = malloc(sizeof(*logs_hdr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a symmetric free()-call if something is malloced, or use a global if one does not bother to do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logs_hdr is immutable, the tool will never read multiple logs without being restarted (even less so now that even more things are global). So there's no reason to ever free it.

I considered making it static / moving it to the BSS but it seemed to require more changes. Maybe I should have done that.

@lgirdwood lgirdwood merged commit 2dfaee6 into thesofproject:main Dec 21, 2022
@marc-hb marc-hb deleted the logger-global-config branch December 21, 2022 17:03
@marc-hb
Copy link
Collaborator Author

marc-hb commented Dec 21, 2022

Not sure the original move to use more global data is a good way to refactor code like this

I do not think going from a pointer passed to each function to global variable is an improvement,

For the record I don't think 5b29dae was a good idea either but going back would require changing many more lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Blocker bugs or important features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants