linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arch-powerpc: Return false instead of -EFAULT
@ 2015-09-17  9:18 Peter Senna Tschudin
  2015-09-17  9:47 ` Michael Ellerman
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Senna Tschudin @ 2015-09-17  9:18 UTC (permalink / raw)
  To: benh, paulus, mpe, anton, linuxppc-dev, linux-kernel; +Cc: Peter Senna Tschudin

Returning a negative value for a boolean function seem to have the
undesired effect of returning true. Replace -EINVAL by false in a
bool-returning function.

The diff of the .s file before and after the change (using cross
compilation) starts with:

440,441c440,441
< .L43:
< 	li 3,1	 # D.25775,
---
> .L42:
> 	li 3,0	 # D.25775,
...

while if -EFAULT is replaced by true, the diff is empty.

There is only one call site, and it expects a boolean value:
arch/powerpc/kernel/ftrace.c:129:
        if (!is_module_trampoline(tramp)) {
                pr_err("Not a trampoline\n");
                return -EINVAL;
        }

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

Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
---
 arch/powerpc/kernel/module_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 6838451..a94a5f1 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -160,7 +160,7 @@ bool is_module_trampoline(u32 *p)
 	BUILD_BUG_ON(sizeof(ppc64_stub_insns) != sizeof(ppc64_stub_mask));
 
 	if (probe_kernel_read(insns, p, sizeof(insns)))
-		return -EFAULT;
+		return false;
 
 	for (i = 0; i < ARRAY_SIZE(ppc64_stub_insns); i++) {
 		u32 insna = insns[i];
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] arch-powerpc: Return false instead of -EFAULT
  2015-09-17  9:18 [PATCH] arch-powerpc: Return false instead of -EFAULT Peter Senna Tschudin
@ 2015-09-17  9:47 ` Michael Ellerman
  2015-09-17  9:58   ` Peter Senna Tschudin
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Ellerman @ 2015-09-17  9:47 UTC (permalink / raw)
  To: Peter Senna Tschudin; +Cc: benh, paulus, anton, linuxppc-dev, linux-kernel

On Thu, 2015-09-17 at 11:18 +0200, Peter Senna Tschudin wrote:
> Returning a negative value for a boolean function seem to have the
> undesired effect of returning true. Replace -EINVAL by false in a
> bool-returning function.
> 
> The diff of the .s file before and after the change (using cross
> compilation) starts with:
> 
> 440,441c440,441
> < .L43:
> < 	li 3,1	 # D.25775,
> ---
> > .L42:
> > 	li 3,0	 # D.25775,
> ...
> 
> while if -EFAULT is replaced by true, the diff is empty.

Ah, that's rather unfortunate.

Can you post the full asm listing, for all three cases?

cheers

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arch-powerpc: Return false instead of -EFAULT
  2015-09-17  9:47 ` Michael Ellerman
@ 2015-09-17  9:58   ` Peter Senna Tschudin
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Senna Tschudin @ 2015-09-17  9:58 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: benh, paulus, anton, linuxppc-dev, linux-kernel@vger.kernel.org

On Thu, Sep 17, 2015 at 11:47 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> On Thu, 2015-09-17 at 11:18 +0200, Peter Senna Tschudin wrote:
>> Returning a negative value for a boolean function seem to have the
>> undesired effect of returning true. Replace -EINVAL by false in a
>> bool-returning function.
>>
>> The diff of the .s file before and after the change (using cross
>> compilation) starts with:
>>
>> 440,441c440,441
>> < .L43:
>> <     li 3,1   # D.25775,
>> ---
>> > .L42:
>> >     li 3,0   # D.25775,
>> ...
>>
>> while if -EFAULT is replaced by true, the diff is empty.
>
> Ah, that's rather unfortunate.
>
> Can you post the full asm listing, for all three cases?
Sure, but it would be 3 files of 70kb each. You can download them form:

http://petersenna.com/files/module_64.s.tar.xz

Let me know if this download method doesn't work for you.

module_64.s: Original file.
module_64-patched.s: With my patch
module_64-true.s: Changing -EFAULT by true

files were made with:
$ make arch/powerpc/kernel/module_64.s

using:
gcc-powerpc64-linux-gnu-4.9.2-5.fc21.x86_64

>
> cheers
>
>



-- 
Peter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-17  9:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-17  9:18 [PATCH] arch-powerpc: Return false instead of -EFAULT Peter Senna Tschudin
2015-09-17  9:47 ` Michael Ellerman
2015-09-17  9:58   ` Peter Senna Tschudin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).