Skip to content

Commit a108dfc

Browse files
ebiggersherbertx
authored andcommitted
crypto: ctr - simplify error handling in crypto_rfc3686_create()
Simplify the error handling in crypto_rfc3686_create() by taking advantage of crypto_grab_skcipher() now handling an ERR_PTR() name and by taking advantage of crypto_drop_skcipher() now accepting (as a no-op) a spawn that hasn't been grabbed yet. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent b8c0d74 commit a108dfc

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

‎crypto/ctr.c‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
260260
struct skcipher_instance *inst;
261261
struct skcipher_alg *alg;
262262
struct crypto_skcipher_spawn *spawn;
263-
const char *cipher_name;
264263
u32 mask;
265264

266265
int err;
@@ -272,10 +271,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
272271
if ((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask)
273272
return -EINVAL;
274273

275-
cipher_name = crypto_attr_alg_name(tb[1]);
276-
if (IS_ERR(cipher_name))
277-
return PTR_ERR(cipher_name);
278-
279274
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
280275
if (!inst)
281276
return -ENOMEM;
@@ -287,7 +282,7 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
287282
spawn = skcipher_instance_ctx(inst);
288283

289284
err = crypto_grab_skcipher(spawn, skcipher_crypto_instance(inst),
290-
cipher_name, 0, mask);
285+
crypto_attr_alg_name(tb[1]), 0, mask);
291286
if (err)
292287
goto err_free_inst;
293288

@@ -296,20 +291,20 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
296291
/* We only support 16-byte blocks. */
297292
err = -EINVAL;
298293
if (crypto_skcipher_alg_ivsize(alg) != CTR_RFC3686_BLOCK_SIZE)
299-
goto err_drop_spawn;
294+
goto err_free_inst;
300295

301296
/* Not a stream cipher? */
302297
if (alg->base.cra_blocksize != 1)
303-
goto err_drop_spawn;
298+
goto err_free_inst;
304299

305300
err = -ENAMETOOLONG;
306301
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
307302
"rfc3686(%s)", alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME)
308-
goto err_drop_spawn;
303+
goto err_free_inst;
309304
if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
310305
"rfc3686(%s)", alg->base.cra_driver_name) >=
311306
CRYPTO_MAX_ALG_NAME)
312-
goto err_drop_spawn;
307+
goto err_free_inst;
313308

314309
inst->alg.base.cra_priority = alg->base.cra_priority;
315310
inst->alg.base.cra_blocksize = 1;
@@ -336,17 +331,11 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
336331
inst->free = crypto_rfc3686_free;
337332

338333
err = skcipher_register_instance(tmpl, inst);
339-
if (err)
340-
goto err_drop_spawn;
341-
342-
out:
343-
return err;
344-
345-
err_drop_spawn:
346-
crypto_drop_skcipher(spawn);
334+
if (err) {
347335
err_free_inst:
348-
kfree(inst);
349-
goto out;
336+
crypto_rfc3686_free(inst);
337+
}
338+
return err;
350339
}
351340

352341
static struct crypto_template crypto_ctr_tmpls[] = {

0 commit comments

Comments
 (0)