hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/crypto/algboss.c
....@@ -1,13 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Create default crypto algorithm instances.
34 *
45 * 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
- *
116 */
127
138 #include <crypto/internal/aead.h>
....@@ -63,7 +58,6 @@
6358 {
6459 struct cryptomgr_param *param = data;
6560 struct crypto_template *tmpl;
66
- struct crypto_instance *inst;
6761 int err;
6862
6963 tmpl = crypto_lookup_template(param->template);
....@@ -71,16 +65,7 @@
7165 goto out;
7266
7367 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);
8469 } while (err == -EAGAIN && !signal_pending(current));
8570
8671 crypto_tmpl_put(tmpl);
....@@ -205,7 +190,6 @@
205190 return NOTIFY_OK;
206191 }
207192
208
-#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
209193 static int cryptomgr_test(void *data)
210194 {
211195 struct crypto_test_param *param = data;
....@@ -227,13 +211,10 @@
227211 kfree(param);
228212 module_put_and_exit(0);
229213 }
230
-#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
231214
232215 static int cryptomgr_schedule_test(struct crypto_alg *alg)
233216 {
234
-#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
235217 struct task_struct *thread;
236
-#endif
237218 struct crypto_test_param *param;
238219 u32 type;
239220
....@@ -254,23 +235,14 @@
254235
255236 param->type = type;
256237
257
-#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
258238 thread = kthread_run(cryptomgr_test, param, "cryptomgr_test");
259239 if (IS_ERR(thread))
260240 goto err_free_param;
261
-#else
262
- crypto_alg_tested(param->driver, 0);
263
-
264
- kfree(param);
265
- module_put(THIS_MODULE);
266
-#endif
267241
268242 return NOTIFY_STOP;
269243
270
-#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
271244 err_free_param:
272245 kfree(param);
273
-#endif
274246 err_put_module:
275247 module_put(THIS_MODULE);
276248 err:
....@@ -285,6 +257,8 @@
285257 return cryptomgr_schedule_probe(data);
286258 case CRYPTO_MSG_ALG_REGISTER:
287259 return cryptomgr_schedule_test(data);
260
+ case CRYPTO_MSG_ALG_LOADED:
261
+ break;
288262 }
289263
290264 return NOTIFY_DONE;
....@@ -305,7 +279,13 @@
305279 BUG_ON(err);
306280 }
307281
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);
309289 module_exit(cryptomgr_exit);
310290
311291 MODULE_LICENSE("GPL");