Skip to content

Commit 6be051c

Browse files
ebiggersherbertx
authored andcommitted
net/tls: use the new scatterwalk functions
Replace calls to the deprecated function scatterwalk_copychunks() with memcpy_from_scatterwalk(), memcpy_to_scatterwalk(), or scatterwalk_skip() as appropriate. The new functions generally behave more as expected and eliminate the need to call scatterwalk_done() or scatterwalk_pagedone(). However, the new functions intentionally do not advance to the next sg entry right away, which would have broken chain_to_walk() which is accessing the fields of struct scatter_walk directly. To avoid this, replace chain_to_walk() with scatterwalk_get_sglist() which supports the needed functionality. Cc: Boris Pismenny <borisp@nvidia.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent fd7cbef commit 6be051c

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

net/tls/tls_device_fallback.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@
3737

3838
#include "tls.h"
3939

40-
static void chain_to_walk(struct scatterlist *sg, struct scatter_walk *walk)
41-
{
42-
struct scatterlist *src = walk->sg;
43-
int diff = walk->offset - src->offset;
44-
45-
sg_set_page(sg, sg_page(src),
46-
src->length - diff, walk->offset);
47-
48-
scatterwalk_crypto_chain(sg, sg_next(src), 2);
49-
}
50-
5140
static int tls_enc_record(struct aead_request *aead_req,
5241
struct crypto_aead *aead, char *aad,
5342
char *iv, __be64 rcd_sn,
@@ -69,16 +58,13 @@ static int tls_enc_record(struct aead_request *aead_req,
6958
buf_size = TLS_HEADER_SIZE + cipher_desc->iv;
7059
len = min_t(int, *in_len, buf_size);
7160

72-
scatterwalk_copychunks(buf, in, len, 0);
73-
scatterwalk_copychunks(buf, out, len, 1);
61+
memcpy_from_scatterwalk(buf, in, len);
62+
memcpy_to_scatterwalk(out, buf, len);
7463

7564
*in_len -= len;
7665
if (!*in_len)
7766
return 0;
7867

79-
scatterwalk_pagedone(in, 0, 1);
80-
scatterwalk_pagedone(out, 1, 1);
81-
8268
len = buf[4] | (buf[3] << 8);
8369
len -= cipher_desc->iv;
8470

@@ -90,8 +76,8 @@ static int tls_enc_record(struct aead_request *aead_req,
9076
sg_init_table(sg_out, ARRAY_SIZE(sg_out));
9177
sg_set_buf(sg_in, aad, TLS_AAD_SPACE_SIZE);
9278
sg_set_buf(sg_out, aad, TLS_AAD_SPACE_SIZE);
93-
chain_to_walk(sg_in + 1, in);
94-
chain_to_walk(sg_out + 1, out);
79+
scatterwalk_get_sglist(in, sg_in + 1);
80+
scatterwalk_get_sglist(out, sg_out + 1);
9581

9682
*in_len -= len;
9783
if (*in_len < 0) {
@@ -110,10 +96,8 @@ static int tls_enc_record(struct aead_request *aead_req,
11096
}
11197

11298
if (*in_len) {
113-
scatterwalk_copychunks(NULL, in, len, 2);
114-
scatterwalk_pagedone(in, 0, 1);
115-
scatterwalk_copychunks(NULL, out, len, 2);
116-
scatterwalk_pagedone(out, 1, 1);
99+
scatterwalk_skip(in, len);
100+
scatterwalk_skip(out, len);
117101
}
118102

119103
len -= cipher_desc->tag;
@@ -162,9 +146,6 @@ static int tls_enc_records(struct aead_request *aead_req,
162146

163147
} while (rc == 0 && len);
164148

165-
scatterwalk_done(&in, 0, 0);
166-
scatterwalk_done(&out, 1, 0);
167-
168149
return rc;
169150
}
170151

0 commit comments

Comments
 (0)