Skip to content

Commit b190a58

Browse files
Boris Pismennydavem330
authored andcommitted
tls: Fill software context without allocation
This patch allows tls_set_sw_offload to fill the context in case it was already allocated previously. We will use it in TLS_DEVICE to fill the RX software context. Signed-off-by: Boris Pismenny <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 39f56e1 commit b190a58

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

net/tls/tls_sw.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,28 +1081,38 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
10811081
}
10821082

10831083
if (tx) {
1084-
sw_ctx_tx = kzalloc(sizeof(*sw_ctx_tx), GFP_KERNEL);
1085-
if (!sw_ctx_tx) {
1086-
rc = -ENOMEM;
1087-
goto out;
1084+
if (!ctx->priv_ctx_tx) {
1085+
sw_ctx_tx = kzalloc(sizeof(*sw_ctx_tx), GFP_KERNEL);
1086+
if (!sw_ctx_tx) {
1087+
rc = -ENOMEM;
1088+
goto out;
1089+
}
1090+
ctx->priv_ctx_tx = sw_ctx_tx;
1091+
} else {
1092+
sw_ctx_tx =
1093+
(struct tls_sw_context_tx *)ctx->priv_ctx_tx;
10881094
}
1089-
crypto_init_wait(&sw_ctx_tx->async_wait);
1090-
ctx->priv_ctx_tx = sw_ctx_tx;
10911095
} else {
1092-
sw_ctx_rx = kzalloc(sizeof(*sw_ctx_rx), GFP_KERNEL);
1093-
if (!sw_ctx_rx) {
1094-
rc = -ENOMEM;
1095-
goto out;
1096+
if (!ctx->priv_ctx_rx) {
1097+
sw_ctx_rx = kzalloc(sizeof(*sw_ctx_rx), GFP_KERNEL);
1098+
if (!sw_ctx_rx) {
1099+
rc = -ENOMEM;
1100+
goto out;
1101+
}
1102+
ctx->priv_ctx_rx = sw_ctx_rx;
1103+
} else {
1104+
sw_ctx_rx =
1105+
(struct tls_sw_context_rx *)ctx->priv_ctx_rx;
10961106
}
1097-
crypto_init_wait(&sw_ctx_rx->async_wait);
1098-
ctx->priv_ctx_rx = sw_ctx_rx;
10991107
}
11001108

11011109
if (tx) {
1110+
crypto_init_wait(&sw_ctx_tx->async_wait);
11021111
crypto_info = &ctx->crypto_send;
11031112
cctx = &ctx->tx;
11041113
aead = &sw_ctx_tx->aead_send;
11051114
} else {
1115+
crypto_init_wait(&sw_ctx_rx->async_wait);
11061116
crypto_info = &ctx->crypto_recv;
11071117
cctx = &ctx->rx;
11081118
aead = &sw_ctx_rx->aead_recv;

0 commit comments

Comments
 (0)