mpilib: use DIV_ROUND_UP and remove unused macros

Remove MIN, MAX and ABS macros that are duplicates kernel's native
implementation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
This commit is contained in:
Andy Shevchenko 2013-01-30 11:30:06 +02:00 committed by James Morris
parent 26d438457e
commit 0d2a1b2d03
2 changed files with 4 additions and 8 deletions

View file

@ -65,10 +65,6 @@
typedef mpi_limb_t *mpi_ptr_t; /* pointer to a limb */ typedef mpi_limb_t *mpi_ptr_t; /* pointer to a limb */
typedef int mpi_size_t; /* (must be a signed type) */ typedef int mpi_size_t; /* (must be a signed type) */
#define ABS(x) (x >= 0 ? x : -x)
#define MIN(l, o) ((l) < (o) ? (l) : (o))
#define MAX(h, i) ((h) > (i) ? (h) : (i))
static inline int RESIZE_IF_NEEDED(MPI a, unsigned b) static inline int RESIZE_IF_NEEDED(MPI a, unsigned b)
{ {
if (a->alloced < b) if (a->alloced < b)

View file

@ -52,7 +52,7 @@ MPI mpi_read_raw_data(const void *xbuffer, size_t nbytes)
else else
nbits = 0; nbits = 0;
nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB; nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB);
val = mpi_alloc(nlimbs); val = mpi_alloc(nlimbs);
if (!val) if (!val)
return NULL; return NULL;
@ -96,8 +96,8 @@ MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread)
buffer += 2; buffer += 2;
nread = 2; nread = 2;
nbytes = (nbits + 7) / 8; nbytes = DIV_ROUND_UP(nbits, 8);
nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB; nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB);
val = mpi_alloc(nlimbs); val = mpi_alloc(nlimbs);
if (!val) if (!val)
return NULL; return NULL;
@ -193,7 +193,7 @@ int mpi_set_buffer(MPI a, const void *xbuffer, unsigned nbytes, int sign)
int nlimbs; int nlimbs;
int i; int i;
nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB; nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB);
if (RESIZE_IF_NEEDED(a, nlimbs) < 0) if (RESIZE_IF_NEEDED(a, nlimbs) < 0)
return -ENOMEM; return -ENOMEM;
a->sign = sign; a->sign = sign;