diff options
author | Nicolai Stange <nicstange@gmail.com> | 2016-03-22 08:12:39 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-04-05 08:35:48 -0400 |
commit | d755290689646fa66cc4830ca55569f2c9863666 (patch) | |
tree | 1f53b405afdfe27b0b5549fb5283b0f5b162b64a /lib/mpi/mpicoder.c | |
parent | cece762f6f3cb1c1687f467e98faef21b0096600 (diff) |
lib/mpi: mpi_write_sgl(): replace open coded endian conversion
Currently, the endian conversion from CPU order to BE is open coded in
mpi_write_sgl().
Replace this by the centrally provided cpu_to_be*() macros.
Signed-off-by: Nicolai Stange <nicstange@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'lib/mpi/mpicoder.c')
-rw-r--r-- | lib/mpi/mpicoder.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index b05d3902d363..623439e4bad5 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include <linux/bitops.h> | 21 | #include <linux/bitops.h> |
22 | #include <linux/count_zeros.h> | 22 | #include <linux/count_zeros.h> |
23 | #include <linux/byteorder/generic.h> | ||
23 | #include "mpi-internal.h" | 24 | #include "mpi-internal.h" |
24 | 25 | ||
25 | #define MAX_EXTERN_MPI_BITS 16384 | 26 | #define MAX_EXTERN_MPI_BITS 16384 |
@@ -359,7 +360,13 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, | |||
359 | int *sign) | 360 | int *sign) |
360 | { | 361 | { |
361 | u8 *p, *p2; | 362 | u8 *p, *p2; |
362 | mpi_limb_t alimb, alimb2; | 363 | #if BYTES_PER_MPI_LIMB == 4 |
364 | __be32 alimb; | ||
365 | #elif BYTES_PER_MPI_LIMB == 8 | ||
366 | __be64 alimb; | ||
367 | #else | ||
368 | #error please implement for this limb size. | ||
369 | #endif | ||
363 | unsigned int n = mpi_get_size(a); | 370 | unsigned int n = mpi_get_size(a); |
364 | int i, x, y = 0, lzeros, buf_len; | 371 | int i, x, y = 0, lzeros, buf_len; |
365 | 372 | ||
@@ -383,22 +390,10 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, | |||
383 | for (i = a->nlimbs - 1 - lzeros / BYTES_PER_MPI_LIMB, | 390 | for (i = a->nlimbs - 1 - lzeros / BYTES_PER_MPI_LIMB, |
384 | lzeros %= BYTES_PER_MPI_LIMB; | 391 | lzeros %= BYTES_PER_MPI_LIMB; |
385 | i >= 0; i--) { | 392 | i >= 0; i--) { |
386 | alimb = a->d[i]; | ||
387 | p = (u8 *)&alimb2; | ||
388 | #if BYTES_PER_MPI_LIMB == 4 | 393 | #if BYTES_PER_MPI_LIMB == 4 |
389 | *p++ = alimb >> 24; | 394 | alimb = cpu_to_be32(a->d[i]); |
390 | *p++ = alimb >> 16; | ||
391 | *p++ = alimb >> 8; | ||
392 | *p++ = alimb; | ||
393 | #elif BYTES_PER_MPI_LIMB == 8 | 395 | #elif BYTES_PER_MPI_LIMB == 8 |
394 | *p++ = alimb >> 56; | 396 | alimb = cpu_to_be64(a->d[i]); |
395 | *p++ = alimb >> 48; | ||
396 | *p++ = alimb >> 40; | ||
397 | *p++ = alimb >> 32; | ||
398 | *p++ = alimb >> 24; | ||
399 | *p++ = alimb >> 16; | ||
400 | *p++ = alimb >> 8; | ||
401 | *p++ = alimb; | ||
402 | #else | 397 | #else |
403 | #error please implement for this limb size. | 398 | #error please implement for this limb size. |
404 | #endif | 399 | #endif |
@@ -407,7 +402,7 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, | |||
407 | lzeros = 0; | 402 | lzeros = 0; |
408 | } | 403 | } |
409 | 404 | ||
410 | p = p - sizeof(alimb) + y; | 405 | p = (u8 *)&alimb + y; |
411 | 406 | ||
412 | for (x = 0; x < sizeof(alimb) - y; x++) { | 407 | for (x = 0; x < sizeof(alimb) - y; x++) { |
413 | if (!buf_len) { | 408 | if (!buf_len) { |