Commit ca7040c6 authored by Tadeusz Struk's avatar Tadeusz Struk Committed by Sasha Levin

crypto: qat - Fix invalid synchronization between register/unregister sym algs

[ Upstream commit 7047312d ]

commit 6f043b50 upstream.

The synchronization method used atomic was bogus.
Use a proper synchronization with mutex.
Signed-off-by: default avatarTadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent 25920396
......@@ -73,7 +73,8 @@
ICP_QAT_HW_CIPHER_KEY_CONVERT, \
ICP_QAT_HW_CIPHER_DECRYPT)
static atomic_t active_dev;
static DEFINE_MUTEX(algs_lock);
static unsigned int active_devs;
struct qat_alg_buf {
uint32_t len;
......@@ -955,27 +956,34 @@ static struct crypto_alg qat_algs[] = { {
int qat_algs_register(void)
{
if (atomic_add_return(1, &active_dev) == 1) {
int ret = 0;
mutex_lock(&algs_lock);
if (++active_devs == 1) {
int i;
for (i = 0; i < ARRAY_SIZE(qat_algs); i++)
qat_algs[i].cra_flags = CRYPTO_ALG_TYPE_AEAD |
CRYPTO_ALG_ASYNC;
return crypto_register_algs(qat_algs, ARRAY_SIZE(qat_algs));
ret = crypto_register_algs(qat_algs, ARRAY_SIZE(qat_algs));
}
return 0;
mutex_unlock(&algs_lock);
return ret;
}
int qat_algs_unregister(void)
{
if (atomic_sub_return(1, &active_dev) == 0)
return crypto_unregister_algs(qat_algs, ARRAY_SIZE(qat_algs));
return 0;
int ret = 0;
mutex_lock(&algs_lock);
if (--active_devs == 0)
ret = crypto_unregister_algs(qat_algs, ARRAY_SIZE(qat_algs));
mutex_unlock(&algs_lock);
return ret;
}
int qat_algs_init(void)
{
atomic_set(&active_dev, 0);
crypto_get_default_rng();
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment