Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-drm-fsl-dcu.git] / arch / s390 / crypto / aes_s390.c
index 2e4b5be31a1bbc2c0dc9b0b3bcb6df91b19d497f..4363528dc8fd013492b2165f6978b5e5226657b1 100644 (file)
@@ -730,6 +730,8 @@ static struct crypto_alg xts_aes_alg = {
        }
 };
 
+static int xts_aes_alg_reg;
+
 static int ctr_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
                           unsigned int key_len)
 {
@@ -851,6 +853,8 @@ static struct crypto_alg ctr_aes_alg = {
        }
 };
 
+static int ctr_aes_alg_reg;
+
 static int __init aes_s390_init(void)
 {
        int ret;
@@ -889,6 +893,7 @@ static int __init aes_s390_init(void)
                ret = crypto_register_alg(&xts_aes_alg);
                if (ret)
                        goto xts_aes_err;
+               xts_aes_alg_reg = 1;
        }
 
        if (crypt_s390_func_available(KMCTR_AES_128_ENCRYPT,
@@ -907,6 +912,7 @@ static int __init aes_s390_init(void)
                        free_page((unsigned long) ctrblk);
                        goto ctr_aes_err;
                }
+               ctr_aes_alg_reg = 1;
        }
 
 out:
@@ -926,9 +932,12 @@ aes_err:
 
 static void __exit aes_s390_fini(void)
 {
-       crypto_unregister_alg(&ctr_aes_alg);
-       free_page((unsigned long) ctrblk);
-       crypto_unregister_alg(&xts_aes_alg);
+       if (ctr_aes_alg_reg) {
+               crypto_unregister_alg(&ctr_aes_alg);
+               free_page((unsigned long) ctrblk);
+       }
+       if (xts_aes_alg_reg)
+               crypto_unregister_alg(&xts_aes_alg);
        crypto_unregister_alg(&cbc_aes_alg);
        crypto_unregister_alg(&ecb_aes_alg);
        crypto_unregister_alg(&aes_alg);