Skip to content

Commit 9a83055

Browse files
committed
crypto: atmel-tdes: Clarify how tdes dev gets allocated to the tfm
The tdes dev gets allocated to the tfm at alg->init time, there's no need to overwrite the pointer to tdes_dd afterwards. There's a single IP per SoC anyway, the first entry from the atmel_tdes.dev_list is chosen without counting for tfms for example, in case one thinks of an even distribution of tfms across the TDES IPs: there's only one. At alg->init time the ctx->dd should already be NULL, there's no need to check its value before requesting for a tdes dev. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
1 parent a1c9297 commit 9a83055

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

drivers/crypto/atmel-tdes.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,14 @@ static void atmel_tdes_write_n(struct atmel_tdes_dev *dd, u32 offset,
196196
atmel_tdes_write(dd, offset, *value);
197197
}
198198

199-
static struct atmel_tdes_dev *atmel_tdes_find_dev(struct atmel_tdes_ctx *ctx)
199+
static struct atmel_tdes_dev *atmel_tdes_dev_alloc(void)
200200
{
201-
struct atmel_tdes_dev *tdes_dd = NULL;
202-
struct atmel_tdes_dev *tmp;
201+
struct atmel_tdes_dev *tmp, *tdes_dd = NULL;
203202

204203
spin_lock_bh(&atmel_tdes.lock);
205-
if (!ctx->dd) {
206-
list_for_each_entry(tmp, &atmel_tdes.dev_list, list) {
207-
tdes_dd = tmp;
208-
break;
209-
}
210-
ctx->dd = tdes_dd;
211-
} else {
212-
tdes_dd = ctx->dd;
204+
list_for_each_entry(tmp, &atmel_tdes.dev_list, list) {
205+
tdes_dd = tmp;
206+
break;
213207
}
214208
spin_unlock_bh(&atmel_tdes.lock);
215209

@@ -646,7 +640,6 @@ static int atmel_tdes_handle_queue(struct atmel_tdes_dev *dd,
646640
rctx->mode &= TDES_FLAGS_MODE_MASK;
647641
dd->flags = (dd->flags & ~TDES_FLAGS_MODE_MASK) | rctx->mode;
648642
dd->ctx = ctx;
649-
ctx->dd = dd;
650643

651644
err = atmel_tdes_write_ctrl(dd);
652645
if (!err)
@@ -897,14 +890,13 @@ static int atmel_tdes_ofb_decrypt(struct skcipher_request *req)
897890
static int atmel_tdes_init_tfm(struct crypto_skcipher *tfm)
898891
{
899892
struct atmel_tdes_ctx *ctx = crypto_skcipher_ctx(tfm);
900-
struct atmel_tdes_dev *dd;
901893

902-
crypto_skcipher_set_reqsize(tfm, sizeof(struct atmel_tdes_reqctx));
903-
904-
dd = atmel_tdes_find_dev(ctx);
905-
if (!dd)
894+
ctx->dd = atmel_tdes_dev_alloc();
895+
if (!ctx->dd)
906896
return -ENODEV;
907897

898+
crypto_skcipher_set_reqsize(tfm, sizeof(struct atmel_tdes_reqctx));
899+
908900
return 0;
909901
}
910902

0 commit comments

Comments
 (0)