diff options
Diffstat (limited to 'recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch')
| -rw-r--r-- | recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch new file mode 100644 index 000000000..9c6e503b8 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | From d9395f7d876f7dfaaae25867c88d1e1f684589de Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Thu, 19 Feb 2015 16:43:29 +0200 | ||
| 4 | Subject: [PATCH 21/48] cryptodev: do not cache file descriptor in 'open' | ||
| 5 | |||
| 6 | The file descriptor returned by get_dev_crypto is cached after a | ||
| 7 | successful return. The issue is, it is cached inside 'open_dev_crypto' | ||
| 8 | which is no longer useful as a general purpose open("/dev/crypto") | ||
| 9 | function. | ||
| 10 | |||
| 11 | This patch is a refactoring that moves the caching operation from | ||
| 12 | open_dev_crypto to get_dev_crypto and leaves the former as a simpler | ||
| 13 | function true to its name | ||
| 14 | |||
| 15 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 16 | --- | ||
| 17 | crypto/engine/eng_cryptodev.c | 43 +++++++++++++++++++++---------------------- | ||
| 18 | 1 file changed, 21 insertions(+), 22 deletions(-) | ||
| 19 | |||
| 20 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 21 | index 14dcddf..75fca7f 100644 | ||
| 22 | --- a/crypto/engine/eng_cryptodev.c | ||
| 23 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 24 | @@ -391,45 +391,44 @@ static void ctr64_inc(unsigned char *counter) | ||
| 25 | } while (n); | ||
| 26 | } | ||
| 27 | |||
| 28 | -/* | ||
| 29 | - * Return a fd if /dev/crypto seems usable, 0 otherwise. | ||
| 30 | - */ | ||
| 31 | static int open_dev_crypto(void) | ||
| 32 | { | ||
| 33 | - static int fd = -1; | ||
| 34 | + int fd; | ||
| 35 | |||
| 36 | - if (fd == -1) { | ||
| 37 | - if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) | ||
| 38 | - return (-1); | ||
| 39 | - /* close on exec */ | ||
| 40 | - if (fcntl(fd, F_SETFD, 1) == -1) { | ||
| 41 | - close(fd); | ||
| 42 | - fd = -1; | ||
| 43 | - return (-1); | ||
| 44 | - } | ||
| 45 | + fd = open("/dev/crypto", O_RDWR, 0); | ||
| 46 | + if (fd < 0) | ||
| 47 | + return -1; | ||
| 48 | + | ||
| 49 | + /* close on exec */ | ||
| 50 | + if (fcntl(fd, F_SETFD, 1) == -1) { | ||
| 51 | + close(fd); | ||
| 52 | + return -1; | ||
| 53 | } | ||
| 54 | - return (fd); | ||
| 55 | + | ||
| 56 | + return fd; | ||
| 57 | } | ||
| 58 | |||
| 59 | static int get_dev_crypto(void) | ||
| 60 | { | ||
| 61 | - int fd, retfd; | ||
| 62 | + static int fd = -1; | ||
| 63 | + int retfd; | ||
| 64 | |||
| 65 | - if ((fd = open_dev_crypto()) == -1) | ||
| 66 | - return (-1); | ||
| 67 | -# ifndef CRIOGET_NOT_NEEDED | ||
| 68 | + if (fd == -1) | ||
| 69 | + fd = open_dev_crypto(); | ||
| 70 | +# ifdef CRIOGET_NOT_NEEDED | ||
| 71 | + return fd; | ||
| 72 | +# else | ||
| 73 | + if (fd == -1) | ||
| 74 | + return -1; | ||
| 75 | if (ioctl(fd, CRIOGET, &retfd) == -1) | ||
| 76 | return (-1); | ||
| 77 | - | ||
| 78 | /* close on exec */ | ||
| 79 | if (fcntl(retfd, F_SETFD, 1) == -1) { | ||
| 80 | close(retfd); | ||
| 81 | return (-1); | ||
| 82 | } | ||
| 83 | -# else | ||
| 84 | - retfd = fd; | ||
| 85 | + return retfd; | ||
| 86 | # endif | ||
| 87 | - return (retfd); | ||
| 88 | } | ||
| 89 | |||
| 90 | static void put_dev_crypto(int fd) | ||
| 91 | -- | ||
| 92 | 2.7.0 | ||
| 93 | |||
