module: cadence / ipc4: Fix memory leak of notification IPC message#10798
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a potential memory leak in the IPC4 Cadence module’s EOS (DRAIN/EOL) notification path by allocating a reusable IPC notification message once during module init and freeing it during module teardown, instead of allocating a new message on each notification send.
Changes:
- Add a persistent
struct ipc_msg *to Cadence codec private data (IPC4) to hold a notification template for the module lifetime. - Allocate/initialize the notification IPC message during
cadence_codec_init()and reuse it incadence_codec_process()when EOS is reached. - Free the allocated IPC message on init error paths and in a new IPC4-specific
.freeimplementation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/include/sof/audio/module_adapter/module/cadence.h | Adds an IPC4-only struct ipc_msg *msg field (with forward declaration) to store the reusable notification message. |
| src/audio/module_adapter/module/cadence_ipc4.c | Introduces notification message init helper, reuses the message on EOS, and frees it via IPC4-specific module free path. |
|
|
||
| static struct ipc_msg *cadence_codec_notification_init(struct processing_module *mod) | ||
| { | ||
| struct cadence_codec_data *cd = module_get_private_data(mod); |
There was a problem hiding this comment.
it is a leftover from previous version when I did the assignment in the function (and returning int error code), I'll remove it in v2
Each notification that that is sent by the module could cause a memory leak in theory. Notification is only sent in case of DRAIN or EOL and multiple notification sending will be blocked by the eos_notification_sent flag. Since pipelines cannot recover from EOS state, this is theoretical until that is fixed, but it is a bug in the code never the less. Follow the example of other modules and store and allocate the notification message for the lifetime of the module to manage the allocation properly. Fixes: f6cfc4c ("module: cadence / ipc4: Support for EOS handling and notification to host") Reported-by: Jyri Sarha <jyri.sarha@linux.intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
d3ff967 to
2ca80d4
Compare
|
Changes since v1:
|
|
SOFCI TEST |
|
rerun ci - looks like build may got stuck. |
|
Intel internal CI fail do an infra issue. |
|
@lrudyX good to merge ? |
| primary.r.notif_type = SOF_IPC4_MODULE_NOTIFICATION; | ||
| primary.r.type = SOF_IPC4_GLB_NOTIFICATION; | ||
| primary.r.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST; | ||
| primary.r.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG; |
There was a problem hiding this comment.
I hope the compiler is smart enough to make this compile-time, otherwise it could be forced by
union ipc4_notification_header primary = {
.r = {
.notif_type = SOF_IPC4_MODULE_NOTIFICATION,
.type = SOF_IPC4_GLB_NOTIFICATION,
.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST,
.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG,
},
};
There was a problem hiding this comment.
Not a blocker, but can be revisited.
Each notification that that is sent by the module could cause a memory leak in theory.
Notification is only sent in case of DRAIN or EOL and multiple notification sending will be blocked by the eos_notification_sent flag. Since pipelines cannot recover from EOS state, this is theoretical until that is fixed, but it is a bug in the code never the less.
Follow the example of other modules and store and allocate the notification message for the lifetime of the module to manage the allocation properly.
Fixes: f6cfc4c ("module: cadence / ipc4: Support for EOS handling and notification to host")
Reported-by: Jyri Sarha jyri.sarha@linux.intel.com