1 From ad7fee26da24fca57efee5ba10756e001769b2ce Mon Sep 17 00:00:00 2001
2 From: Alexe Radu <radu.alexe@nxp.com>
3 Date: Tue, 25 Oct 2016 16:46:11 +0300
4 Subject: [PATCH 056/104] fix: set min value when allocating alligned memory
7 The function "posix_memalign()" requires that the alignment be at least
8 sizeof(void*). In some situations the alignmask for some crypto algorithms
9 is smaller then the minimum required. For ex. on 64-bit platforms where
10 the alignment may be 4 bytes.
12 Signed-off-by: Alexe Radu <radu.alexe@nxp.com>
13 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
15 tests/async_speed.c | 4 ++++
17 2 files changed, 6 insertions(+)
19 diff --git a/tests/async_speed.c b/tests/async_speed.c
20 index 263ead7..b895a85 100644
21 --- a/tests/async_speed.c
22 +++ b/tests/async_speed.c
23 @@ -232,6 +232,7 @@ int run_test(int id, struct test_params tp)
24 int get_alignmask(int fdc, struct session_op *sess)
27 + int min_alignmask = sizeof(void*) - 1;
30 struct session_info_op siop;
31 @@ -242,6 +243,9 @@ int get_alignmask(int fdc, struct session_op *sess)
34 alignmask = siop.alignmask;
35 + if (alignmask < min_alignmask) {
36 + alignmask = min_alignmask;
41 diff --git a/tests/speed.c b/tests/speed.c
42 index bd6d2b2..0b14c88 100644
45 @@ -80,8 +80,10 @@ int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
47 double secs, ddata, dspeed;
49 + int min_alignmask = sizeof(void*) - 1;
52 + alignmask = ((alignmask < min_alignmask) ? min_alignmask : alignmask);
53 if (posix_memalign((void **)&buffer, MAX(alignmask + 1, sizeof(void*)), chunksize)) {
54 printf("posix_memalign() failed! (mask %x, size: %d)\n", alignmask+1, chunksize);