engines: cleanup casts and move memset
authorVincent Fu <vincent.fu@samsung.com>
Sat, 15 Apr 2023 00:50:58 +0000 (00:50 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 20 Apr 2023 13:43:30 +0000 (09:43 -0400)
Drop type casting of malloc's return value. Move a memset call closer to
its corresponding malloc call.

This is a prep patch for a Coccinelle script that converts
malloc+memset(,0,) to calloc.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
engines/null.c
engines/solarisaio.c

index 68759c26f1096e98d062ff178e7a88458eac8f5c..68c9969c4f03a646e81b699efec029a2226ad484 100644 (file)
@@ -106,12 +106,12 @@ static void null_cleanup(struct null_data *nd)
 
 static struct null_data *null_init(struct thread_data *td)
 {
-       struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
+       struct null_data *nd = malloc(sizeof(*nd));
 
        memset(nd, 0, sizeof(*nd));
 
        if (td->o.iodepth != 1) {
-               nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
+               nd->io_us = malloc(td->o.iodepth * sizeof(struct io_u *));
                memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
                td->io_ops->flags |= FIO_ASYNCIO_SETS_ISSUE_TIME;
        } else
index 21e95935b20bdc387a41f5c176fd806ff3c8f504..59bae71379a34cd5324243aced85e8af7328996b 100644 (file)
@@ -185,8 +185,9 @@ static void fio_solarisaio_init_sigio(void)
 
 static int fio_solarisaio_init(struct thread_data *td)
 {
-       struct solarisaio_data *sd = malloc(sizeof(*sd));
        unsigned int max_depth;
+       struct solarisaio_data *sd = malloc(sizeof(*sd));
+       memset(sd, 0, sizeof(*sd));
 
        max_depth = td->o.iodepth;
        if (max_depth > MAXASYNCHIO) {
@@ -195,7 +196,6 @@ static int fio_solarisaio_init(struct thread_data *td)
                                                        max_depth);
        }
 
-       memset(sd, 0, sizeof(*sd));
        sd->aio_events = malloc(max_depth * sizeof(struct io_u *));
        memset(sd->aio_events, 0, max_depth * sizeof(struct io_u *));
        sd->max_depth = max_depth;