Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 34204
b: refs/heads/master
c: 6521f30
h: refs/heads/master
v: v3
  • Loading branch information
Herbert Xu committed Sep 21, 2006
1 parent b67715d commit 6f66ea7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 72fa491912689ca69dd15f4266945d2c2f2819f8
refs/heads/master: 6521f30273fbec65146a0f16de74b7b402b0f7b0
32 changes: 26 additions & 6 deletions trunk/crypto/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,26 @@
LIST_HEAD(crypto_alg_list);
DECLARE_RWSEM(crypto_alg_sem);

static inline int crypto_mod_get(struct crypto_alg *alg)
static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
{
return try_module_get(alg->cra_module);
atomic_inc(&alg->cra_refcnt);
return alg;
}

static inline void crypto_alg_put(struct crypto_alg *alg)
{
if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
alg->cra_destroy(alg);
}

static struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
{
return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
}

static inline void crypto_mod_put(struct crypto_alg *alg)
static void crypto_mod_put(struct crypto_alg *alg)
{
crypto_alg_put(alg);
module_put(alg->cra_module);
}

Expand Down Expand Up @@ -274,6 +287,7 @@ int crypto_register_alg(struct crypto_alg *alg)
}

list_add(&alg->cra_list, &crypto_alg_list);
atomic_set(&alg->cra_refcnt, 1);
out:
up_write(&crypto_alg_sem);
return ret;
Expand All @@ -284,8 +298,6 @@ int crypto_unregister_alg(struct crypto_alg *alg)
int ret = -ENOENT;
struct crypto_alg *q;

BUG_ON(!alg->cra_module);

down_write(&crypto_alg_sem);
list_for_each_entry(q, &crypto_alg_list, cra_list) {
if (alg == q) {
Expand All @@ -296,7 +308,15 @@ int crypto_unregister_alg(struct crypto_alg *alg)
}
out:
up_write(&crypto_alg_sem);
return ret;

if (ret)
return ret;

BUG_ON(atomic_read(&alg->cra_refcnt) != 1);
if (alg->cra_destroy)
alg->cra_destroy(alg);

return 0;
}

int crypto_alg_available(const char *name, u32 flags)
Expand Down
3 changes: 3 additions & 0 deletions trunk/crypto/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* any later version.
*
*/

#include <asm/atomic.h>
#include <linux/init.h>
#include <linux/crypto.h>
#include <linux/rwsem.h>
Expand Down Expand Up @@ -54,6 +56,7 @@ static int c_show(struct seq_file *m, void *p)
seq_printf(m, "driver : %s\n", alg->cra_driver_name);
seq_printf(m, "module : %s\n", module_name(alg->cra_module));
seq_printf(m, "priority : %d\n", alg->cra_priority);
seq_printf(m, "refcnt : %d\n", atomic_read(&alg->cra_refcnt));

switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
case CRYPTO_ALG_TYPE_CIPHER:
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef _LINUX_CRYPTO_H
#define _LINUX_CRYPTO_H

#include <asm/atomic.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
Expand Down Expand Up @@ -148,6 +149,7 @@ struct crypto_alg {
unsigned int cra_alignmask;

int cra_priority;
atomic_t cra_refcnt;

char cra_name[CRYPTO_MAX_ALG_NAME];
char cra_driver_name[CRYPTO_MAX_ALG_NAME];
Expand All @@ -160,6 +162,7 @@ struct crypto_alg {

int (*cra_init)(struct crypto_tfm *tfm);
void (*cra_exit)(struct crypto_tfm *tfm);
void (*cra_destroy)(struct crypto_alg *alg);

struct module *cra_module;
};
Expand Down

0 comments on commit 6f66ea7

Please sign in to comment.