diff --git a/lib/tcrypt/tcrypt.c b/lib/tcrypt/tcrypt.c index 1672c718..b1ebd051 100644 --- a/lib/tcrypt/tcrypt.c +++ b/lib/tcrypt/tcrypt.c @@ -471,16 +471,12 @@ static int TCRYPT_init_hdr(struct crypt_device *cd, struct crypt_params_tcrypt *params) { unsigned char pwd[TCRYPT_KEY_POOL_LEN] = {}; - size_t passphrase_size, alignment; + size_t passphrase_size; char *key; unsigned int i, skipped = 0; int r = -EINVAL, legacy_modes; - alignment = crypt_getpagesize(); - if (alignment < 0) - return -EINVAL; - - if (posix_memalign((void*)&key, alignment, TCRYPT_HDR_KEY_LEN)) + if (posix_memalign((void*)&key, crypt_getpagesize(), TCRYPT_HDR_KEY_LEN)) return -ENOMEM; if (params->keyfiles_count) diff --git a/lib/utils.c b/lib/utils.c index 22315227..eef78911 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -30,7 +30,8 @@ unsigned crypt_getpagesize(void) { - return (unsigned)sysconf(_SC_PAGESIZE); + long r = sysconf(_SC_PAGESIZE); + return r < 0 ? DEFAULT_MEM_ALIGNMENT : r; } static int get_alignment(int fd) diff --git a/lib/utils_benchmark.c b/lib/utils_benchmark.c index f3923828..4ee0c033 100644 --- a/lib/utils_benchmark.c +++ b/lib/utils_benchmark.c @@ -128,14 +128,9 @@ static int cipher_perf(struct cipher_perf *cp, { long ms_enc, ms_dec, ms; int repeat_enc, repeat_dec; - size_t alignment; void *buf = NULL; - alignment = crypt_getpagesize(); - if (alignment < 0) - return -EINVAL; - - if (posix_memalign(&buf, alignment, cp->buffer_size)) + if (posix_memalign(&buf, crypt_getpagesize(), cp->buffer_size)) return -ENOMEM; ms_enc = 0;