public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: dhowells@redhat.com, Rusty Russell <rusty@rustcorp.com.au>,
	d.kasatkin@samsung.com, linux-kernel@vger.kernel.org,
	keyrings@linux-nfs.org
Subject: Re: [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp
Date: Fri, 09 Jan 2015 11:00:23 +0000	[thread overview]
Message-ID: <2258.1420801223@warthog.procyon.org.uk> (raw)
In-Reply-To: <1417824042-539-2-git-send-email-linux@rasmusvillemoes.dk>

This looks very reasonable.  cc'ing Dmitry for his check.

David
---
Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:

> The condition preceding 'return 1;' makes my head hurt. At this point,
> we know that u and v have the same sign; if they are negative, they
> compare opposite to how their absolute values compare (which
> mpihelp_cmp found for us), otherwise cmp itself is the
> answer. Negating cmp is ok since mpihelp_cmp returns {-1,0,1};
> -INT_MIN==INT_MIN won't bite us.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  lib/mpi/mpi-cmp.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
> index 3801694240d8..d25e9e96c310 100644
> --- a/lib/mpi/mpi-cmp.c
> +++ b/lib/mpi/mpi-cmp.c
> @@ -61,10 +61,8 @@ int mpi_cmp(MPI u, MPI v)
>  	if (!usize)
>  		return 0;
>  	cmp = mpihelp_cmp(u->d, v->d, usize);
> -	if (!cmp)
> -		return 0;
> -	if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0))
> -		return 1;
> -	return -1;
> +	if (u->sign)
> +		return -cmp;
> +	return cmp;
>  }
>  EXPORT_SYMBOL_GPL(mpi_cmp);
> -- 
> 2.1.3

  reply	other threads:[~2015-01-09 11:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-06  0:00 [PATCH 1/2] MPILIB: Fix comparison of negative MPIs Rasmus Villemoes
2014-12-06  0:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp Rasmus Villemoes
2015-01-09 11:00   ` David Howells [this message]
2015-01-10 10:29     ` [Keyrings] " Dmitry Kasatkin
2015-01-12 11:43       ` David Howells
2015-01-12 11:47         ` Dmitry Kasatkin
2015-01-09 10:58 ` [PATCH 1/2] MPILIB: Fix comparison of negative MPIs David Howells
2015-01-10 10:27   ` [Keyrings] " Dmitry Kasatkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2258.1420801223@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=d.kasatkin@samsung.com \
    --cc=keyrings@linux-nfs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox