Re: [PATCH] x86/alternatives: Fix alt_max_short macro to really be a max()

From: Mathias Krause
Date: Thu Oct 05 2017 - 08:35:39 EST


On 5 October 2017 at 09:58, Mathias Krause <minipli@xxxxxxxxxxxxxx> wrote:
> On 5 October 2017 at 09:38, Borislav Petkov <bp@xxxxxxxxx> wrote:
>> On Wed, Oct 04, 2017 at 08:08:12PM +0200, Mathias Krause wrote:
>>> diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
>>> index c096624137ae..7c553f48f163 100644
>>> --- a/arch/x86/include/asm/alternative.h
>>> +++ b/arch/x86/include/asm/alternative.h
>>> @@ -106,9 +106,9 @@ static inline int alternatives_text_reserved(void *start, void *end)
>>> * max without conditionals. Idea adapted from:
>> ^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>> You did read this part, right?

Oh, btw., quoting its counter part from arch/x86/include/asm/alternative-asm.h:

/*
* max without conditionals. Idea adapted from:
* http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
*/
#define alt_max_short(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))

Note the "<"! ...comment is wrong, though the implementation works!

Cheers,
Mathias