@@ -190,55 +190,12 @@ static inline unsigned int ahash_align_buffer_size(unsigned len,
190
190
return len + (mask & ~(crypto_tfm_ctx_alignment () - 1 ));
191
191
}
192
192
193
- static void ahash_op_unaligned_finish (struct ahash_request * req , int err )
194
- {
195
- struct ahash_request_priv * priv = req -> priv ;
196
-
197
- if (err == - EINPROGRESS )
198
- return ;
199
-
200
- if (!err )
201
- memcpy (priv -> result , req -> result ,
202
- crypto_ahash_digestsize (crypto_ahash_reqtfm (req )));
203
-
204
- /* Restore the original crypto request. */
205
- req -> result = priv -> result ;
206
- req -> base .complete = priv -> complete ;
207
- req -> base .data = priv -> data ;
208
- req -> priv = NULL ;
209
-
210
- /* Free the req->priv.priv from the ADJUSTED request. */
211
- kzfree (priv );
212
- }
213
-
214
- static void ahash_op_unaligned_done (struct crypto_async_request * req , int err )
215
- {
216
- struct ahash_request * areq = req -> data ;
217
-
218
- /*
219
- * Restore the original request, see ahash_op_unaligned() for what
220
- * goes where.
221
- *
222
- * The "struct ahash_request *req" here is in fact the "req.base"
223
- * from the ADJUSTED request from ahash_op_unaligned(), thus as it
224
- * is a pointer to self, it is also the ADJUSTED "req" .
225
- */
226
-
227
- /* First copy areq->result into areq->priv.result */
228
- ahash_op_unaligned_finish (areq , err );
229
-
230
- /* Complete the ORIGINAL request. */
231
- areq -> base .complete (& areq -> base , err );
232
- }
233
-
234
- static int ahash_op_unaligned (struct ahash_request * req ,
235
- int (* op )(struct ahash_request * ))
193
+ static int ahash_save_req (struct ahash_request * req , crypto_completion_t cplt )
236
194
{
237
195
struct crypto_ahash * tfm = crypto_ahash_reqtfm (req );
238
196
unsigned long alignmask = crypto_ahash_alignmask (tfm );
239
197
unsigned int ds = crypto_ahash_digestsize (tfm );
240
198
struct ahash_request_priv * priv ;
241
- int err ;
242
199
243
200
priv = kmalloc (sizeof (* priv ) + ahash_align_buffer_size (ds , alignmask ),
244
201
(req -> base .flags & CRYPTO_TFM_REQ_MAY_SLEEP ) ?
@@ -281,10 +238,70 @@ static int ahash_op_unaligned(struct ahash_request *req,
281
238
*/
282
239
283
240
req -> result = PTR_ALIGN ((u8 * )priv -> ubuf , alignmask + 1 );
284
- req -> base .complete = ahash_op_unaligned_done ;
241
+ req -> base .complete = cplt ;
285
242
req -> base .data = req ;
286
243
req -> priv = priv ;
287
244
245
+ return 0 ;
246
+ }
247
+
248
+ static void ahash_restore_req (struct ahash_request * req )
249
+ {
250
+ struct ahash_request_priv * priv = req -> priv ;
251
+
252
+ /* Restore the original crypto request. */
253
+ req -> result = priv -> result ;
254
+ req -> base .complete = priv -> complete ;
255
+ req -> base .data = priv -> data ;
256
+ req -> priv = NULL ;
257
+
258
+ /* Free the req->priv.priv from the ADJUSTED request. */
259
+ kzfree (priv );
260
+ }
261
+
262
+ static void ahash_op_unaligned_finish (struct ahash_request * req , int err )
263
+ {
264
+ struct ahash_request_priv * priv = req -> priv ;
265
+
266
+ if (err == - EINPROGRESS )
267
+ return ;
268
+
269
+ if (!err )
270
+ memcpy (priv -> result , req -> result ,
271
+ crypto_ahash_digestsize (crypto_ahash_reqtfm (req )));
272
+
273
+ ahash_restore_req (req );
274
+ }
275
+
276
+ static void ahash_op_unaligned_done (struct crypto_async_request * req , int err )
277
+ {
278
+ struct ahash_request * areq = req -> data ;
279
+
280
+ /*
281
+ * Restore the original request, see ahash_op_unaligned() for what
282
+ * goes where.
283
+ *
284
+ * The "struct ahash_request *req" here is in fact the "req.base"
285
+ * from the ADJUSTED request from ahash_op_unaligned(), thus as it
286
+ * is a pointer to self, it is also the ADJUSTED "req" .
287
+ */
288
+
289
+ /* First copy req->result into req->priv.result */
290
+ ahash_op_unaligned_finish (areq , err );
291
+
292
+ /* Complete the ORIGINAL request. */
293
+ areq -> base .complete (& areq -> base , err );
294
+ }
295
+
296
+ static int ahash_op_unaligned (struct ahash_request * req ,
297
+ int (* op )(struct ahash_request * ))
298
+ {
299
+ int err ;
300
+
301
+ err = ahash_save_req (req , ahash_op_unaligned_done );
302
+ if (err )
303
+ return err ;
304
+
288
305
err = op (req );
289
306
ahash_op_unaligned_finish (req , err );
290
307
0 commit comments