From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 373D76E970 for ; Mon, 18 Oct 2021 07:19:45 +0000 (UTC) Date: Mon, 18 Oct 2021 10:19:41 +0300 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= Message-ID: References: <20211013125949.19373-1-ville.syrjala@linux.intel.com> <20211013125949.19373-2-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: Subject: Re: [igt-dev] [PATCH i-g-t 1/7] lib: Introduce igt_memdup() List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" To: "Modem, Bhanuprakash" Cc: "igt-dev@lists.freedesktop.org" List-ID: On Mon, Oct 18, 2021 at 04:19:41AM +0000, Modem, Bhanuprakash wrote: > > From: igt-dev 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() > >=20 > > From: Ville Syrj=E4l=E4 > >=20 > > Provide a helper to do the malloc()+memcpy() in one swift blow. > >=20 > > Signed-off-by: Ville Syrj=E4l=E4 > > --- > > lib/igt_aux.c | 11 +++++++++++ > > lib/igt_aux.h | 2 ++ > > 2 files changed, 13 insertions(+) > >=20 > > 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 =3D malloc(len); > > + if (dup) > > + memcpy(dup, ptr, len); > > + > > + return dup; >=20 > 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. --=20 Ville Syrj=E4l=E4 Intel