iolog: check scalloc return value
authorVincent Fu <vincent.fu@samsung.com>
Tue, 11 Jun 2024 20:09:00 +0000 (16:09 -0400)
committerVincent Fu <vincent.fu@samsung.com>
Tue, 11 Jun 2024 20:09:00 +0000 (16:09 -0400)
It is possible for scalloc to return NULL. setup_log() does not return a
value to indicate failure but we can use an assert here to check for a
NULL scalloc return value. This will trigger an exception similar to the
segfault that would happen if scalloc returns null, but this should
silence Coverity.

This was reported by Coverity:

** CID 496646:  Null pointer dereferences  (NULL_RETURNS)
/iolog.c: 843 in setup_log()

*** CID 496646:  Null pointer dereferences  (NULL_RETURNS)
/iolog.c: 843 in setup_log()
837      struct io_log *l;
838      int i;
839      struct io_u_plat_entry *entry;
840      struct flist_head *list;
841
842      l = scalloc(1, sizeof(*l));
>>>     CID 496646:  Null pointer dereferences  (NULL_RETURNS)
>>>     Dereferencing "l", which is known to be "NULL".

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
iolog.c

diff --git a/iolog.c b/iolog.c
index b57f845e275e04fbe76c39cdc987c1bb2269d83e..f727c97f498a65243f797b55b39073a2a703a55e 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -840,6 +840,7 @@ void setup_log(struct io_log **log, struct log_params *p,
        struct flist_head *list;
 
        l = scalloc(1, sizeof(*l));
+       assert(l);
        INIT_FLIST_HEAD(&l->io_logs);
        l->log_type = p->log_type;
        l->log_offset = p->log_offset;