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: 9ea9bed77b ("fastrpc: hexagonrpcd: listener: do not attempt to allocate zero outbufs")
This commit is contained in:
Richard Acayan
2023-12-07 19:44:10 -05:00
parent f085f578e3
commit 1dc590d638

View File

@@ -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;