]> code.ossystems Code Review - meta-freescale.git/blob
e798d3e237868457e0ff6fad325de720d8e4a518
[meta-freescale.git] /
1 From a44701abd995b3db80001d0c5d88e9ead05972c1 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 24/26] 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 Change-Id: I980170969410381973ce75f6679a4a1401738847
16 Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
17 Reviewed-on: http://git.am.freescale.net:8181/34219
18 ---
19  crypto/engine/eng_cryptodev.c | 50 +++++++++++++++++++++----------------------
20  1 file changed, 24 insertions(+), 26 deletions(-)
21
22 diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
23 index dceb4f5..b74fc7c 100644
24 --- a/crypto/engine/eng_cryptodev.c
25 +++ b/crypto/engine/eng_cryptodev.c
26 @@ -306,47 +306,45 @@ static void ctr64_inc(unsigned char *counter) {
27                 if (c) return;
28         } while (n);
29  }
30 -/*
31 - * Return a fd if /dev/crypto seems usable, 0 otherwise.
32 - */
33 -static int
34 -open_dev_crypto(void)
35 +
36 +static int open_dev_crypto(void)
37  {
38 -       static int fd = -1;
39 +       int fd;
40  
41 -       if (fd == -1) {
42 -               if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1)
43 -                       return (-1);
44 -               /* close on exec */
45 -               if (fcntl(fd, F_SETFD, 1) == -1) {
46 -                       close(fd);
47 -                       fd = -1;
48 -                       return (-1);
49 -               }
50 +       fd = open("/dev/crypto", O_RDWR, 0);
51 +       if ( fd < 0)
52 +               return -1;
53 +
54 +       /* close on exec */
55 +       if (fcntl(fd, F_SETFD, 1) == -1) {
56 +               close(fd);
57 +               return -1;
58         }
59 -       return (fd);
60 +
61 +       return fd;
62  }
63  
64 -static int
65 -get_dev_crypto(void)
66 +static int get_dev_crypto(void)
67  {
68 -       int fd, retfd;
69 +       static int fd = -1;
70 +       int retfd;
71  
72 -       if ((fd = open_dev_crypto()) == -1)
73 -               return (-1);
74 -#ifndef CRIOGET_NOT_NEEDED
75 +       if (fd == -1)
76 +               fd = open_dev_crypto();
77 +#ifdef CRIOGET_NOT_NEEDED
78 +       return fd;
79 +#else
80 +       if (fd == -1)
81 +               return -1;
82         if (ioctl(fd, CRIOGET, &retfd) == -1)
83                 return (-1);
84 -
85         /* close on exec */
86         if (fcntl(retfd, F_SETFD, 1) == -1) {
87                 close(retfd);
88                 return (-1);
89         }
90 -#else
91 -        retfd = fd;
92 +       return retfd;
93  #endif
94 -       return (retfd);
95  }
96  
97  static void put_dev_crypto(int fd)
98 -- 
99 2.3.5
100