Thread (20 messages) read the whole thread 20 messages, 3 authors, 2021-10-18

Re: [igt-dev] [PATCH i-g-t 1/7] lib: Introduce igt_memdup()

From: Ville Syrjälä <hidden>
Date: 2021-10-18 07:19:45

On Mon, Oct 18, 2021 at 04:19:41AM +0000, Modem, Bhanuprakash wrote:
quoted
From: igt-dev <redacted> On Behalf Of Ville
Syrjala
Sent: Wednesday, October 13, 2021 6:30 PM
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 1/7] lib: Introduce igt_memdup()

From: Ville Syrjälä <redacted>

Provide a helper to do the malloc()+memcpy() in one swift blow.

Signed-off-by: Ville Syrjälä <redacted>
---
 lib/igt_aux.c | 11 +++++++++++
 lib/igt_aux.h |  2 ++
 2 files changed, 13 insertions(+)
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 1217f5e88094..2445e483e210 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1527,3 +1527,14 @@ uint64_t vfs_file_max(void)
 	}
 	return max;
 }
+
+void *igt_memdup(const void *ptr, size_t len)
+{
+	void *dup;
+
+	dup = malloc(len);
+	if (dup)
+		memcpy(dup, ptr, len);
+
+	return dup;
Don't we need to handle the malloc() failures?
Returning NULL is the way we handle malloc failures.
If it is fine to return NULL (in case of malloc failure) from here,
I haven't seen that any caller (Other patches in this series) is handling
this NULL.
In actual tests the normal way to handle malloc failures is by
exploding. Nothing special needed for that.

-- 
Ville Syrjälä
Intel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help