Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH v2] crypto: qat - Don't attempt to register algorithm multiple times
@ 2015-07-22  5:07 Tadeusz Struk
  2015-07-23 10:19 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Tadeusz Struk @ 2015-07-22  5:07 UTC (permalink / raw)
  To: herbert; +Cc: qat-linux, tadeusz.struk, davem, linux-crypto

When multiple devices are present in the system the driver attempts
to register the same algorithm many times.

Changes in v2:
 - use proper synchronization mechanizm between register and unregister

Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
---
 drivers/crypto/qat/qat_common/qat_asym_algs.c |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto/qat/qat_common/qat_asym_algs.c
index 13a76a0..d06c7d2 100644
--- a/drivers/crypto/qat/qat_common/qat_asym_algs.c
+++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c
@@ -58,6 +58,9 @@
 #include "adf_common_drv.h"
 #include "qat_crypto.h"
 
+static DEFINE_MUTEX(algs_lock);
+static unsigned int active_devs;
+
 struct qat_rsa_input_params {
 	union {
 		struct {
@@ -629,11 +632,21 @@ static struct akcipher_alg rsa = {
 
 int qat_asym_algs_register(void)
 {
-	rsa.base.cra_flags = 0;
-	return crypto_register_akcipher(&rsa);
+	int ret = 0;
+
+	mutex_lock(&algs_lock);
+	if (++active_devs == 1) {
+		rsa.base.cra_flags = 0;
+		ret = crypto_register_akcipher(&rsa);
+	}
+	mutex_unlock(&algs_lock);
+	return ret;
 }
 
 void qat_asym_algs_unregister(void)
 {
-	crypto_unregister_akcipher(&rsa);
+	mutex_lock(&algs_lock);
+	if (--active_devs == 0)
+		crypto_unregister_akcipher(&rsa);
+	mutex_unlock(&algs_lock);
 }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] crypto: qat - Don't attempt to register algorithm multiple times
  2015-07-22  5:07 [PATCH v2] crypto: qat - Don't attempt to register algorithm multiple times Tadeusz Struk
@ 2015-07-23 10:19 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2015-07-23 10:19 UTC (permalink / raw)
  To: Tadeusz Struk; +Cc: qat-linux, davem, linux-crypto

On Tue, Jul 21, 2015 at 10:07:47PM -0700, Tadeusz Struk wrote:
> When multiple devices are present in the system the driver attempts
> to register the same algorithm many times.
> 
> Changes in v2:
>  - use proper synchronization mechanizm between register and unregister
> 
> Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>

Applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-23 10:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-22  5:07 [PATCH v2] crypto: qat - Don't attempt to register algorithm multiple times Tadeusz Struk
2015-07-23 10:19 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox