Skip to content

Commit

Permalink
selftests/powerpc: Return false instead of -1 in require_paranoia_bel…
Browse files Browse the repository at this point in the history
…ow()

Returning a negative value for a boolean function seem to have the
undesired effect of returning true. require_paranoia_below() is a
boolean function, but the variable used to store the return value is an
integer, receiving -1 or 0. This patch converts rc to bool, replaces -1
by false, and 0 by true.

mpe: This wasn't exhibiting in practice because the common case, where
we do the comparison of the desired level vs the current value, was
being compiled into a computation based on the result of the comparison,
ie. it wasn't using the default -1 value at all. However that was just
luck and the code is still wrong.

Signed-off-by: Peter Senna Tschudin <[email protected]>
Signed-off-by: Andrew Shadura <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
petersenna authored and mpe committed Nov 14, 2016
1 parent 99e5cde commit 0e27d27
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tools/testing/selftests/powerpc/pmu/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ bool require_paranoia_below(int level)
long current;
char *end, buf[16];
FILE *f;
int rc;
bool rc;

rc = -1;
rc = false;

f = fopen(PARANOID_PATH, "r");
if (!f) {
Expand All @@ -218,7 +218,7 @@ bool require_paranoia_below(int level)
if (current >= level)
goto out_close;

rc = 0;
rc = true;
out_close:
fclose(f);
out:
Expand Down

0 comments on commit 0e27d27

Please sign in to comment.