Skip to content

Commit

Permalink
net/tls: Use kmemdup to simplify the code
Browse files Browse the repository at this point in the history
Kmemdup is better than kmalloc+memcpy. So replace them.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
zhong jiang authored and David S. Miller committed Aug 1, 2018
1 parent b053fcc commit 969d509
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions net/tls/tls_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 969d509

Please sign in to comment.