Skip to content

Commit

Permalink
crypto: pcrypt - Make tfm_count an atomic_t
Browse files Browse the repository at this point in the history
The variable tfm_count is accessed by multiple threads without
locking.  This patch converts it to an atomic_t.

Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed May 25, 2015
1 parent 30e4c01 commit a5a22e5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crypto/pcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <crypto/algapi.h>
#include <crypto/internal/aead.h>
#include <linux/atomic.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/module.h>
Expand Down Expand Up @@ -61,7 +62,7 @@ static struct kset *pcrypt_kset;

struct pcrypt_instance_ctx {
struct crypto_aead_spawn spawn;
unsigned int tfm_count;
atomic_t tfm_count;
};

struct pcrypt_aead_ctx {
Expand Down Expand Up @@ -278,9 +279,8 @@ static int pcrypt_aead_init_tfm(struct crypto_tfm *tfm)
struct pcrypt_aead_ctx *ctx = crypto_tfm_ctx(tfm);
struct crypto_aead *cipher;

ictx->tfm_count++;

cpu_index = ictx->tfm_count % cpumask_weight(cpu_online_mask);
cpu_index = (unsigned int)atomic_inc_return(&ictx->tfm_count) %
cpumask_weight(cpu_online_mask);

ctx->cb_cpu = cpumask_first(cpu_online_mask);
for (cpu = 0; cpu < cpu_index; cpu++)
Expand Down

0 comments on commit a5a22e5

Please sign in to comment.