.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Create default crypto algorithm instances. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au> |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify it |
---|
7 | | - * under the terms of the GNU General Public License as published by the Free |
---|
8 | | - * Software Foundation; either version 2 of the License, or (at your option) |
---|
9 | | - * any later version. |
---|
10 | | - * |
---|
11 | 6 | */ |
---|
12 | 7 | |
---|
13 | 8 | #include <crypto/internal/aead.h> |
---|
.. | .. |
---|
63 | 58 | { |
---|
64 | 59 | struct cryptomgr_param *param = data; |
---|
65 | 60 | struct crypto_template *tmpl; |
---|
66 | | - struct crypto_instance *inst; |
---|
67 | 61 | int err; |
---|
68 | 62 | |
---|
69 | 63 | tmpl = crypto_lookup_template(param->template); |
---|
.. | .. |
---|
71 | 65 | goto out; |
---|
72 | 66 | |
---|
73 | 67 | do { |
---|
74 | | - if (tmpl->create) { |
---|
75 | | - err = tmpl->create(tmpl, param->tb); |
---|
76 | | - continue; |
---|
77 | | - } |
---|
78 | | - |
---|
79 | | - inst = tmpl->alloc(param->tb); |
---|
80 | | - if (IS_ERR(inst)) |
---|
81 | | - err = PTR_ERR(inst); |
---|
82 | | - else if ((err = crypto_register_instance(tmpl, inst))) |
---|
83 | | - tmpl->free(inst); |
---|
| 68 | + err = tmpl->create(tmpl, param->tb); |
---|
84 | 69 | } while (err == -EAGAIN && !signal_pending(current)); |
---|
85 | 70 | |
---|
86 | 71 | crypto_tmpl_put(tmpl); |
---|
.. | .. |
---|
205 | 190 | return NOTIFY_OK; |
---|
206 | 191 | } |
---|
207 | 192 | |
---|
208 | | -#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS |
---|
209 | 193 | static int cryptomgr_test(void *data) |
---|
210 | 194 | { |
---|
211 | 195 | struct crypto_test_param *param = data; |
---|
.. | .. |
---|
227 | 211 | kfree(param); |
---|
228 | 212 | module_put_and_exit(0); |
---|
229 | 213 | } |
---|
230 | | -#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */ |
---|
231 | 214 | |
---|
232 | 215 | static int cryptomgr_schedule_test(struct crypto_alg *alg) |
---|
233 | 216 | { |
---|
234 | | -#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS |
---|
235 | 217 | struct task_struct *thread; |
---|
236 | | -#endif |
---|
237 | 218 | struct crypto_test_param *param; |
---|
238 | 219 | u32 type; |
---|
239 | 220 | |
---|
.. | .. |
---|
254 | 235 | |
---|
255 | 236 | param->type = type; |
---|
256 | 237 | |
---|
257 | | -#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS |
---|
258 | 238 | thread = kthread_run(cryptomgr_test, param, "cryptomgr_test"); |
---|
259 | 239 | if (IS_ERR(thread)) |
---|
260 | 240 | goto err_free_param; |
---|
261 | | -#else |
---|
262 | | - crypto_alg_tested(param->driver, 0); |
---|
263 | | - |
---|
264 | | - kfree(param); |
---|
265 | | - module_put(THIS_MODULE); |
---|
266 | | -#endif |
---|
267 | 241 | |
---|
268 | 242 | return NOTIFY_STOP; |
---|
269 | 243 | |
---|
270 | | -#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS |
---|
271 | 244 | err_free_param: |
---|
272 | 245 | kfree(param); |
---|
273 | | -#endif |
---|
274 | 246 | err_put_module: |
---|
275 | 247 | module_put(THIS_MODULE); |
---|
276 | 248 | err: |
---|
.. | .. |
---|
285 | 257 | return cryptomgr_schedule_probe(data); |
---|
286 | 258 | case CRYPTO_MSG_ALG_REGISTER: |
---|
287 | 259 | return cryptomgr_schedule_test(data); |
---|
| 260 | + case CRYPTO_MSG_ALG_LOADED: |
---|
| 261 | + break; |
---|
288 | 262 | } |
---|
289 | 263 | |
---|
290 | 264 | return NOTIFY_DONE; |
---|
.. | .. |
---|
305 | 279 | BUG_ON(err); |
---|
306 | 280 | } |
---|
307 | 281 | |
---|
308 | | -subsys_initcall(cryptomgr_init); |
---|
| 282 | +/* |
---|
| 283 | + * This is arch_initcall() so that the crypto self-tests are run on algorithms |
---|
| 284 | + * registered early by subsys_initcall(). subsys_initcall() is needed for |
---|
| 285 | + * generic implementations so that they're available for comparison tests when |
---|
| 286 | + * other implementations are registered later by module_init(). |
---|
| 287 | + */ |
---|
| 288 | +arch_initcall(cryptomgr_init); |
---|
309 | 289 | module_exit(cryptomgr_exit); |
---|
310 | 290 | |
---|
311 | 291 | MODULE_LICENSE("GPL"); |
---|