44 *
55 * Copyright (c) 2013 Chanho Min <chanho.min@lge.com>
66 */
7+ #include <crypto/internal/scompress.h>
78#include <linux/init.h>
89#include <linux/module.h>
9- #include <linux/crypto.h>
1010#include <linux/vmalloc.h>
1111#include <linux/lz4.h>
12- #include <crypto/internal/scompress.h>
1312
1413struct lz4hc_ctx {
1514 void * lz4hc_comp_mem ;
@@ -26,29 +25,11 @@ static void *lz4hc_alloc_ctx(void)
2625 return ctx ;
2726}
2827
29- static int lz4hc_init (struct crypto_tfm * tfm )
30- {
31- struct lz4hc_ctx * ctx = crypto_tfm_ctx (tfm );
32-
33- ctx -> lz4hc_comp_mem = lz4hc_alloc_ctx ();
34- if (IS_ERR (ctx -> lz4hc_comp_mem ))
35- return - ENOMEM ;
36-
37- return 0 ;
38- }
39-
4028static void lz4hc_free_ctx (void * ctx )
4129{
4230 vfree (ctx );
4331}
4432
45- static void lz4hc_exit (struct crypto_tfm * tfm )
46- {
47- struct lz4hc_ctx * ctx = crypto_tfm_ctx (tfm );
48-
49- lz4hc_free_ctx (ctx -> lz4hc_comp_mem );
50- }
51-
5233static int __lz4hc_compress_crypto (const u8 * src , unsigned int slen ,
5334 u8 * dst , unsigned int * dlen , void * ctx )
5435{
@@ -69,16 +50,6 @@ static int lz4hc_scompress(struct crypto_scomp *tfm, const u8 *src,
6950 return __lz4hc_compress_crypto (src , slen , dst , dlen , ctx );
7051}
7152
72- static int lz4hc_compress_crypto (struct crypto_tfm * tfm , const u8 * src ,
73- unsigned int slen , u8 * dst ,
74- unsigned int * dlen )
75- {
76- struct lz4hc_ctx * ctx = crypto_tfm_ctx (tfm );
77-
78- return __lz4hc_compress_crypto (src , slen , dst , dlen ,
79- ctx -> lz4hc_comp_mem );
80- }
81-
8253static int __lz4hc_decompress_crypto (const u8 * src , unsigned int slen ,
8354 u8 * dst , unsigned int * dlen , void * ctx )
8455{
@@ -98,26 +69,6 @@ static int lz4hc_sdecompress(struct crypto_scomp *tfm, const u8 *src,
9869 return __lz4hc_decompress_crypto (src , slen , dst , dlen , NULL );
9970}
10071
101- static int lz4hc_decompress_crypto (struct crypto_tfm * tfm , const u8 * src ,
102- unsigned int slen , u8 * dst ,
103- unsigned int * dlen )
104- {
105- return __lz4hc_decompress_crypto (src , slen , dst , dlen , NULL );
106- }
107-
108- static struct crypto_alg alg_lz4hc = {
109- .cra_name = "lz4hc" ,
110- .cra_driver_name = "lz4hc-generic" ,
111- .cra_flags = CRYPTO_ALG_TYPE_COMPRESS ,
112- .cra_ctxsize = sizeof (struct lz4hc_ctx ),
113- .cra_module = THIS_MODULE ,
114- .cra_init = lz4hc_init ,
115- .cra_exit = lz4hc_exit ,
116- .cra_u = { .compress = {
117- .coa_compress = lz4hc_compress_crypto ,
118- .coa_decompress = lz4hc_decompress_crypto } }
119- };
120-
12172static struct scomp_alg scomp = {
12273 .alloc_ctx = lz4hc_alloc_ctx ,
12374 .free_ctx = lz4hc_free_ctx ,
@@ -132,24 +83,11 @@ static struct scomp_alg scomp = {
13283
13384static int __init lz4hc_mod_init (void )
13485{
135- int ret ;
136-
137- ret = crypto_register_alg (& alg_lz4hc );
138- if (ret )
139- return ret ;
140-
141- ret = crypto_register_scomp (& scomp );
142- if (ret ) {
143- crypto_unregister_alg (& alg_lz4hc );
144- return ret ;
145- }
146-
147- return ret ;
86+ return crypto_register_scomp (& scomp );
14887}
14988
15089static void __exit lz4hc_mod_fini (void )
15190{
152- crypto_unregister_alg (& alg_lz4hc );
15391 crypto_unregister_scomp (& scomp );
15492}
15593
0 commit comments