Get page size should never fail (in the works case it fails later with wrong alignment).

This commit is contained in:
Milan Broz
2012-12-10 17:47:06 +01:00
parent 80d21c039e
commit 50d5cfa8bc
3 changed files with 5 additions and 13 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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;