* [PATCH] net/tls: Use kmemdup to simplify the code
@ 2018-07-31 16:50 zhong jiang
2018-08-01 16:48 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: zhong jiang @ 2018-07-31 16:50 UTC (permalink / raw)
To: borisp, aviadye, davejwatson, davem; +Cc: netdev, linux-kernel
Kmemdup is better than kmalloc+memcpy. So replace them.
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
net/tls/tls_device.c | 3 +--
net/tls/tls_sw.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index 1e968d2..292742e 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -716,12 +716,11 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
memcpy(ctx->tx.iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, iv, iv_size);
ctx->tx.rec_seq_size = rec_seq_size;
- ctx->tx.rec_seq = kmalloc(rec_seq_size, GFP_KERNEL);
+ ctx->tx.rec_seq = kmemdup(rec_seq, rec_seq_size, GFP_KERNEL);
if (!ctx->tx.rec_seq) {
rc = -ENOMEM;
goto free_iv;
}
- memcpy(ctx->tx.rec_seq, rec_seq, rec_seq_size);
rc = tls_sw_fallback_init(sk, offload_ctx, crypto_info);
if (rc)
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 33838f1..ff3a690 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1173,12 +1173,11 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
memcpy(cctx->iv, gcm_128_info->salt, TLS_CIPHER_AES_GCM_128_SALT_SIZE);
memcpy(cctx->iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, iv, iv_size);
cctx->rec_seq_size = rec_seq_size;
- cctx->rec_seq = kmalloc(rec_seq_size, GFP_KERNEL);
+ cctx->rec_seq = kmemdup(rec_seq, rec_seq_size, GFP_KERNEL);
if (!cctx->rec_seq) {
rc = -ENOMEM;
goto free_iv;
}
- memcpy(cctx->rec_seq, rec_seq, rec_seq_size);
if (sw_ctx_tx) {
sg_init_table(sw_ctx_tx->sg_encrypted_data,
--
1.7.12.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net/tls: Use kmemdup to simplify the code
2018-07-31 16:50 [PATCH] net/tls: Use kmemdup to simplify the code zhong jiang
@ 2018-08-01 16:48 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-08-01 16:48 UTC (permalink / raw)
To: zhongjiang; +Cc: borisp, aviadye, davejwatson, netdev, linux-kernel
From: zhong jiang <zhongjiang@huawei.com>
Date: Wed, 1 Aug 2018 00:50:24 +0800
> Kmemdup is better than kmalloc+memcpy. So replace them.
>
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-08-01 16:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-31 16:50 [PATCH] net/tls: Use kmemdup to simplify the code zhong jiang
2018-08-01 16:48 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).