3
3
* Cryptographic API.
4
4
*/
5
5
6
+ #include <crypto/internal/scompress.h>
6
7
#include <linux/init.h>
7
- #include <linux/module.h>
8
- #include <linux/crypto.h>
9
- #include <linux/vmalloc.h>
10
- #include <linux/mm.h>
11
8
#include <linux/lzo.h>
12
- #include <crypto/internal/scompress.h>
9
+ #include <linux/module.h>
10
+ #include <linux/slab.h>
13
11
14
12
struct lzorle_ctx {
15
13
void * lzorle_comp_mem ;
@@ -26,29 +24,11 @@ static void *lzorle_alloc_ctx(void)
26
24
return ctx ;
27
25
}
28
26
29
- static int lzorle_init (struct crypto_tfm * tfm )
30
- {
31
- struct lzorle_ctx * ctx = crypto_tfm_ctx (tfm );
32
-
33
- ctx -> lzorle_comp_mem = lzorle_alloc_ctx ();
34
- if (IS_ERR (ctx -> lzorle_comp_mem ))
35
- return - ENOMEM ;
36
-
37
- return 0 ;
38
- }
39
-
40
27
static void lzorle_free_ctx (void * ctx )
41
28
{
42
29
kvfree (ctx );
43
30
}
44
31
45
- static void lzorle_exit (struct crypto_tfm * tfm )
46
- {
47
- struct lzorle_ctx * ctx = crypto_tfm_ctx (tfm );
48
-
49
- lzorle_free_ctx (ctx -> lzorle_comp_mem );
50
- }
51
-
52
32
static int __lzorle_compress (const u8 * src , unsigned int slen ,
53
33
u8 * dst , unsigned int * dlen , void * ctx )
54
34
{
@@ -64,14 +44,6 @@ static int __lzorle_compress(const u8 *src, unsigned int slen,
64
44
return 0 ;
65
45
}
66
46
67
- static int lzorle_compress (struct crypto_tfm * tfm , const u8 * src ,
68
- unsigned int slen , u8 * dst , unsigned int * dlen )
69
- {
70
- struct lzorle_ctx * ctx = crypto_tfm_ctx (tfm );
71
-
72
- return __lzorle_compress (src , slen , dst , dlen , ctx -> lzorle_comp_mem );
73
- }
74
-
75
47
static int lzorle_scompress (struct crypto_scomp * tfm , const u8 * src ,
76
48
unsigned int slen , u8 * dst , unsigned int * dlen ,
77
49
void * ctx )
@@ -94,32 +66,13 @@ static int __lzorle_decompress(const u8 *src, unsigned int slen,
94
66
return 0 ;
95
67
}
96
68
97
- static int lzorle_decompress (struct crypto_tfm * tfm , const u8 * src ,
98
- unsigned int slen , u8 * dst , unsigned int * dlen )
99
- {
100
- return __lzorle_decompress (src , slen , dst , dlen );
101
- }
102
-
103
69
static int lzorle_sdecompress (struct crypto_scomp * tfm , const u8 * src ,
104
70
unsigned int slen , u8 * dst , unsigned int * dlen ,
105
71
void * ctx )
106
72
{
107
73
return __lzorle_decompress (src , slen , dst , dlen );
108
74
}
109
75
110
- static struct crypto_alg alg = {
111
- .cra_name = "lzo-rle" ,
112
- .cra_driver_name = "lzo-rle-generic" ,
113
- .cra_flags = CRYPTO_ALG_TYPE_COMPRESS ,
114
- .cra_ctxsize = sizeof (struct lzorle_ctx ),
115
- .cra_module = THIS_MODULE ,
116
- .cra_init = lzorle_init ,
117
- .cra_exit = lzorle_exit ,
118
- .cra_u = { .compress = {
119
- .coa_compress = lzorle_compress ,
120
- .coa_decompress = lzorle_decompress } }
121
- };
122
-
123
76
static struct scomp_alg scomp = {
124
77
.alloc_ctx = lzorle_alloc_ctx ,
125
78
.free_ctx = lzorle_free_ctx ,
@@ -134,24 +87,11 @@ static struct scomp_alg scomp = {
134
87
135
88
static int __init lzorle_mod_init (void )
136
89
{
137
- int ret ;
138
-
139
- ret = crypto_register_alg (& alg );
140
- if (ret )
141
- return ret ;
142
-
143
- ret = crypto_register_scomp (& scomp );
144
- if (ret ) {
145
- crypto_unregister_alg (& alg );
146
- return ret ;
147
- }
148
-
149
- return ret ;
90
+ return crypto_register_scomp (& scomp );
150
91
}
151
92
152
93
static void __exit lzorle_mod_fini (void )
153
94
{
154
- crypto_unregister_alg (& alg );
155
95
crypto_unregister_scomp (& scomp );
156
96
}
157
97
0 commit comments