Skip to content

math: fft: fix error path in mod_fft_multi_plan_new()#10914

Open
singalsu wants to merge 1 commit into
thesofproject:mainfrom
singalsu:fft_updates
Open

math: fft: fix error path in mod_fft_multi_plan_new()#10914
singalsu wants to merge 1 commit into
thesofproject:mainfrom
singalsu:fft_updates

Conversation

@singalsu

Copy link
Copy Markdown
Collaborator

The error path of mod_fft_multi_plan_new() had two related bugs. With num_ffts == 1 the temporary input buffer aliases the caller-provided inb, but the err_free_buffer label freed plan->tmp_i32[0] unconditionally, which would have released the caller's buffer. With num_ffts == 3, a failure in the second or third fft_plan_common_new() call only freed the shared scratch buffer and the bit-reverse table, leaking the previously allocated fft_plan entries.

Collapse all error labels into a single err: that calls mod_fft_multi_plan_free(). That helper already walks fft_plan[] (NULL slots from the initial mod_zalloc() are no-ops in mod_free()) and only frees tmp_i32[0] when num_ffts > 1, so both issues are handled in one place.

The error path of mod_fft_multi_plan_new() had two related bugs. With
num_ffts == 1 the temporary input buffer aliases the caller-provided
inb, but the err_free_buffer label freed plan->tmp_i32[0]
unconditionally, which would have released the caller's buffer. With
num_ffts == 3, a failure in the second or third fft_plan_common_new()
call only freed the shared scratch buffer and the bit-reverse table,
leaking the previously allocated fft_plan entries.

Collapse all error labels into a single err: that calls
mod_fft_multi_plan_free(). That helper already walks fft_plan[] (NULL
slots from the initial mod_zalloc() are no-ops in mod_free()) and only
frees tmp_i32[0] when num_ffts > 1, so both issues are handled in one
place.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu marked this pull request as ready for review June 15, 2026 11:15
Copilot AI review requested due to automatic review settings June 15, 2026 11:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes cleanup logic in mod_fft_multi_plan_new() so error handling is correct for both the single-FFT (power-of-2) and 3-FFT (size divisible by 3) cases, avoiding both an invalid free and partial-allocation leaks.

Changes:

  • Replace multiple error labels with a single err: path that delegates cleanup to mod_fft_multi_plan_free().
  • Ensure partial initialization (e.g., some fft_plan[i] allocated, others NULL) is cleaned up consistently and safely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants