[igt-dev] [PATCH i-g-t 1/7] lib: Introduce igt_memdup()
Ville Syrjälä
ville.syrjala at linux.intel.com
Mon Oct 18 07:19:41 UTC 2021
On Mon, Oct 18, 2021 at 04:19:41AM +0000, Modem, Bhanuprakash wrote:
> > 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?
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
More information about the igt-dev
mailing list