diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2024-08-10 14:20:57 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2024-08-17 13:55:50 +0800 |
commit | 8e3a67f2de87ee94ac11ea69beb4edc2993b17a0 (patch) | |
tree | f9d05f6e63667776697cf2642098292f7c9d91cf /lib/crypto/mpi/mpi-internal.h | |
parent | fca5cb4dd2b4a9423cb6d112cc71c33899955a1f (diff) |
crypto: lib/mpi - Add error checks to extension
The remaining functions added by commit
a8ea8bdd9df92a0e5db5b43900abb7a288b8a53e did not check for memory
allocation errors. Add the checks and change the API to allow errors
to be returned.
Fixes: a8ea8bdd9df9 ("lib/mpi: Extend the MPI library")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'lib/crypto/mpi/mpi-internal.h')
-rw-r--r-- | lib/crypto/mpi/mpi-internal.h | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/crypto/mpi/mpi-internal.h b/lib/crypto/mpi/mpi-internal.h index b6fbb43afbc8..8a4f49e3043c 100644 --- a/lib/crypto/mpi/mpi-internal.h +++ b/lib/crypto/mpi/mpi-internal.h @@ -52,11 +52,12 @@ typedef mpi_limb_t *mpi_ptr_t; /* pointer to a limb */ typedef int mpi_size_t; /* (must be a signed type) */ -#define RESIZE_IF_NEEDED(a, b) \ - do { \ - if ((a)->alloced < (b)) \ - mpi_resize((a), (b)); \ - } while (0) +static inline int RESIZE_IF_NEEDED(MPI a, unsigned b) +{ + if (a->alloced < b) + return mpi_resize(a, b); + return 0; +} /* Copy N limbs from S to D. */ #define MPN_COPY(d, s, n) \ |