> -----Original Message----- > From: Ammar Faizi [mailto:ammarfaizi2@xxxxxxxxxxx] > Sent: Thursday, April 28, 2022 8:47 PM > To: Jens Axboe <axboe@xxxxxxxxx> > Cc: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>; Alviro Iskandar Setiawan > <alviro.iskandar@xxxxxxxxxxx>; Niklas Cassel > <Niklas.Cassel@xxxxxxx>; fio Mailing List <fio@xxxxxxxxxxxxxxx>; > GNU/Weeb Mailing List <gwml@xxxxxxxxxxxxxxxx> > Subject: [PATCH v1 3/8] engines/net: Add ENOMEM handling on a > `malloc()` call > > From: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx> > > Replace `malloc()` + `memset()` with `calloc()` to simplify the call. > `calloc()` zeroes the allocated memory, so we can avoid `memset()`. > Also, handle the `ENOMEM` case. > > Signed-off-by: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx> > --- > engines/net.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/engines/net.c b/engines/net.c > index c6cec584..24c1463d 100644 > --- a/engines/net.c > +++ b/engines/net.c > @@ -1370,9 +1370,9 @@ static int fio_netio_setup(struct thread_data > *td) > } > > if (!td->io_ops_data) { > - nd = malloc(sizeof(*nd)); > - > - memset(nd, 0, sizeof(*nd)); > + nd = calloc(1, sizeof(*nd)); > + if (!nd) > + return 1; > nd->listenfd = -1; > nd->pipes[0] = nd->pipes[1] = -1; > td->io_ops_data = nd; > @@ -1391,7 +1391,8 @@ static int fio_netio_setup_splice(struct > thread_data *td) > { > struct netio_data *nd; > > - fio_netio_setup(td); > + if (fio_netio_setup(td)) > + return 1; > > nd = td->io_ops_data; > if (nd) { > -- > Ammar Faizi Looks good. Reviewed-by: Vincent Fu <vincent.fu@xxxxxxxxxxx>