iolog: always use calloc() and always init both lists
authorJens Axboe <axboe@kernel.dk>
Thu, 26 Apr 2018 20:44:18 +0000 (14:44 -0600)
committerJens Axboe <axboe@kernel.dk>
Thu, 26 Apr 2018 20:44:18 +0000 (14:44 -0600)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
blktrace.c
iolog.c
iolog.h

index 721bcd4bc422a93f7333ef54185f000c6853f571..29d1ff748d1b7b1e3017429f216f5b91e206137c 100644 (file)
@@ -222,8 +222,9 @@ static void store_ipo(struct thread_data *td, unsigned long long offset,
                      unsigned int bytes, int rw, unsigned long long ttime,
                      int fileno, unsigned int bs)
 {
                      unsigned int bytes, int rw, unsigned long long ttime,
                      int fileno, unsigned int bs)
 {
-       struct io_piece *ipo = malloc(sizeof(*ipo));
+       struct io_piece *ipo;
 
 
+       ipo = calloc(1, sizeof(*ipo));
        init_ipo(ipo);
 
        ipo->offset = offset * bs;
        init_ipo(ipo);
 
        ipo->offset = offset * bs;
@@ -268,10 +269,11 @@ static void handle_trace_discard(struct thread_data *td,
                                 unsigned long long ttime,
                                 unsigned long *ios, unsigned int *rw_bs)
 {
                                 unsigned long long ttime,
                                 unsigned long *ios, unsigned int *rw_bs)
 {
-       struct io_piece *ipo = malloc(sizeof(*ipo));
+       struct io_piece *ipo;
        unsigned int bs;
        int fileno;
 
        unsigned int bs;
        int fileno;
 
+       ipo = calloc(1, sizeof(*ipo));
        init_ipo(ipo);
        fileno = trace_add_file(td, t->device, &bs);
 
        init_ipo(ipo);
        fileno = trace_add_file(td, t->device, &bs);
 
diff --git a/iolog.c b/iolog.c
index 74c89f0cae2de5c3b0bad5438dc63ac9d211db28..f1e52311b38208c4c505fce38ab279b506670302 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -211,7 +211,7 @@ void log_io_piece(struct thread_data *td, struct io_u *io_u)
        struct fio_rb_node **p, *parent;
        struct io_piece *ipo, *__ipo;
 
        struct fio_rb_node **p, *parent;
        struct io_piece *ipo, *__ipo;
 
-       ipo = malloc(sizeof(struct io_piece));
+       ipo = calloc(1, sizeof(struct io_piece));
        init_ipo(ipo);
        ipo->file = io_u->file;
        ipo->offset = io_u->offset;
        init_ipo(ipo);
        ipo->file = io_u->file;
        ipo->offset = io_u->offset;
@@ -440,7 +440,7 @@ static int read_iolog2(struct thread_data *td, FILE *f)
                /*
                 * Make note of file
                 */
                /*
                 * Make note of file
                 */
-               ipo = malloc(sizeof(*ipo));
+               ipo = calloc(1, sizeof(*ipo));
                init_ipo(ipo);
                ipo->ddir = rw;
                if (rw == DDIR_WAIT) {
                init_ipo(ipo);
                ipo->ddir = rw;
                if (rw == DDIR_WAIT) {
diff --git a/iolog.h b/iolog.h
index f70eb61e6eae92edb324ed5dbea35c9e6dcb11dc..d689140f87d399a5fb220e2e3dbeca7051e00adf 100644 (file)
--- a/iolog.h
+++ b/iolog.h
@@ -296,7 +296,7 @@ extern int iolog_cur_flush(struct io_log *, struct io_logs *);
 
 static inline void init_ipo(struct io_piece *ipo)
 {
 
 static inline void init_ipo(struct io_piece *ipo)
 {
-       memset(ipo, 0, sizeof(*ipo));
+       INIT_FLIST_HEAD(&ipo->list);
        INIT_FLIST_HEAD(&ipo->trim_list);
 }
 
        INIT_FLIST_HEAD(&ipo->trim_list);
 }