Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/tls: use sg_next() to walk sg entries

Partially sent record cleanup path increments an SG entry
directly instead of using sg_next(). This should not be a
problem today, as encrypted messages should be always
allocated as arrays. But given this is a cleanup path it's
easy to miss was this ever to change. Use sg_next(), and
simplify the code.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
c5daa6cc 9e5ffed3

+5 -13
+1 -1
include/net/tls.h
··· 376 376 int flags); 377 377 int tls_push_partial_record(struct sock *sk, struct tls_context *ctx, 378 378 int flags); 379 - bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx); 379 + void tls_free_partial_record(struct sock *sk, struct tls_context *ctx); 380 380 381 381 static inline struct tls_msg *tls_msg(struct sk_buff *skb) 382 382 {
+2 -11
net/tls/tls_main.c
··· 209 209 return tls_push_sg(sk, ctx, sg, offset, flags); 210 210 } 211 211 212 - bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx) 212 + void tls_free_partial_record(struct sock *sk, struct tls_context *ctx) 213 213 { 214 214 struct scatterlist *sg; 215 215 216 - sg = ctx->partially_sent_record; 217 - if (!sg) 218 - return false; 219 - 220 - while (1) { 216 + for (sg = ctx->partially_sent_record; sg; sg = sg_next(sg)) { 221 217 put_page(sg_page(sg)); 222 218 sk_mem_uncharge(sk, sg->length); 223 - 224 - if (sg_is_last(sg)) 225 - break; 226 - sg++; 227 219 } 228 220 ctx->partially_sent_record = NULL; 229 - return true; 230 221 } 231 222 232 223 static void tls_write_space(struct sock *sk)
+2 -1
net/tls/tls_sw.c
··· 2089 2089 /* Free up un-sent records in tx_list. First, free 2090 2090 * the partially sent record if any at head of tx_list. 2091 2091 */ 2092 - if (tls_free_partial_record(sk, tls_ctx)) { 2092 + if (tls_ctx->partially_sent_record) { 2093 + tls_free_partial_record(sk, tls_ctx); 2093 2094 rec = list_first_entry(&ctx->tx_list, 2094 2095 struct tls_rec, list); 2095 2096 list_del(&rec->list);