[igt-dev] [PATCH i-g-t 1/7] lib: Introduce igt_memdup()
Modem, Bhanuprakash
bhanuprakash.modem at intel.com
Mon Oct 18 04:19:41 UTC 2021
> From: igt-dev <igt-dev-bounces at lists.freedesktop.org> On Behalf Of Ville
> Syrjala
> Sent: Wednesday, October 13, 2021 6:30 PM
> To: igt-dev at lists.freedesktop.org
> Subject: [igt-dev] [PATCH i-g-t 1/7] lib: Introduce igt_memdup()
>
> From: Ville Syrjälä <ville.syrjala at linux.intel.com>
>
> Provide a helper to do the malloc()+memcpy() in one swift blow.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
> ---
> 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?
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.
- Bhanu
> +}
> diff --git a/lib/igt_aux.h b/lib/igt_aux.h
> index 30b175d70d8b..a3c477abcd86 100644
> --- a/lib/igt_aux.h
> +++ b/lib/igt_aux.h
> @@ -324,4 +324,6 @@ void igt_lsof(const char *dpath);
>
> uint64_t vfs_file_max(void);
>
> +void *igt_memdup(const void *ptr, size_t len);
> +
> #endif /* IGT_AUX_H */
> --
> 2.32.0
More information about the igt-dev
mailing list