Audio modules fixes#10752
Conversation
Properly track allocation state in the ASRC component lifecycle to prevent double-free of heap memory during module teardown in ZTest environments. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add input validation for the frame_shift configuration field in mfcc_setup(). A zero or negative value would cause a division by zero during STFT processing. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add null checks for hardware device pointers that may not be available when running in ZTest environments without real hardware. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a few robustness issues in the audio modules that were surfaced by the audio ztest unit tests, primarily by adding missing validation and making teardown paths safer.
Changes:
- Add Zephyr
device_is_ready()gating to mic privacy manager initialization and guard policy queries when the device isn’t initialized. - Add MFCC configuration validation to reject non-positive
frame_shift. - Harden ASRC free/reset paths by adding NULL checks, clearing pointers after freeing, and resetting module private data.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/audio/mic_privacy_manager/mic_privacy_manager_intel.c |
Add device readiness check during init and a guard in get_policy() to avoid dereferencing an uninitialized device pointer. |
src/audio/mfcc/mfcc_setup.c |
Add basic validation for frame_shift to prevent invalid hop sizes. |
src/audio/asrc/asrc.c |
Make free()/reset() more defensive by checking allocations before releasing and nulling pointers after free. |
| if (!device_is_ready(mic_priv_dev)) { | ||
| LOG_ERR("mic_privacy device not ready"); | ||
| return -ENODEV; | ||
| } |
There was a problem hiding this comment.
This is a valid concern. Maybe alternative is to drop mic privacy when running the ztest?
| fft->fft_size = config->frame_length; | ||
| fft->fft_padded_size = 1 << (31 - norm_int32(fft->fft_size)); /* Round up to nearest 2^N */ | ||
| if (config->frame_shift <= 0) { | ||
| comp_err(dev, "frame_shift must be positive"); | ||
| return -EINVAL; | ||
| } |
kv2019i
left a comment
There was a problem hiding this comment.
Looks ok. Not 100% sure whether for mic privacy would be easier to just disable mic privacy for ztest runs. Otherwise you'd need add more checks (or make the dev null if init is not done).
| if (!device_is_ready(mic_priv_dev)) { | ||
| LOG_ERR("mic_privacy device not ready"); | ||
| return -ENODEV; | ||
| } |
There was a problem hiding this comment.
This is a valid concern. Maybe alternative is to drop mic privacy when running the ztest?
Some small fixes picked up by the audio ztest UTs.