Re: [PATCH 1/3] futex: remove duplicated code
From: Geert Uytterhoeven
Date: Mon Mar 06 2017 - 09:14:48 EST
Hi Jiri,
On Mon, Mar 6, 2017 at 9:46 AM, Jiri Slaby <jslaby@xxxxxxx> 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 <jslaby@xxxxxxx>
>
> 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@xxxxxxxxxxxxxx
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