public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] s390/hmcdrv: Switch to memdup_user_nul() helper
@ 2023-08-15 11:55 Ruan Jinjie
  2023-08-15 12:13 ` Heiko Carstens
  0 siblings, 1 reply; 2+ messages in thread
From: Ruan Jinjie @ 2023-08-15 11:55 UTC (permalink / raw)
  To: linux-s390, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle
  Cc: ruanjinjie

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

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
 drivers/s390/char/hmcdrv_dev.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/drivers/s390/char/hmcdrv_dev.c b/drivers/s390/char/hmcdrv_dev.c
index 8d50c894711f..504cdbf9998d 100644
--- a/drivers/s390/char/hmcdrv_dev.c
+++ b/drivers/s390/char/hmcdrv_dev.c
@@ -252,19 +252,12 @@ static ssize_t hmcdrv_dev_write(struct file *fp, const char __user *ubuf,
 		 fp, (long long) *pos, len);
 
 	if (!fp->private_data) { /* first expect a cmd write */
-		fp->private_data = kmalloc(len + 1, GFP_KERNEL);
-
-		if (!fp->private_data)
-			return -ENOMEM;
-
-		if (!copy_from_user(fp->private_data, ubuf, len)) {
-			((char *)fp->private_data)[len] = '\0';
-			return len;
+		fp->private_data = memdup_user_nul(ubuf, len);
+		if (IS_ERR(fp->private_data)) {
+			fp->private_data = NULL;
+			return PTR_ERR(fp->private_data);
 		}
-
-		kfree(fp->private_data);
-		fp->private_data = NULL;
-		return -EFAULT;
+		return len;
 	}
 
 	retlen = hmcdrv_dev_transfer((char *) fp->private_data,
-- 
2.34.1


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

end of thread, other threads:[~2023-08-15 12:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-15 11:55 [PATCH -next] s390/hmcdrv: Switch to memdup_user_nul() helper Ruan Jinjie
2023-08-15 12:13 ` Heiko Carstens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox