Skip to content

More cosmetic fixes and clean up - #1025

Merged
lgirdwood merged 12 commits into
thesofproject:masterfrom
lyakh:kw-fix
Mar 14, 2019
Merged

More cosmetic fixes and clean up#1025
lgirdwood merged 12 commits into
thesofproject:masterfrom
lyakh:kw-fix

Conversation

@lyakh

@lyakh lyakh commented Feb 20, 2019

Copy link
Copy Markdown
Collaborator

A couple of cosmetic fixes and improvements. They don't have anything to do with KW any more, since the only patch, that was dealing with a KW complaint, was fixing a false positive - thanks to all for pointing out! So, all what's left is just clean up and cosmetic stuff.

Comment thread src/arch/xtensa/task.c Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one is trickier here, because depending on the CONFIG_TASK_HAVE_PRIORITY_XXX you can end up with memory leaks.

But looking at the code it looks that it doesn't really matter if those allocation failed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it was already mentioned somewhere, that it looks like KW problem, because fail to alloc from system heap always ends in panic.

Comment thread src/arch/xtensa/smp/idc.c Outdated
Comment thread src/arch/xtensa/smp/idc.c Outdated

@mmaka1 mmaka1 Feb 20, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

rmalloc_sys() panics if there is no free memory to allocate which practically makes the if(null) a dead code in every place that follows an allocation from RZONE_SYS, and what is more, it suggests the reader that the allocation may really fail at run-time being handled by the callers. If not sure why KW is unable to analyze that path and follow switch (zone & RZONE_TYPE_MASK) correctly.

I am also not sure why the _malloc() just traces error in the switch() default branch and returns NULL ptr since it seems to be a serious logic error, not a run-time problem to be handled in some way. This branch seems to confuse KW. I'd try another approach: panic in the default branch in _malloc() and mark this infinite loop as 'by design' piece to neutralize KW.

@lyakh lyakh changed the title KW and related fixes More cosmetic fixes and clean up Feb 21, 2019
@lyakh

lyakh commented Feb 21, 2019

Copy link
Copy Markdown
Collaborator Author

@mmaka1 @tlauda thanks for the clarifications! I've dropped that commit.

@lgirdwood

Copy link
Copy Markdown
Member

@lyakh looks like CI builds have failed.

@mmaka1

mmaka1 commented Feb 25, 2019

Copy link
Copy Markdown

@lyakh Could you plase rebase with master, KW should be OK now wrt sys heap allocations.

lyakh added 4 commits March 13, 2019 12:43
Add a missing preamble in a recently created idc.c

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Interrupt registration can fail, check its return code in idc.c
and propagate error to the caller.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
The SMP version of init.c calls panic(), therefore it needs panic.h,
OTOH the UP version doesn't call panic(), so the header isn't needed
there.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
When returning an error, it's usually better to propagate the error
code, that caused the termination, than overriding it.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
@lyakh

lyakh commented Mar 13, 2019

Copy link
Copy Markdown
Collaborator Author

I rebased and extended this series, also moved here cosmetic patches from my interrupt extension PR #1053

lyakh added 6 commits March 13, 2019 14:37
All trace_event() style macros resolve to _log_message() or
__log_message() eventually. This message makes those macros usable
as a function, e.g. within "if () else" clauses with or without
curly braces.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Using macro arguments multiple times within the macro definition body
can lead to repeated expressioon evaluation. To avoid that replace
MIN() and MAX() macros with safer versions.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Function-type macros are usually called as "M(...);" with a semicolon
in the end. Therefore defining such macros with a semicolon isn't a
good practice. This breaks constructs like
if (...)
	M(...);
else
	...;
Fix the dma_set_drvdata() macro to avoid such problems.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Some editors (e.g. emacs) do not take into account preprocessor
conditionals when performing syntax highlighting. I.e. patterns like

	if (a) {
	if (b) {
		do_things();
	}

cause those editors to miscalculate the number of opening and closing
braces and thus break code highlighting. Move the opening brace to
after the preprocessor conditional to avoid that.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Rearrange a conditional to reduce the number of branches and
eliminate a goto.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
As long as the low bits of two numbers are 0, there's no need to
right shift those numbers to compare them.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
lyakh added 2 commits March 13, 2019 14:38
Use a "for" loop instead of simulating it, using a "while" loop. Also
avoid needlessly setting a variable inside that loop, where it can
just be set once after the loop termination.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
"Formate" and "format" are two different words, in this case it's
"format" that is meant.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
j = 0;
/* Loop until NULL */
while (fir_list[j]) {
for (j = 0; fir_list[j]; j++) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suppose this works but what is the improvement?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I find

for (i = 0; i < N; i++)

better than

i = 0;
while (i < N) {
...
i++;
}

trace_dmic("dmic_set_config(), cfg mfir_a = %u, mfir_b = %u",
cfg.mfir_a, cfg.mfir_b);
trace_dmic("dmic_set_config(), cfg cic_shift = %u", cfg.cic_shift)
trace_dmic("dmic_set_config(), cfg cic_shift = %u", cfg.cic_shift);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No wonder indenting in editor has behaved strange. Thanks!


#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) ({ \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm curious, why is this better?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

if you have MIN(x++, y), then with the first version you'd get

(x++ > y) ? x++ : y;

i.e. you'd have x incremented twice. With the second version you'd correctly have it incremented once. Same for any MIN(f(x), y) - f(x) would be called twice with the first version.

@lgirdwood
lgirdwood merged commit 01f1a4a into thesofproject:master Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants