Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 117780ee authored by H. Peter Anvin's avatar H. Peter Anvin Committed by H. Peter Anvin
Browse files

x86, asm: use bool for bitops and other assembly outputs



The gcc people have confirmed that using "bool" when combined with
inline assembly always is treated as a byte-sized operand that can be
assumed to be 0 or 1, which is exactly what the SET instruction
emits.  Change the output types and intermediate variables of as many
operations as practical to "bool".

Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
Link: http://lkml.kernel.org/r/1465414726-197858-3-git-send-email-hpa@linux.intel.com


Reviewed-by: default avatarAndy Lutomirski <luto@kernel.org>
Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
parent 2823d4da
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -16,14 +16,16 @@
#define BOOT_BITOPS_H
#define _LINUX_BITOPS_H		/* Inhibit inclusion of <linux/bitops.h> */

static inline int constant_test_bit(int nr, const void *addr)
#include <linux/types.h>

static inline bool constant_test_bit(int nr, const void *addr)
{
	const u32 *p = (const u32 *)addr;
	return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
}
static inline int variable_test_bit(int nr, const void *addr)
static inline bool variable_test_bit(int nr, const void *addr)
{
	u8 v;
	bool v;
	const u32 *p = (const u32 *)addr;

	asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
+4 −4
Original line number Diff line number Diff line
@@ -176,16 +176,16 @@ static inline void wrgs32(u32 v, addr_t addr)
}

/* Note: these only return true/false, not a signed return value! */
static inline int memcmp_fs(const void *s1, addr_t s2, size_t len)
static inline bool memcmp_fs(const void *s1, addr_t s2, size_t len)
{
	u8 diff;
	bool diff;
	asm volatile("fs; repe; cmpsb; setnz %0"
		     : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
	return diff;
}
static inline int memcmp_gs(const void *s1, addr_t s2, size_t len)
static inline bool memcmp_gs(const void *s1, addr_t s2, size_t len)
{
	u8 diff;
	bool diff;
	asm volatile("gs; repe; cmpsb; setnz %0"
		     : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
	return diff;
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@

int memcmp(const void *s1, const void *s2, size_t len)
{
	u8 diff;
	bool diff;
	asm("repe; cmpsb; setnz %0"
	    : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
	return diff;
+3 −3
Original line number Diff line number Diff line
@@ -45,11 +45,11 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
		: "memory", "cc");
}

static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
					    u32 ecx_in, u32 *eax)
{
	int	cx, dx, si;
	u8	error;
	bool	error;

	/*
	 * N.B. We do NOT need a cld after the BIOS call
+8 −8
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@
#ifdef CONFIG_ARCH_RANDOM

/* Instead of arch_get_random_long() when alternatives haven't run. */
static inline int rdrand_long(unsigned long *v)
static inline bool rdrand_long(unsigned long *v)
{
	int ok;
	asm volatile("1: " RDRAND_LONG "\n\t"
@@ -53,13 +53,13 @@ static inline int rdrand_long(unsigned long *v)
		     "2:"
		     : "=r" (ok), "=a" (*v)
		     : "0" (RDRAND_RETRY_LOOPS));
	return ok;
	return !!ok;
}

/* A single attempt at RDSEED */
static inline bool rdseed_long(unsigned long *v)
{
	unsigned char ok;
	bool ok;
	asm volatile(RDSEED_LONG "\n\t"
		     "setc %0"
		     : "=qm" (ok), "=a" (*v));
@@ -67,7 +67,7 @@ static inline bool rdseed_long(unsigned long *v)
}

#define GET_RANDOM(name, type, rdrand, nop)			\
static inline int name(type *v)					\
static inline bool name(type *v)				\
{								\
	int ok;							\
	alternative_io("movl $0, %0\n\t"			\
@@ -80,13 +80,13 @@ static inline int name(type *v) \
		       X86_FEATURE_RDRAND,                      \
		       ASM_OUTPUT2("=r" (ok), "=a" (*v)),       \
		       "0" (RDRAND_RETRY_LOOPS));		\
	return ok;						\
	return !!ok;						\
}

#define GET_SEED(name, type, rdseed, nop)			\
static inline int name(type *v)					\
static inline bool name(type *v)				\
{								\
	unsigned char ok;					\
	bool ok;						\
	alternative_io("movb $0, %0\n\t"			\
		       nop,					\
		       rdseed "\n\t"				\
@@ -119,7 +119,7 @@ GET_SEED(arch_get_random_seed_int, unsigned int, RDSEED_INT, ASM_NOP4);

#else

static inline int rdrand_long(unsigned long *v)
static inline bool rdrand_long(unsigned long *v)
{
	return 0;
}
Loading