Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753210AbdCFJPh (ORCPT ); Mon, 6 Mar 2017 04:15:37 -0500 Received: from terminus.zytor.com ([65.50.211.136]:54148 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752848AbdCFJP1 (ORCPT ); Mon, 6 Mar 2017 04:15:27 -0500 Subject: Re: [PATCH 1/3] futex: remove duplicated code To: Jiri Slaby , Stafford Horne 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> Cc: Russell King - ARM Linux , akpm@linux-foundation.org, 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 From: "H. Peter Anvin" Message-ID: <29ec8cda-02bd-fe07-340b-2bb775c8446b@zytor.com> Date: Mon, 6 Mar 2017 01:13:52 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <3662dd60-2467-f858-dc32-0b0fb6abb33b@suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 755 Lines: 21 On 03/06/17 00:46, Jiri Slaby wrote: > > static int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr) > { > - int op = (encoded_op >> 28) & 7; > - int cmp = (encoded_op >> 24) & 15; > - 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; > At least in the sign-extend case the mask is unnecessary. This is why it would be nice to have both sign and zero extend for symmetry. -hpa