4
4
*
5
5
* Copyright (c) 2013 Chanho Min <[email protected] >
6
6
*/
7
+ #include <crypto/internal/scompress.h>
7
8
#include <linux/init.h>
8
9
#include <linux/module.h>
9
- #include <linux/crypto.h>
10
10
#include <linux/vmalloc.h>
11
11
#include <linux/lz4.h>
12
- #include <crypto/internal/scompress.h>
13
12
14
13
struct lz4hc_ctx {
15
14
void * lz4hc_comp_mem ;
@@ -26,29 +25,11 @@ static void *lz4hc_alloc_ctx(void)
26
25
return ctx ;
27
26
}
28
27
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
-
40
28
static void lz4hc_free_ctx (void * ctx )
41
29
{
42
30
vfree (ctx );
43
31
}
44
32
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
-
52
33
static int __lz4hc_compress_crypto (const u8 * src , unsigned int slen ,
53
34
u8 * dst , unsigned int * dlen , void * ctx )
54
35
{
@@ -69,16 +50,6 @@ static int lz4hc_scompress(struct crypto_scomp *tfm, const u8 *src,
69
50
return __lz4hc_compress_crypto (src , slen , dst , dlen , ctx );
70
51
}
71
52
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
-
82
53
static int __lz4hc_decompress_crypto (const u8 * src , unsigned int slen ,
83
54
u8 * dst , unsigned int * dlen , void * ctx )
84
55
{
@@ -98,26 +69,6 @@ static int lz4hc_sdecompress(struct crypto_scomp *tfm, const u8 *src,
98
69
return __lz4hc_decompress_crypto (src , slen , dst , dlen , NULL );
99
70
}
100
71
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
-
121
72
static struct scomp_alg scomp = {
122
73
.alloc_ctx = lz4hc_alloc_ctx ,
123
74
.free_ctx = lz4hc_free_ctx ,
@@ -132,24 +83,11 @@ static struct scomp_alg scomp = {
132
83
133
84
static int __init lz4hc_mod_init (void )
134
85
{
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 );
148
87
}
149
88
150
89
static void __exit lz4hc_mod_fini (void )
151
90
{
152
- crypto_unregister_alg (& alg_lz4hc );
153
91
crypto_unregister_scomp (& scomp );
154
92
}
155
93
0 commit comments