33 * Cryptographic API.
44 */
55
6+ #include <crypto/internal/scompress.h>
67#include <linux/init.h>
7- #include <linux/module.h>
8- #include <linux/crypto.h>
9- #include <linux/vmalloc.h>
10- #include <linux/mm.h>
118#include <linux/lzo.h>
12- #include <crypto/internal/scompress.h>
9+ #include <linux/module.h>
10+ #include <linux/slab.h>
1311
1412struct lzo_ctx {
1513 void * lzo_comp_mem ;
@@ -26,29 +24,11 @@ static void *lzo_alloc_ctx(void)
2624 return ctx ;
2725}
2826
29- static int lzo_init (struct crypto_tfm * tfm )
30- {
31- struct lzo_ctx * ctx = crypto_tfm_ctx (tfm );
32-
33- ctx -> lzo_comp_mem = lzo_alloc_ctx ();
34- if (IS_ERR (ctx -> lzo_comp_mem ))
35- return - ENOMEM ;
36-
37- return 0 ;
38- }
39-
4027static void lzo_free_ctx (void * ctx )
4128{
4229 kvfree (ctx );
4330}
4431
45- static void lzo_exit (struct crypto_tfm * tfm )
46- {
47- struct lzo_ctx * ctx = crypto_tfm_ctx (tfm );
48-
49- lzo_free_ctx (ctx -> lzo_comp_mem );
50- }
51-
5232static int __lzo_compress (const u8 * src , unsigned int slen ,
5333 u8 * dst , unsigned int * dlen , void * ctx )
5434{
@@ -64,14 +44,6 @@ static int __lzo_compress(const u8 *src, unsigned int slen,
6444 return 0 ;
6545}
6646
67- static int lzo_compress (struct crypto_tfm * tfm , const u8 * src ,
68- unsigned int slen , u8 * dst , unsigned int * dlen )
69- {
70- struct lzo_ctx * ctx = crypto_tfm_ctx (tfm );
71-
72- return __lzo_compress (src , slen , dst , dlen , ctx -> lzo_comp_mem );
73- }
74-
7547static int lzo_scompress (struct crypto_scomp * tfm , const u8 * src ,
7648 unsigned int slen , u8 * dst , unsigned int * dlen ,
7749 void * ctx )
@@ -94,32 +66,13 @@ static int __lzo_decompress(const u8 *src, unsigned int slen,
9466 return 0 ;
9567}
9668
97- static int lzo_decompress (struct crypto_tfm * tfm , const u8 * src ,
98- unsigned int slen , u8 * dst , unsigned int * dlen )
99- {
100- return __lzo_decompress (src , slen , dst , dlen );
101- }
102-
10369static int lzo_sdecompress (struct crypto_scomp * tfm , const u8 * src ,
10470 unsigned int slen , u8 * dst , unsigned int * dlen ,
10571 void * ctx )
10672{
10773 return __lzo_decompress (src , slen , dst , dlen );
10874}
10975
110- static struct crypto_alg alg = {
111- .cra_name = "lzo" ,
112- .cra_driver_name = "lzo-generic" ,
113- .cra_flags = CRYPTO_ALG_TYPE_COMPRESS ,
114- .cra_ctxsize = sizeof (struct lzo_ctx ),
115- .cra_module = THIS_MODULE ,
116- .cra_init = lzo_init ,
117- .cra_exit = lzo_exit ,
118- .cra_u = { .compress = {
119- .coa_compress = lzo_compress ,
120- .coa_decompress = lzo_decompress } }
121- };
122-
12376static struct scomp_alg scomp = {
12477 .alloc_ctx = lzo_alloc_ctx ,
12578 .free_ctx = lzo_free_ctx ,
@@ -134,24 +87,11 @@ static struct scomp_alg scomp = {
13487
13588static int __init lzo_mod_init (void )
13689{
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 );
15091}
15192
15293static void __exit lzo_mod_fini (void )
15394{
154- crypto_unregister_alg (& alg );
15595 crypto_unregister_scomp (& scomp );
15696}
15797
0 commit comments