From 1dc590d638baabebcbb3d724903ff6966de020ee Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Thu, 7 Dec 2023 19:44:10 -0500 Subject: [PATCH] fastrpc: hexagonrpcd: listener: compute out_count before zero check The amount of output buffers needed should be computed before the check, otherwise it checks an uninitialized value. Initialize it first so that the zero check works as intended. Fixes: 9ea9bed77b18 ("fastrpc: hexagonrpcd: listener: do not attempt to allocate zero outbufs") --- fastrpc/hexagonrpcd/listener.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastrpc/hexagonrpcd/listener.c b/fastrpc/hexagonrpcd/listener.c index bcdc857..c0527a0 100644 --- a/fastrpc/hexagonrpcd/listener.c +++ b/fastrpc/hexagonrpcd/listener.c @@ -73,6 +73,7 @@ static struct fastrpc_io_buffer *allocate_outbufs(const struct fastrpc_function_ off_t off; uint32_t *sizes; + out_count = def->out_bufs + (def->out_nums && 1); /* * POSIX allows malloc to return a non-NULL pointer to a zero-size area * in memory. Since the code below assumes non-zero size if the pointer @@ -81,7 +82,6 @@ static struct fastrpc_io_buffer *allocate_outbufs(const struct fastrpc_function_ if (out_count == 0) return NULL; - out_count = def->out_bufs + (def->out_nums && 1); out = malloc(sizeof(struct fastrpc_io_buffer) * out_count); if (out == NULL) return NULL;