mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-s390@vger.kernel.org, kernel-janitors@vger.kernel.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Bornträger" <borntraeger@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Peter Oberparleiter" <oberpar@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Vineeth Vijayan" <vneethv@linux.ibm.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] s390/cio: Use memdup_user() rather than duplicating its implementation
Date: Mon, 29 Jan 2024 15:19:00 +0100	[thread overview]
Message-ID: <e8939703-b9a4-4ed0-ae7e-ad9a08ae96d4@web.de> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Jan 2024 15:00:36 +0100

* Reuse existing functionality from memdup_user() instead of keeping
  duplicate source code.

  Generated by: scripts/coccinelle/api/memdup_user.cocci

* Use another label in six function implementations.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/s390/cio/chsc_sch.c | 90 +++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 48 deletions(-)

diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
index 902237d0baef..2ad4264589d9 100644
--- a/drivers/s390/cio/chsc_sch.c
+++ b/drivers/s390/cio/chsc_sch.c
@@ -442,15 +442,13 @@ static int chsc_ioctl_info_channel_path(void __user *user_cd)
 	scpcd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
 	if (!scpcd_area)
 		return -ENOMEM;
-	cd = kzalloc(sizeof(*cd), GFP_KERNEL);
-	if (!cd) {
-		ret = -ENOMEM;
-		goto out_free;
-	}
-	if (copy_from_user(cd, user_cd, sizeof(*cd))) {
-		ret = -EFAULT;
-		goto out_free;
+
+	cd = memdup_user(user_cd, sizeof(*cd));
+	if (IS_ERR(cd)) {
+		ret = PTR_ERR(cd);
+		goto out_free_page;
 	}
+
 	scpcd_area->request.length = 0x0010;
 	scpcd_area->request.code = 0x0028;
 	scpcd_area->m = cd->m;
@@ -477,6 +475,7 @@ static int chsc_ioctl_info_channel_path(void __user *user_cd)
 		ret = 0;
 out_free:
 	kfree(cd);
+out_free_page:
 	free_page((unsigned long)scpcd_area);
 	return ret;
 }
@@ -504,15 +503,13 @@ static int chsc_ioctl_info_cu(void __user *user_cd)
 	scucd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
 	if (!scucd_area)
 		return -ENOMEM;
-	cd = kzalloc(sizeof(*cd), GFP_KERNEL);
-	if (!cd) {
-		ret = -ENOMEM;
-		goto out_free;
-	}
-	if (copy_from_user(cd, user_cd, sizeof(*cd))) {
-		ret = -EFAULT;
-		goto out_free;
+
+	cd = memdup_user(user_cd, sizeof(*cd));
+	if (IS_ERR(cd)) {
+		ret = PTR_ERR(cd);
+		goto out_free_page;
 	}
+
 	scucd_area->request.length = 0x0010;
 	scucd_area->request.code = 0x0026;
 	scucd_area->m = cd->m;
@@ -539,6 +536,7 @@ static int chsc_ioctl_info_cu(void __user *user_cd)
 		ret = 0;
 out_free:
 	kfree(cd);
+out_free_page:
 	free_page((unsigned long)scucd_area);
 	return ret;
 }
@@ -567,15 +565,13 @@ static int chsc_ioctl_info_sch_cu(void __user *user_cud)
 	sscud_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
 	if (!sscud_area)
 		return -ENOMEM;
-	cud = kzalloc(sizeof(*cud), GFP_KERNEL);
-	if (!cud) {
-		ret = -ENOMEM;
-		goto out_free;
-	}
-	if (copy_from_user(cud, user_cud, sizeof(*cud))) {
-		ret = -EFAULT;
-		goto out_free;
+
+	cud = memdup_user(user_cud, sizeof(*cud));
+	if (IS_ERR(cud)) {
+		ret = PTR_ERR(cud);
+		goto out_free_page;
 	}
+
 	sscud_area->request.length = 0x0010;
 	sscud_area->request.code = 0x0006;
 	sscud_area->m = cud->schid.m;
@@ -603,6 +599,7 @@ static int chsc_ioctl_info_sch_cu(void __user *user_cud)
 		ret = 0;
 out_free:
 	kfree(cud);
+out_free_page:
 	free_page((unsigned long)sscud_area);
 	return ret;
 }
@@ -629,15 +626,13 @@ static int chsc_ioctl_conf_info(void __user *user_ci)
 	sci_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
 	if (!sci_area)
 		return -ENOMEM;
-	ci = kzalloc(sizeof(*ci), GFP_KERNEL);
-	if (!ci) {
-		ret = -ENOMEM;
-		goto out_free;
-	}
-	if (copy_from_user(ci, user_ci, sizeof(*ci))) {
-		ret = -EFAULT;
-		goto out_free;
+
+	ci = memdup_user(user_ci, sizeof(*ci));
+	if (IS_ERR(ci)) {
+		ret = PTR_ERR(ci);
+		goto out_free_page;
 	}
+
 	sci_area->request.length = 0x0010;
 	sci_area->request.code = 0x0012;
 	sci_area->m = ci->id.m;
@@ -663,6 +658,7 @@ static int chsc_ioctl_conf_info(void __user *user_ci)
 		ret = 0;
 out_free:
 	kfree(ci);
+out_free_page:
 	free_page((unsigned long)sci_area);
 	return ret;
 }
@@ -700,15 +696,13 @@ static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
 	sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
 	if (!sccl_area)
 		return -ENOMEM;
-	ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
-	if (!ccl) {
-		ret = -ENOMEM;
-		goto out_free;
-	}
-	if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
-		ret = -EFAULT;
-		goto out_free;
+
+	ccl = memdup_user(user_ccl, sizeof(*ccl));
+	if (IS_ERR(ccl)) {
+		ret = PTR_ERR(ccl);
+		goto out_free_page;
 	}
+
 	sccl_area->request.length = 0x0020;
 	sccl_area->request.code = 0x0030;
 	sccl_area->fmt = ccl->req.fmt;
@@ -746,6 +740,7 @@ static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
 		ret = 0;
 out_free:
 	kfree(ccl);
+out_free_page:
 	free_page((unsigned long)sccl_area);
 	return ret;
 }
@@ -800,15 +795,13 @@ static int chsc_ioctl_dcal(void __user *user_dcal)
 	sdcal_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
 	if (!sdcal_area)
 		return -ENOMEM;
-	dcal = kzalloc(sizeof(*dcal), GFP_KERNEL);
-	if (!dcal) {
-		ret = -ENOMEM;
-		goto out_free;
-	}
-	if (copy_from_user(dcal, user_dcal, sizeof(*dcal))) {
-		ret = -EFAULT;
-		goto out_free;
+
+	dcal = memdup_user(user_dcal, sizeof(*dcal));
+	if (IS_ERR(dcal)) {
+		ret = PTR_ERR(dcal);
+		goto out_free_page;
 	}
+
 	sdcal_area->request.length = 0x0020;
 	sdcal_area->request.code = 0x0034;
 	sdcal_area->atype = dcal->req.atype;
@@ -835,6 +828,7 @@ static int chsc_ioctl_dcal(void __user *user_dcal)
 		ret = 0;
 out_free:
 	kfree(dcal);
+out_free_page:
 	free_page((unsigned long)sdcal_area);
 	return ret;
 }
--
2.43.0


                 reply	other threads:[~2024-01-29 14:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e8939703-b9a4-4ed0-ae7e-ad9a08ae96d4@web.de \
    --to=markus.elfring@web.de \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=oberpar@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    --cc=vneethv@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®