mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Senna Tschudin <peter.senna@gmail.com>
To: shuahkh@osg.samsung.com, mpe@ellerman.id.au,
	sam.bobroff@au1.ibm.com, linux-api@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Peter Senna Tschudin <peter.senna@gmail.com>
Subject: [PATCH] tools-powerpc: Return false instead of -1
Date: Thu, 17 Sep 2015 13:03:21 +0200	[thread overview]
Message-ID: <1442487801-22661-1-git-send-email-peter.senna@gmail.com> (raw)

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 convert rc to bool, replace -1
by false, and 0 by true.

This issue was found by the following Coccinelle semantic patch:
<smpl>
@@
identifier f, ret;
constant C;
typedef bool;
@@
bool f (...){
<+...
ret = -C;
...
* return ret;
...+>
}
</smpl>

Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
---
I could not compile this specific file, but I did some testing on toy examples:

t.c:
_Bool main(void)
{
        return -1;
}

$ powerpc64-linux-gnu-gcc -O2 -S -fomit-frame-pointer t.c

t.s:
...
.L.main:
        li 3,1
        blr

However if the function type is int instead of bool, it behaves as
expected:

t2.c:
int main(void)
{
        return -1;
}

$ powerpc64-linux-gnu-gcc -O2 -S -fomit-frame-pointer t2.c

t2.s:
...
.L.main:
        li 3,-1
        blr

So another solution would be to change the function type to int.

 tools/testing/selftests/powerpc/pmu/lib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/powerpc/pmu/lib.c b/tools/testing/selftests/powerpc/pmu/lib.c
index a07104c..2f17110 100644
--- a/tools/testing/selftests/powerpc/pmu/lib.c
+++ b/tools/testing/selftests/powerpc/pmu/lib.c
@@ -219,9 +219,9 @@ bool require_paranoia_below(int level)
 	unsigned long current;
 	char *end, buf[16];
 	FILE *f;
-	int rc;
+	bool rc;
 
-	rc = -1;
+	rc = false;
 
 	f = fopen(PARANOID_PATH, "r");
 	if (!f) {
@@ -244,7 +244,7 @@ bool require_paranoia_below(int level)
 	if (current >= level)
 		goto out;
 
-	rc = 0;
+	rc = true;
 out_close:
 	fclose(f);
 out:
-- 
2.1.0


             reply	other threads:[~2015-09-17 11:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-17 11:03 Peter Senna Tschudin [this message]
2016-09-02  9:54 ` Andrew Shadura

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442487801-22661-1-git-send-email-peter.senna@gmail.com \
    --to=peter.senna@gmail.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=sam.bobroff@au1.ibm.com \
    --cc=shuahkh@osg.samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®