Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MPILIB: Deobfuscate mpi_cmp

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>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>

authored by

Rasmus Villemoes and committed by
David Howells
7fe21291 b2d1965d

+3 -5
+3 -5
lib/mpi/mpi-cmp.c
··· 61 61 if (!usize) 62 62 return 0; 63 63 cmp = mpihelp_cmp(u->d, v->d, usize); 64 - if (!cmp) 65 - return 0; 66 - if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0)) 67 - return 1; 68 - return -1; 64 + if (u->sign) 65 + return -cmp; 66 + return cmp; 69 67 } 70 68 EXPORT_SYMBOL_GPL(mpi_cmp);