From d9c7e7d28617c6e980b640e1ecb9eb4c7b25644c Mon Sep 17 00:00:00 2001 From: Adrian Bonislawski Date: Fri, 15 May 2026 10:53:16 +0200 Subject: [PATCH] math: fft: move NULL guard before plan dereferences in HiFi3 variants In fft_execute_16() and fft_execute_32() HiFi3 implementations, local variables are initialized from plan->size, plan->len (and in 32-bit: plan->inb32, plan->outb32, plan->bit_reverse_idx) before the 'if (!plan)' guard is reached. Move all plan-> accesses after the NULL check, matching the generic fft_16.c / fft_32.c ordering. Signed-off-by: Adrian Bonislawski --- src/math/fft/fft_16_hifi3.c | 6 ++++-- src/math/fft/fft_32_hifi3.c | 15 ++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/math/fft/fft_16_hifi3.c b/src/math/fft/fft_16_hifi3.c index 318fb0d1a216..56d5bc177789 100644 --- a/src/math/fft/fft_16_hifi3.c +++ b/src/math/fft/fft_16_hifi3.c @@ -35,12 +35,14 @@ void fft_execute_16(struct fft_plan *plan, bool ifft) ae_valign outu = AE_ZALIGN64(); int depth, top, bottom, index; int i, j, k, m, n; - int size = plan->size; - int len = plan->len; + int size, len; if (!plan || !plan->bit_reverse_idx) return; + size = plan->size; + len = plan->len; + outb = plan->outb16; if (!plan->inb16 || !outb) return; diff --git a/src/math/fft/fft_32_hifi3.c b/src/math/fft/fft_32_hifi3.c index 266f83fc1b0a..1d00dacd1b7f 100644 --- a/src/math/fft/fft_32_hifi3.c +++ b/src/math/fft/fft_32_hifi3.c @@ -20,17 +20,16 @@ void fft_execute_32(struct fft_plan *plan, bool ifft) ae_int32x2 sample1; ae_int32x2 sample2; ae_int32x2 tw; - ae_int32x2 *inx = (ae_int32x2 *)plan->inb32; - ae_int32x2 *outx = (ae_int32x2 *)plan->outb32; + ae_int32x2 *inx; + ae_int32x2 *outx; ae_int32x2 *top_ptr; ae_int32x2 *bot_ptr; - uint16_t *idx = &plan->bit_reverse_idx[0]; + uint16_t *idx; const int32_t *tw_r; const int32_t *tw_i; int depth, i; int j, k, m, n; - int size = plan->size; - int len = plan->len; + int size, len; if (!plan || !plan->bit_reverse_idx) return; @@ -38,6 +37,12 @@ void fft_execute_32(struct fft_plan *plan, bool ifft) if (!plan->inb32 || !plan->outb32) return; + inx = (ae_int32x2 *)plan->inb32; + outx = (ae_int32x2 *)plan->outb32; + idx = &plan->bit_reverse_idx[0]; + size = plan->size; + len = plan->len; + /* step 1: re-arrange input in bit reverse order, and shrink the level to avoid overflow */ if (ifft) { /* convert to complex conjugate for ifft */