All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next v3] crypto: hisilicon - switch to memdup_user_nul()
@ 2021-05-24  9:47 Zou Wei
  2021-06-03 12:28 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Zou Wei @ 2021-05-24  9:47 UTC (permalink / raw)
  To: wangzhou1, herbert, davem; +Cc: linux-crypto, linux-kernel, Zou Wei

Use memdup_user_nul() helper instead of open-coding to
simplify the code.

v1-->v2:
   fixed patch title error
v2-->v3:
   return the actual error

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 drivers/crypto/hisilicon/qm.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index 8f7ea50..8b389c2 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -1571,16 +1571,9 @@ static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer,
 	if (count > QM_DBG_WRITE_LEN)
 		return -ENOSPC;
 
-	cmd_buf = kzalloc(count + 1, GFP_KERNEL);
-	if (!cmd_buf)
-		return -ENOMEM;
-
-	if (copy_from_user(cmd_buf, buffer, count)) {
-		kfree(cmd_buf);
-		return -EFAULT;
-	}
-
-	cmd_buf[count] = '\0';
+	cmd_buf = memdup_user_nul(buffer, count);
+	if (IS_ERR(cmd_buf))
+		return PTR_ERR(cmd_buf);
 
 	cmd_buf_tmp = strchr(cmd_buf, '\n');
 	if (cmd_buf_tmp) {
-- 
2.6.2


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

* Re: [PATCH -next v3] crypto: hisilicon - switch to memdup_user_nul()
  2021-05-24  9:47 [PATCH -next v3] crypto: hisilicon - switch to memdup_user_nul() Zou Wei
@ 2021-06-03 12:28 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2021-06-03 12:28 UTC (permalink / raw)
  To: Zou Wei; +Cc: wangzhou1, davem, linux-crypto, linux-kernel

On Mon, May 24, 2021 at 05:47:08PM +0800, Zou Wei wrote:
> Use memdup_user_nul() helper instead of open-coding to
> simplify the code.
> 
> v1-->v2:
>    fixed patch title error
> v2-->v3:
>    return the actual error
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
>  drivers/crypto/hisilicon/qm.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2021-06-03 12:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24  9:47 [PATCH -next v3] crypto: hisilicon - switch to memdup_user_nul() Zou Wei
2021-06-03 12:28 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.