Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1671797

Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative

From Ingo Molnar <mingo@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative
Date 2017-06-21 18:50 +0200
Message-ID <tUQZk-aB-19@gated-at.bofh.it> (permalink)
References <tUQZk-aB-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


* zhong jiang <zhongjiang@huawei.com> wrote:

> when shift expoment is negative, left shift alway zero. therefore, we
> modify the logic to avoid the warining.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  arch/x86/include/asm/futex.h | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
> index b4c1f54..2425fca 100644
> --- a/arch/x86/include/asm/futex.h
> +++ b/arch/x86/include/asm/futex.h
> @@ -49,8 +49,12 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
>  	int cmparg = (encoded_op << 20) >> 20;
>  	int oldval = 0, ret, tem;
>  
> -	if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
> -		oparg = 1 << oparg;
> +	if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) {
> +		if (oparg >= 0)
> +			oparg = 1 << oparg;
> +		else
> +			oparg = 0;
> +	}

Could we avoid all these complications by using an unsigned type?

Thanks,

	Ingo

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH] futex: avoid undefined behaviour when shift exponent is  negative Ingo Molnar <mingo@kernel.org> - 2017-06-21 18:50 +0200
  Re: [PATCH] futex: avoid undefined behaviour when shift exponent  is negative zhong jiang <zhongjiang@huawei.com> - 2017-06-28 06:40 +0200
    Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative hpa@zytor.com - 2017-06-28 23:50 +0200
      Re: [PATCH] futex: avoid undefined behaviour when shift exponent  is negative zhong jiang <zhongjiang@huawei.com> - 2017-06-29 04:20 +0200
        Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative hpa@zytor.com - 2017-06-29 06:40 +0200
          Re: [PATCH] futex: avoid undefined behaviour when shift exponent  is negative zhong jiang <zhongjiang@huawei.com> - 2017-06-29 08:10 +0200
    Re: [PATCH] futex: avoid undefined behaviour when shift exponent is  negative Thomas Gleixner <tglx@linutronix.de> - 2017-06-29 00:20 +0200
      Re: [PATCH] futex: avoid undefined behaviour when shift exponent  is negative zhong jiang <zhongjiang@huawei.com> - 2017-06-29 04:00 +0200
        Re: [PATCH] futex: avoid undefined behaviour when shift exponent is  negative Thomas Gleixner <tglx@linutronix.de> - 2017-06-29 08:40 +0200
          Re: [PATCH] futex: avoid undefined behaviour when shift exponent  is negative zhong jiang <zhongjiang@huawei.com> - 2017-06-29 09:10 +0200

csiph-web