linux-s390.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] s390/zcrypt: Use kmemdup to replace kmalloc + memcpy
@ 2018-09-08  8:50 zhong jiang
  2018-09-10  6:34 ` Martin Schwidefsky
  0 siblings, 1 reply; 2+ messages in thread
From: zhong jiang @ 2018-09-08  8:50 UTC (permalink / raw)
  To: freude, schwidefsky, heiko.carstens; +Cc: linux-s390, linux-kernel

kmemdup has implemented the function that kmalloc() + memcpy() will
do. and we prefer to use the kmemdup rather than the open coded implementation.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 drivers/s390/crypto/zcrypt_msgtype6.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
index 2101776..9ac960d 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.c
+++ b/drivers/s390/crypto/zcrypt_msgtype6.c
@@ -1131,10 +1131,9 @@ unsigned int get_cprb_fc(struct ica_xcRB *xcRB,
 	ap_msg->receive = zcrypt_msgtype6_receive;
 	ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
 				atomic_inc_return(&zcrypt_step);
-	ap_msg->private = kmalloc(sizeof(resp_type), GFP_KERNEL);
+	ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
 	if (!ap_msg->private)
 		return -ENOMEM;
-	memcpy(ap_msg->private, &resp_type, sizeof(resp_type));
 	return XCRB_msg_to_type6CPRB_msgX(ap_msg, xcRB, func_code, dom);
 }
 
@@ -1187,10 +1186,9 @@ unsigned int get_ep11cprb_fc(struct ep11_urb *xcrb,
 	ap_msg->receive = zcrypt_msgtype6_receive_ep11;
 	ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
 				atomic_inc_return(&zcrypt_step);
-	ap_msg->private = kmalloc(sizeof(resp_type), GFP_KERNEL);
+	ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
 	if (!ap_msg->private)
 		return -ENOMEM;
-	memcpy(ap_msg->private, &resp_type, sizeof(resp_type));
 	return xcrb_msg_to_type6_ep11cprb_msgx(ap_msg, xcrb, func_code);
 }
 
@@ -1282,10 +1280,9 @@ unsigned int get_rng_fc(struct ap_message *ap_msg, int *func_code,
 	ap_msg->receive = zcrypt_msgtype6_receive;
 	ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
 				atomic_inc_return(&zcrypt_step);
-	ap_msg->private = kmalloc(sizeof(resp_type), GFP_KERNEL);
+	ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
 	if (!ap_msg->private)
 		return -ENOMEM;
-	memcpy(ap_msg->private, &resp_type, sizeof(resp_type));
 
 	rng_type6CPRB_msgX(ap_msg, ZCRYPT_RNG_BUFFER_SIZE, domain);
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] s390/zcrypt: Use kmemdup to replace kmalloc + memcpy
  2018-09-08  8:50 [PATCH] s390/zcrypt: Use kmemdup to replace kmalloc + memcpy zhong jiang
@ 2018-09-10  6:34 ` Martin Schwidefsky
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Schwidefsky @ 2018-09-10  6:34 UTC (permalink / raw)
  To: zhong jiang; +Cc: freude, heiko.carstens, linux-s390, linux-kernel

On Sat, 8 Sep 2018 16:50:21 +0800
zhong jiang <zhongjiang@huawei.com> wrote:

> kmemdup has implemented the function that kmalloc() + memcpy() will
> do. and we prefer to use the kmemdup rather than the open coded implementation.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  drivers/s390/crypto/zcrypt_msgtype6.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)

Applied to linux-390:features. Thanks.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-10  6:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-08  8:50 [PATCH] s390/zcrypt: Use kmemdup to replace kmalloc + memcpy zhong jiang
2018-09-10  6:34 ` Martin Schwidefsky

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).