Whamcloud - gitweb
LU-2212 crypto: add crc32c module loading to libcfs
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-crypto.c
index bacf26a..2f14540 100644 (file)
@@ -23,6 +23,8 @@
 
 /*
  * Copyright 2012 Xyratex Technology Limited
+ *
+ * Copyright (c) 2012, Intel Corporation.
  */
 
 #include <linux/crypto.h>
@@ -167,7 +169,7 @@ int cfs_crypto_hash_digest(unsigned char alg_id,
                           unsigned char *key, unsigned int key_len,
                           unsigned char *hash, unsigned int *hash_len)
 {
-       struct scatterlist      sl = {0};
+       struct scatterlist      sl;
        struct hash_desc        hdesc;
        int                     err;
        const struct cfs_crypto_hash_type       *type;
@@ -184,7 +186,7 @@ int cfs_crypto_hash_digest(unsigned char alg_id,
                crypto_free_hash(hdesc.tfm);
                return -ENOSPC;
        }
-       sg_set_buf(&sl, (void *)buf, buf_len);
+       sg_init_one(&sl, (void *)buf, buf_len);
 
        hdesc.flags = 0;
        err = crypto_hash_digest(&hdesc, &sl, sl.length, hash);
@@ -221,8 +223,9 @@ int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *hdesc,
                                cfs_page_t *page, unsigned int offset,
                                unsigned int len)
 {
-       struct scatterlist      sl = {0};
+       struct scatterlist sl;
 
+       sg_init_table(&sl, 1);
        sg_set_page(&sl, page, len, offset & ~CFS_PAGE_MASK);
 
        return crypto_hash_update((struct hash_desc *)hdesc, &sl, sl.length);
@@ -232,9 +235,9 @@ EXPORT_SYMBOL(cfs_crypto_hash_update_page);
 int cfs_crypto_hash_update(struct cfs_crypto_hash_desc *hdesc,
                           const void *buf, unsigned int buf_len)
 {
-       struct scatterlist      sl = {0};
+       struct scatterlist sl;
 
-       sg_set_buf(&sl, (void *)buf, buf_len);
+       sg_init_one(&sl, (void *)buf, buf_len);
 
        return crypto_hash_update((struct hash_desc *)hdesc, &sl, sl.length);
 }
@@ -249,6 +252,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 +266,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,20 +344,22 @@ static int cfs_crypto_test_hashes(void)
 
 static int crc32, adler32;
 
-#ifdef CONFIG_X86
+#ifdef HAVE_PCLMULQDQ
 static int crc32pclmul;
 #endif
 
 int cfs_crypto_register(void)
 {
+       cfs_request_module("crc32c");
+
        crc32 = cfs_crypto_crc32_register();
        adler32 = cfs_crypto_adler32_register();
 
-#ifdef CONFIG_X86
+#ifdef HAVE_PCLMULQDQ
        crc32pclmul = cfs_crypto_crc32_pclmul_register();
 #endif
 
-       /* check all algorithms and do perfermance test */
+       /* check all algorithms and do performance test */
        cfs_crypto_test_hashes();
        return 0;
 }
@@ -363,7 +370,7 @@ void cfs_crypto_unregister(void)
        if (adler32 == 0)
                cfs_crypto_adler32_unregister();
 
-#ifdef CONFIG_X86
+#ifdef HAVE_PCLMULQDQ
        if (crc32pclmul == 0)
                cfs_crypto_crc32_pclmul_unregister();
 #endif