Whamcloud - gitweb
LU-2053 crypto: Fix cfs_crypto_hash memleak
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-crypto.c
index a15938a..002b241 100644 (file)
@@ -151,8 +151,8 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
        }
 
        CDEBUG(D_INFO, "Using crypto hash: %s (%s) speed %d MB/s\n",
-              crypto_tfm_alg_name(crypto_hash_tfm(desc->tfm)),
-              crypto_tfm_alg_driver_name(crypto_hash_tfm(desc->tfm)),
+              (crypto_hash_tfm(desc->tfm))->__crt_alg->cra_name,
+              (crypto_hash_tfm(desc->tfm))->__crt_alg->cra_driver_name,
               cfs_crypto_hash_speeds[alg_id]);
 
 #ifdef HAVE_STRUCT_SHASH_ALG
@@ -249,6 +249,7 @@ int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *hdesc,
 
        if (hash_len == NULL) {
                crypto_free_hash(((struct hash_desc *)hdesc)->tfm);
+               cfs_free(hdesc);
                return 0;
        }
        if (hash == NULL || *hash_len < size) {
@@ -262,6 +263,7 @@ int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *hdesc,
                return err;
        }
        crypto_free_hash(((struct hash_desc *)hdesc)->tfm);
+       cfs_free(hdesc);
        return err;
 }
 EXPORT_SYMBOL(cfs_crypto_hash_final);
@@ -339,11 +341,19 @@ static int cfs_crypto_test_hashes(void)
 
 static int crc32, adler32;
 
+#ifdef CONFIG_X86
+static int crc32pclmul;
+#endif
+
 int cfs_crypto_register(void)
 {
        crc32 = cfs_crypto_crc32_register();
        adler32 = cfs_crypto_adler32_register();
 
+#ifdef CONFIG_X86
+       crc32pclmul = cfs_crypto_crc32_pclmul_register();
+#endif
+
        /* check all algorithms and do perfermance test */
        cfs_crypto_test_hashes();
        return 0;
@@ -354,5 +364,11 @@ void cfs_crypto_unregister(void)
                cfs_crypto_crc32_unregister();
        if (adler32 == 0)
                cfs_crypto_adler32_unregister();
+
+#ifdef CONFIG_X86
+       if (crc32pclmul == 0)
+               cfs_crypto_crc32_pclmul_unregister();
+#endif
+
        return;
 }