Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932144AbdCFOOe (ORCPT ); Mon, 6 Mar 2017 09:14:34 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:36285 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753150AbdCFOOO (ORCPT ); Mon, 6 Mar 2017 09:14:14 -0500 MIME-Version: 1.0 In-Reply-To: <3662dd60-2467-f858-dc32-0b0fb6abb33b@suse.cz> References: <20170303122712.13353-1-jslaby@suse.cz> <20170304130550.GT21222@n2100.armlinux.org.uk> <3994975e-89a5-d2b5-60be-a8633ddc3733@zytor.com> <20170304213805.GA2449@lianli.shorne-pla.net> <201703042308.v24N8wvh012716@mail.zytor.com> <20170304233919.GB2449@lianli.shorne-pla.net> <3662dd60-2467-f858-dc32-0b0fb6abb33b@suse.cz> From: Geert Uytterhoeven Date: Mon, 6 Mar 2017 15:14:08 +0100 X-Google-Sender-Auth: zbMS60lNHr5j2BcU57uFPwhTv3w Message-ID: Subject: Re: [PATCH 1/3] futex: remove duplicated code To: Jiri Slaby Cc: Stafford Horne , "H. Peter Anvin" , Russell King - ARM Linux , Andrew Morton , "linux-kernel@vger.kernel.org" , Richard Henderson , Ivan Kokshaysky , Matt Turner , Vineet Gupta , Catalin Marinas , Will Deacon , Richard Kuo , Tony Luck , Fenghua Yu , Michal Simek , Ralf Baechle , Jonas Bonn , Stefan Kristiansson , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Martin Schwidefsky , Heiko Carstens , Yoshinori Sato , Rich Felker , DavidS.Miller@zytor.com Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1764 Lines: 46 Hi Jiri, On Mon, Mar 6, 2017 at 9:46 AM, Jiri Slaby wrote: > futex: make the encoded_op decoding readable > > Decoding of encoded_op is a bit unreadable. It contains shifts to the > left and to the right by some constants. Make it clearly visible what > part of the bit mask is taken and shift the values only to the right > appropriately. And make sure sign extension takes place using > sign_extend32. > > Signed-off-by: Jiri Slaby > > diff --git a/kernel/futex.c b/kernel/futex.c > index 0ead0756a593..f90314bd42cb 100644 > --- a/kernel/futex.c > +++ b/kernel/futex.c > @@ -1461,10 +1461,10 @@ futex_wake(u32 __user *uaddr, unsigned int > flags, int nr_wake, u32 bitset) > > static int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr) > { > - int op = (encoded_op >> 28) & 7; > - int cmp = (encoded_op >> 24) & 15; At least for the two above (modulo 7 vs 15?), the old decoding code matched the flow of operation in FUTEX_OP(). > - int oparg = (encoded_op << 8) >> 20; > - int cmparg = (encoded_op << 20) >> 20; > + int op = (encoded_op & 0x70000000) >> 28; > + int cmp = (encoded_op & 0x0f000000) >> 24; > + int oparg = sign_extend32((encoded_op & 0x00fff000) >> 12, 12); > + int cmparg = sign_extend32(encoded_op & 0x00000fff, 12); > int oldval, ret; Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds