Skip to content

Commit cbf8b5a

Browse files
aeglIngo Molnar
authored andcommitted
x86/mm, x86/mce: Fix return type/value for memcpy_mcsafe()
Returning a 'bool' was very unpopular. Doubly so because the code was just wrong (returning zero for true, one for false; great for shell programming, not so good for C). Change return type to "int". Keep zero as the success indicator because it matches other similar code and people may be more comfortable writing: if (memcpy_mcsafe(to, from, count)) { printk("Sad panda, copy failed\n"); ... } Make the failure return value -EFAULT for now. Reported by: Mika Penttilä <mika.penttila@nextfour.com> Signed-off-by: Tony Luck <tony.luck@intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: mika.penttila@nextfour.com Fixes: 92b0729 ("x86/mm, x86/mce: Add memcpy_mcsafe()") Link: http://lkml.kernel.org/r/695f14233fa7a54fcac4406c706d7fec228e3f4c.1457993040.git.tony.luck@intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ba4e06d commit cbf8b5a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

arch/x86/include/asm/string_64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ int strcmp(const char *cs, const char *ct);
8787
*
8888
* Low level memory copy function that catches machine checks
8989
*
90-
* Return true for success, false for fail
90+
* Return 0 for success, -EFAULT for fail
9191
*/
92-
bool memcpy_mcsafe(void *dst, const void *src, size_t cnt);
92+
int memcpy_mcsafe(void *dst, const void *src, size_t cnt);
9393

9494
#endif /* __KERNEL__ */
9595

arch/x86/lib/memcpy_64.S

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Copyright 2002 Andi Kleen */
22

33
#include <linux/linkage.h>
4+
#include <asm/errno.h>
45
#include <asm/cpufeatures.h>
56
#include <asm/alternative-asm.h>
67

@@ -268,16 +269,16 @@ ENTRY(memcpy_mcsafe)
268269
decl %ecx
269270
jnz .L_copy_trailing_bytes
270271

271-
/* Copy successful. Return true */
272+
/* Copy successful. Return zero */
272273
.L_done_memcpy_trap:
273274
xorq %rax, %rax
274275
ret
275276
ENDPROC(memcpy_mcsafe)
276277

277278
.section .fixup, "ax"
278-
/* Return false for any failure */
279+
/* Return -EFAULT for any failure */
279280
.L_memcpy_mcsafe_fail:
280-
mov $1, %rax
281+
mov $-EFAULT, %rax
281282
ret
282283

283284
.previous

0 commit comments

Comments
 (0)