Commit d7552906 authored by Nicolai Stange's avatar Nicolai Stange Committed by Herbert Xu

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: default avatarNicolai Stange <nicstange@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent cece762f
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/count_zeros.h> #include <linux/count_zeros.h>
#include <linux/byteorder/generic.h>
#include "mpi-internal.h" #include "mpi-internal.h"
#define MAX_EXTERN_MPI_BITS 16384 #define MAX_EXTERN_MPI_BITS 16384
...@@ -359,7 +360,13 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, ...@@ -359,7 +360,13 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes,
int *sign) int *sign)
{ {
u8 *p, *p2; u8 *p, *p2;
mpi_limb_t alimb, alimb2; #if BYTES_PER_MPI_LIMB == 4
__be32 alimb;
#elif BYTES_PER_MPI_LIMB == 8
__be64 alimb;
#else
#error please implement for this limb size.
#endif
unsigned int n = mpi_get_size(a); unsigned int n = mpi_get_size(a);
int i, x, y = 0, lzeros, buf_len; int i, x, y = 0, lzeros, buf_len;
...@@ -383,22 +390,10 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, ...@@ -383,22 +390,10 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes,
for (i = a->nlimbs - 1 - lzeros / BYTES_PER_MPI_LIMB, for (i = a->nlimbs - 1 - lzeros / BYTES_PER_MPI_LIMB,
lzeros %= BYTES_PER_MPI_LIMB; lzeros %= BYTES_PER_MPI_LIMB;
i >= 0; i--) { i >= 0; i--) {
alimb = a->d[i];
p = (u8 *)&alimb2;
#if BYTES_PER_MPI_LIMB == 4 #if BYTES_PER_MPI_LIMB == 4
*p++ = alimb >> 24; alimb = cpu_to_be32(a->d[i]);
*p++ = alimb >> 16;
*p++ = alimb >> 8;
*p++ = alimb;
#elif BYTES_PER_MPI_LIMB == 8 #elif BYTES_PER_MPI_LIMB == 8
*p++ = alimb >> 56; alimb = cpu_to_be64(a->d[i]);
*p++ = alimb >> 48;
*p++ = alimb >> 40;
*p++ = alimb >> 32;
*p++ = alimb >> 24;
*p++ = alimb >> 16;
*p++ = alimb >> 8;
*p++ = alimb;
#else #else
#error please implement for this limb size. #error please implement for this limb size.
#endif #endif
...@@ -407,7 +402,7 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, ...@@ -407,7 +402,7 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes,
lzeros = 0; lzeros = 0;
} }
p = p - sizeof(alimb) + y; p = (u8 *)&alimb + y;
for (x = 0; x < sizeof(alimb) - y; x++) { for (x = 0; x < sizeof(alimb) - y; x++) {
if (!buf_len) { if (!buf_len) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment