lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <c07221ed-8eaf-490e-9672-033b1cfe7b6e@web.de>
Date: Sun, 28 Jan 2024 21:06:05 +0100
From: Markus Elfring <Markus.Elfring@....de>
To: dri-devel@...ts.freedesktop.org, kernel-janitors@...r.kernel.org,
 Daniel Vetter <daniel@...ll.ch>, David Airlie <airlied@...il.com>,
 Donald Robson <donald.robson@...tec.com>,
 Frank Binns <frank.binns@...tec.com>,
 Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
 Matt Coster <matt.coster@...tec.com>, Maxime Ripard <mripard@...nel.org>,
 Thomas Zimmermann <tzimmermann@...e.de>
Cc: LKML <linux-kernel@...r.kernel.org>,
 Sarah Walker <sarah.walker@...tec.com>
Subject: [PATCH] drm/imagination: Use memdup_user() rather than duplicating
 its implementation

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Sun, 28 Jan 2024 20:50:36 +0100

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

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

* Delete labels and statements which became unnecessary
  with this refactoring.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 drivers/gpu/drm/imagination/pvr_context.c | 21 +++------------------
 drivers/gpu/drm/imagination/pvr_job.c     | 15 +++------------
 2 files changed, 6 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/imagination/pvr_context.c b/drivers/gpu/drm/imagination/pvr_context.c
index eded5e955cc0..27814ae8a8f8 100644
--- a/drivers/gpu/drm/imagination/pvr_context.c
+++ b/drivers/gpu/drm/imagination/pvr_context.c
@@ -66,29 +66,14 @@ static int
 process_static_context_state(struct pvr_device *pvr_dev, const struct pvr_stream_cmd_defs *cmd_defs,
 			     u64 stream_user_ptr, u32 stream_size, void *dest)
 {
-	void *stream;
 	int err;
+	void *stream = memdup_user(u64_to_user_ptr(stream_user_ptr), stream_size);

-	stream = kzalloc(stream_size, GFP_KERNEL);
-	if (!stream)
-		return -ENOMEM;
-
-	if (copy_from_user(stream, u64_to_user_ptr(stream_user_ptr), stream_size)) {
-		err = -EFAULT;
-		goto err_free;
-	}
+	if (IS_ERR(stream))
+		return PTR_ERR(stream);

 	err = pvr_stream_process(pvr_dev, cmd_defs, stream, stream_size, dest);
-	if (err)
-		goto err_free;
-
 	kfree(stream);
-
-	return 0;
-
-err_free:
-	kfree(stream);
-
 	return err;
 }

diff --git a/drivers/gpu/drm/imagination/pvr_job.c b/drivers/gpu/drm/imagination/pvr_job.c
index 78c2f3c6dce0..e17d53b93b1f 100644
--- a/drivers/gpu/drm/imagination/pvr_job.c
+++ b/drivers/gpu/drm/imagination/pvr_job.c
@@ -87,23 +87,14 @@ static int pvr_fw_cmd_init(struct pvr_device *pvr_dev, struct pvr_job *job,
 			   const struct pvr_stream_cmd_defs *stream_def,
 			   u64 stream_userptr, u32 stream_len)
 {
-	void *stream;
 	int err;
+	void *stream = memdup_user(u64_to_user_ptr(stream_userptr), stream_len);

-	stream = kzalloc(stream_len, GFP_KERNEL);
-	if (!stream)
-		return -ENOMEM;
-
-	if (copy_from_user(stream, u64_to_user_ptr(stream_userptr), stream_len)) {
-		err = -EFAULT;
-		goto err_free_stream;
-	}
+	if (IS_ERR(stream))
+		return PTR_ERR(stream);

 	err = pvr_job_process_stream(pvr_dev, stream_def, stream, stream_len, job);
-
-err_free_stream:
 	kfree(stream);
-
 	return err;
 }

--
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ