Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752822AbdFUQkm (ORCPT ); Wed, 21 Jun 2017 12:40:42 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33296 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751674AbdFUQkk (ORCPT ); Wed, 21 Jun 2017 12:40:40 -0400 Date: Wed, 21 Jun 2017 18:40:36 +0200 From: Ingo Molnar To: zhong jiang Cc: akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com, minchan@kernel.org, mhocko@suse.com, hpa@zytor.com, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative Message-ID: <20170621164036.4findvvz7jj4cvqo@gmail.com> References: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 969 Lines: 33 * zhong jiang wrote: > when shift expoment is negative, left shift alway zero. therefore, we > modify the logic to avoid the warining. > > Signed-off-by: zhong jiang > --- > 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