aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/api.c32
-rw-r--r--crypto/proc.c3
2 files changed, 29 insertions, 6 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 8c2743a05f90..5994a58ef954 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -29,13 +29,26 @@
29LIST_HEAD(crypto_alg_list); 29LIST_HEAD(crypto_alg_list);
30DECLARE_RWSEM(crypto_alg_sem); 30DECLARE_RWSEM(crypto_alg_sem);
31 31
32static inline int crypto_mod_get(struct crypto_alg *alg) 32static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
33{ 33{
34 return try_module_get(alg->cra_module); 34 atomic_inc(&alg->cra_refcnt);
35 return alg;
36}
37
38static inline void crypto_alg_put(struct crypto_alg *alg)
39{
40 if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
41 alg->cra_destroy(alg);
42}
43
44static struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
45{
46 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
35} 47}
36 48
37static inline void crypto_mod_put(struct crypto_alg *alg) 49static void crypto_mod_put(struct crypto_alg *alg)
38{ 50{
51 crypto_alg_put(alg);
39 module_put(alg->cra_module); 52 module_put(alg->cra_module);
40} 53}
41 54
@@ -274,6 +287,7 @@ int crypto_register_alg(struct crypto_alg *alg)
274 } 287 }
275 288
276 list_add(&alg->cra_list, &crypto_alg_list); 289 list_add(&alg->cra_list, &crypto_alg_list);
290 atomic_set(&alg->cra_refcnt, 1);
277out: 291out:
278 up_write(&crypto_alg_sem); 292 up_write(&crypto_alg_sem);
279 return ret; 293 return ret;
@@ -284,8 +298,6 @@ int crypto_unregister_alg(struct crypto_alg *alg)
284 int ret = -ENOENT; 298 int ret = -ENOENT;
285 struct crypto_alg *q; 299 struct crypto_alg *q;
286 300
287 BUG_ON(!alg->cra_module);
288
289 down_write(&crypto_alg_sem); 301 down_write(&crypto_alg_sem);
290 list_for_each_entry(q, &crypto_alg_list, cra_list) { 302 list_for_each_entry(q, &crypto_alg_list, cra_list) {
291 if (alg == q) { 303 if (alg == q) {
@@ -296,7 +308,15 @@ int crypto_unregister_alg(struct crypto_alg *alg)
296 } 308 }
297out: 309out:
298 up_write(&crypto_alg_sem); 310 up_write(&crypto_alg_sem);
299 return ret; 311
312 if (ret)
313 return ret;
314
315 BUG_ON(atomic_read(&alg->cra_refcnt) != 1);
316 if (alg->cra_destroy)
317 alg->cra_destroy(alg);
318
319 return 0;
300} 320}
301 321
302int crypto_alg_available(const char *name, u32 flags) 322int crypto_alg_available(const char *name, u32 flags)
diff --git a/crypto/proc.c b/crypto/proc.c
index c0a5dd7ce2cc..8543b7a157d6 100644
--- a/crypto/proc.c
+++ b/crypto/proc.c
@@ -12,6 +12,8 @@
12 * any later version. 12 * any later version.
13 * 13 *
14 */ 14 */
15
16#include <asm/atomic.h>
15#include <linux/init.h> 17#include <linux/init.h>
16#include <linux/crypto.h> 18#include <linux/crypto.h>
17#include <linux/rwsem.h> 19#include <linux/rwsem.h>
@@ -54,6 +56,7 @@ static int c_show(struct seq_file *m, void *p)
54 seq_printf(m, "driver : %s\n", alg->cra_driver_name); 56 seq_printf(m, "driver : %s\n", alg->cra_driver_name);
55 seq_printf(m, "module : %s\n", module_name(alg->cra_module)); 57 seq_printf(m, "module : %s\n", module_name(alg->cra_module));
56 seq_printf(m, "priority : %d\n", alg->cra_priority); 58 seq_printf(m, "priority : %d\n", alg->cra_priority);
59 seq_printf(m, "refcnt : %d\n", atomic_read(&alg->cra_refcnt));
57 60
58 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { 61 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
59 case CRYPTO_ALG_TYPE_CIPHER: 62 case CRYPTO_ALG_TYPE_CIPHER: