@@ -137,7 +137,6 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
137
137
skcipher_alg .base );
138
138
struct device * dev = drvdata_to_dev (cc_alg -> drvdata );
139
139
unsigned int max_key_buf_size = cc_alg -> skcipher_alg .max_keysize ;
140
- int rc = 0 ;
141
140
142
141
dev_dbg (dev , "Initializing context @%p for %s\n" , ctx_p ,
143
142
crypto_tfm_alg_name (tfm ));
@@ -149,10 +148,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
149
148
ctx_p -> flow_mode = cc_alg -> flow_mode ;
150
149
ctx_p -> drvdata = cc_alg -> drvdata ;
151
150
151
+ if (ctx_p -> cipher_mode == DRV_CIPHER_ESSIV ) {
152
+ /* Alloc hash tfm for essiv */
153
+ ctx_p -> shash_tfm = crypto_alloc_shash ("sha256-generic" , 0 , 0 );
154
+ if (IS_ERR (ctx_p -> shash_tfm )) {
155
+ dev_err (dev , "Error allocating hash tfm for ESSIV.\n" );
156
+ return PTR_ERR (ctx_p -> shash_tfm );
157
+ }
158
+ }
159
+
152
160
/* Allocate key buffer, cache line aligned */
153
161
ctx_p -> user .key = kmalloc (max_key_buf_size , GFP_KERNEL );
154
162
if (!ctx_p -> user .key )
155
- return - ENOMEM ;
163
+ goto free_shash ;
156
164
157
165
dev_dbg (dev , "Allocated key buffer in context. key=@%p\n" ,
158
166
ctx_p -> user .key );
@@ -164,21 +172,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
164
172
if (dma_mapping_error (dev , ctx_p -> user .key_dma_addr )) {
165
173
dev_err (dev , "Mapping Key %u B at va=%pK for DMA failed\n" ,
166
174
max_key_buf_size , ctx_p -> user .key );
167
- return - ENOMEM ;
175
+ goto free_key ;
168
176
}
169
177
dev_dbg (dev , "Mapped key %u B at va=%pK to dma=%pad\n" ,
170
178
max_key_buf_size , ctx_p -> user .key , & ctx_p -> user .key_dma_addr );
171
179
172
- if (ctx_p -> cipher_mode == DRV_CIPHER_ESSIV ) {
173
- /* Alloc hash tfm for essiv */
174
- ctx_p -> shash_tfm = crypto_alloc_shash ("sha256-generic" , 0 , 0 );
175
- if (IS_ERR (ctx_p -> shash_tfm )) {
176
- dev_err (dev , "Error allocating hash tfm for ESSIV.\n" );
177
- return PTR_ERR (ctx_p -> shash_tfm );
178
- }
179
- }
180
+ return 0 ;
180
181
181
- return rc ;
182
+ free_key :
183
+ kfree (ctx_p -> user .key );
184
+ free_shash :
185
+ crypto_free_shash (ctx_p -> shash_tfm );
186
+
187
+ return - ENOMEM ;
182
188
}
183
189
184
190
static void cc_cipher_exit (struct crypto_tfm * tfm )
0 commit comments