From e5a7c4f0a6cbda14aa1be53b0f94a23528ae496a Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 11 Sep 2026 12:15:55 +0200 Subject: [PATCH 1/2] script: add a script to add missing comments to #endif Add a script to add missing comments after #endif and #else. Signed-off-by: Guennadi Liakhovetski --- scripts/add-endif-comments.py | 242 ++++++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100755 scripts/add-endif-comments.py diff --git a/scripts/add-endif-comments.py b/scripts/add-endif-comments.py new file mode 100755 index 000000000000..a2a668adec4d --- /dev/null +++ b/scripts/add-endif-comments.py @@ -0,0 +1,242 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +"""Add missing '/* CONDITION */' comments to preprocessor #endif (and +optionally #else) lines that are far away from their matching #if / +#ifdef / #ifndef. + +SOF style tags long conditional blocks like this: + + #if FOO + ... + #endif /* FOO */ + +This script finds #endif lines without such a trailing comment whose +matching #if/#ifdef/#ifndef is more than --threshold lines away, and +appends the comment. Nested conditionals are handled recursively. + +Usage: + scripts/add-endif-comments.py [--threshold N] [--else] [--apply] PATH... + +By default the script only prints a unified diff of what it would +change (dry run). Pass --apply to modify files in place. +""" + +import argparse +import difflib +import re +import sys +from pathlib import Path + +DEFAULT_THRESHOLD = 15 +DEFAULT_EXTENSIONS = {".c", ".h", ".cpp", ".hpp", ".cc", ".hh"} +SKIP_DIRS = {".git"} + +IF_RE = re.compile(r'^\s*#\s*(if|ifdef|ifndef)\b(.*)$') +ELIF_RE = re.compile(r'^\s*#\s*elif\b') +ELSE_RE = re.compile(r'^\s*#\s*else\b') +ENDIF_RE = re.compile(r'^\s*#\s*endif\b') +COMMENT_RE = re.compile(r'/\*|//') + + +def compute_comment_state(lines): + """Return a list, parallel to lines, telling whether each line starts + inside an unterminated /* */ block comment. Used so that #if-like text + inside a comment is never mistaken for a real directive.""" + states = [] + in_block_comment = False + for line in lines: + states.append(in_block_comment) + i, length = 0, len(line) + in_string = in_char = False + while i < length: + if in_block_comment: + end = line.find('*/', i) + if end == -1: + break + in_block_comment = False + i = end + 2 + continue + c = line[i] + if in_string: + i += 2 if c == '\\' else 1 + if c == '"': + in_string = False + continue + if in_char: + i += 2 if c == '\\' else 1 + if c == "'": + in_char = False + continue + if c == '"': + in_string = True + elif c == "'": + in_char = True + elif c == '/' and i + 1 < length: + nxt = line[i + 1] + if nxt == '*': + in_block_comment = True + i += 2 + continue + if nxt == '/': + break + i += 1 + return states + + +def format_condition(text): + """Normalize a raw #if/#ifdef/#ifndef argument into comment text.""" + text = re.sub(r'/\*.*?\*/', '', text) + text = re.sub(r'//.*$', '', text) + return re.sub(r'\s+', ' ', text).strip() + + +def join_continuation(lines, i): + """Join a directive line with any backslash-continued lines that follow. + Returns (joined_text, index_of_last_physical_line).""" + parts = [lines[i].rstrip('\n')] + j = i + while parts[-1].rstrip().endswith('\\') and j + 1 < len(lines): + j += 1 + parts.append(lines[j].rstrip('\n')) + joined = ' '.join(p.rstrip().rstrip('\\').strip() for p in parts) + return joined, j + + +def has_trailing_comment(line): + return bool(COMMENT_RE.search(line)) + + +def append_comment(line, condition): + return f"{line.rstrip(chr(10))} /* {condition} */\n" + + +def process_block(lines, start_idx, comment_state, threshold, do_else, changes): + """Handle the #if/#ifdef/#ifndef block that opens at start_idx. + Recurses into any nested conditional found along the way. + Returns the index of the line right after the matching #endif.""" + match = IF_RE.match(lines[start_idx]) + joined, directive_end = join_continuation(lines, start_idx) + text_match = re.match(r'^\s*#\s*(?:if|ifdef|ifndef)\b(.*)$', joined) + condition = format_condition(text_match.group(1) if text_match else match.group(2)) + + i = directive_end + 1 + n = len(lines) + while i < n: + if comment_state[i]: + i += 1 + continue + line = lines[i] + if IF_RE.match(line): + i = process_block(lines, i, comment_state, threshold, do_else, changes) + continue + if ENDIF_RE.match(line): + distance = i - start_idx + if distance > threshold and not has_trailing_comment(line): + lines[i] = append_comment(line, condition) + changes.append((i + 1, condition)) + return i + 1 + if do_else and ELSE_RE.match(line): + distance = i - start_idx + if distance > threshold and not has_trailing_comment(line): + lines[i] = append_comment(line, condition) + changes.append((i + 1, condition)) + i += 1 + # Reached EOF without a matching #endif (malformed file, or macro + # trickery); nothing more we can do for this block. + return i + + +def process_lines(lines, threshold, do_else): + """Mutates lines in place, returns list of (line_no, condition) changes.""" + comment_state = compute_comment_state(lines) + changes = [] + i, n = 0, len(lines) + while i < n: + if not comment_state[i] and IF_RE.match(lines[i]): + i = process_block(lines, i, comment_state, threshold, do_else, changes) + else: + i += 1 + return changes + + +def iter_source_files(paths, extensions): + for path in paths: + p = Path(path) + if p.is_dir(): + for sub in sorted(p.rglob('*')): + if any(part in SKIP_DIRS for part in sub.parts): + continue + if sub.is_file() and sub.suffix in extensions: + yield sub + elif p.is_file(): + yield p + else: + print(f"warning: {p} not found", file=sys.stderr) + + +def process_file(path, threshold, do_else, apply_changes): + original_text = path.read_text(encoding='utf-8', errors='surrogateescape') + lines = original_text.splitlines(keepends=True) + if lines and not lines[-1].endswith('\n'): + lines[-1] += '\n' + trailing_newline_added = True + else: + trailing_newline_added = False + + changes = process_lines(lines, threshold, do_else) + if not changes: + return changes + + new_text = ''.join(lines) + if trailing_newline_added: + new_text = new_text[:-1] + + if apply_changes: + path.write_text(new_text, encoding='utf-8', errors='surrogateescape') + else: + diff = difflib.unified_diff( + original_text.splitlines(keepends=True), + new_text.splitlines(keepends=True), + fromfile=str(path), tofile=str(path), + ) + sys.stdout.writelines(diff) + return changes + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('paths', nargs='+', help='files or directories to scan') + parser.add_argument('--threshold', type=int, default=DEFAULT_THRESHOLD, + help=f'minimum block length to require a comment (default: {DEFAULT_THRESHOLD})') + parser.add_argument('--else', dest='do_else', action='store_true', + help='also add comments to far-away #else lines') + parser.add_argument('--apply', action='store_true', + help='write changes to disk instead of printing a diff') + parser.add_argument('--ext', action='append', dest='extensions', + help='additional file extension to scan (e.g. --ext .cc), repeatable') + args = parser.parse_args() + + extensions = set(DEFAULT_EXTENSIONS) + if args.extensions: + extensions.update(e if e.startswith('.') else f'.{e}' for e in args.extensions) + + total_changes = 0 + total_files = 0 + for path in iter_source_files(args.paths, extensions): + changes = process_file(path, args.threshold, args.do_else, args.apply) + if changes: + total_files += 1 + total_changes += len(changes) + action = "updated" if args.apply else "would update" + print(f"# {action} {path}: {len(changes)} comment(s)", file=sys.stderr) + + print(f"# total: {total_changes} comment(s) in {total_files} file(s)", file=sys.stderr) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) From d5b40286515b88c3bd3f8ed49b739a3e799c6f52 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 11 Sep 2026 12:21:03 +0200 Subject: [PATCH 2/2] tree-wide: add missing preprocessor comments Use the add-endif-comments.py script to add missing comments to ipc, library_manager and schedule directories under src/. Signed-off-by: Guennadi Liakhovetski --- src/ipc/ipc-common.c | 12 +++++----- src/ipc/ipc3/dai.c | 6 ++--- src/ipc/ipc3/handler.c | 20 ++++++++-------- src/ipc/ipc3/helper.c | 2 +- src/ipc/ipc3/host-page-table.c | 2 +- src/ipc/ipc4/dai.c | 2 +- src/ipc/ipc4/handler-kernel.c | 12 +++++----- src/ipc/ipc4/handler-user.c | 24 +++++++++---------- src/ipc/ipc4/helper.c | 16 ++++++------- src/ipc/ipc4/logging.c | 2 +- src/ipc/ipc4/notification.c | 2 +- src/library_manager/llext_manager.c | 6 ++--- src/schedule/ll_schedule_xtos.c | 6 ++--- src/schedule/zephyr_domain.c | 4 ++-- src/schedule/zephyr_dp_schedule_application.c | 2 +- src/schedule/zephyr_ll.c | 14 +++++------ 16 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/ipc/ipc-common.c b/src/ipc/ipc-common.c index 51f9c50a9817..4f3425334358 100644 --- a/src/ipc/ipc-common.c +++ b/src/ipc/ipc-common.c @@ -336,7 +336,7 @@ void z_vrfy_ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority) z_impl_ipc_msg_send(msg, data, high_priority); } #include -#endif +#endif /* CONFIG_USERSPACE */ void z_impl_ipc_msg_list_remove(struct ipc_msg *msg) { @@ -375,7 +375,7 @@ void z_vrfy_ipc_msg_list_remove(struct ipc_msg *msg) z_impl_ipc_msg_list_remove(msg); } #include -#endif +#endif /* CONFIG_USERSPACE */ #ifdef __ZEPHYR__ static void ipc_work_handler(struct k_work *work) @@ -683,7 +683,7 @@ __cold static void ipc_user_init(void) LOG_WRN("cold rodata partition %#zx @ %#lx add failed: %d", cold_part.size, cold_part.start, ret); } -#endif +#endif /* CONFIG_COLD_STORE_EXECUTE_DRAM */ k_sem_init(ipc_user->sem, 0, 1); @@ -730,7 +730,7 @@ __cold static void ipc_user_init(void) /* Wait for user thread startup — consumes the initial k_sem_give from thread */ k_sem_take(ipc_user->sem, K_FOREVER); } -#else +#else /* CONFIG_SOF_USERSPACE_LL */ static void ipc_user_init(void) { } @@ -768,7 +768,7 @@ __cold int ipc_init(struct sof *sof) return -ENOMEM; } sof->ipc = ipc; -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ ipc->comp_data = sof_heap_alloc(heap, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, SOF_IPC_MSG_MAX_SIZE, 0); @@ -818,7 +818,7 @@ __cold int ipc_init(struct sof *sof) k_thread_resume(thread); k_work_init_delayable(&ipc->z_delayed_work, ipc_work_handler); -#endif +#endif /* __ZEPHYR__ */ ipc_user_init(); diff --git a/src/ipc/ipc3/dai.c b/src/ipc/ipc3/dai.c index af06e21955cd..46d54d2d86e5 100644 --- a/src/ipc/ipc3/dai.c +++ b/src/ipc/ipc3/dai.c @@ -225,7 +225,7 @@ int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev) } } } -#endif +#endif /* defined(CONFIG_AMD) && !defined(CONFIG_SOC_ACP_6_0) */ break; case SOF_DAI_AMD_SDW: #if defined(CONFIG_AMD) && !defined(CONFIG_SOC_ACP_6_0) @@ -265,7 +265,7 @@ int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev) pin_data->instance = DAI_INDEX_INVALID; dev_data->dai_index_ptr = pin_data; } -#endif +#endif /* defined(CONFIG_AMD) && !defined(CONFIG_SOC_ACP_6_0) */ break; case SOF_DAI_MEDIATEK_AFE: break; @@ -390,7 +390,7 @@ void dai_dma_release(struct dai_data *dd, struct comp_dev *dev) dd->chan->dev_data = NULL; dd->chan = NULL; } -#endif +#endif /* CONFIG_ZEPHYR_NATIVE_DRIVERS */ } int dai_config(struct dai_data *dd, struct comp_dev *dev, struct ipc_config_dai *common_config, diff --git a/src/ipc/ipc3/handler.c b/src/ipc/ipc3/handler.c index 5bd5293c61b7..3c7c38f30f15 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -191,7 +191,7 @@ static bool is_hostless_upstream(struct comp_dev *current) return true; } -#endif +#endif /* CONFIG_HOST_PTABLE */ /* allocate a new stream */ static int ipc_stream_pcm_params(uint32_t stream) @@ -305,7 +305,7 @@ static int ipc_stream_pcm_params(uint32_t stream) } pipe_params: -#endif +#endif /* CONFIG_HOST_PTABLE */ /* configure pipeline audio params */ err = pipeline_params(pcm_dev->cd->pipeline, pcm_dev->cd, @@ -694,7 +694,7 @@ static int ipc_pm_context_save(uint32_t header) /* write the context to the host driver */ //mailbox_hostbox_write(0, pm_ctx, sizeof(*pm_ctx)); -#endif +#endif /* !defined(CONFIG_LIBRARY) && !defined(CONFIG_ZEPHYR_POSIX) */ ipc_get()->pm_prepare_D3 = 1; return 0; @@ -866,7 +866,7 @@ static int ipc_dma_trace_config(uint32_t header) /* host buffer size for DMA trace */ dmat->host_size = params.buffer.size; -#endif +#endif /* CONFIG_HOST_PTABLE */ err = dma_trace_enable(dmat); if (err < 0) { @@ -956,7 +956,7 @@ static int ipc_glb_trace_message(uint32_t header) return -EINVAL; } } -#else +#else /* CONFIG_TRACE */ static int ipc_glb_trace_message(uint32_t header) { /* Return success, as the protocol provides no way to inform @@ -965,7 +965,7 @@ static int ipc_glb_trace_message(uint32_t header) */ return 0; } -#endif +#endif /* CONFIG_TRACE */ static int ipc_glb_gdb_debug(uint32_t header) { @@ -1174,14 +1174,14 @@ static int ipc_glb_probe(uint32_t header) return -EINVAL; } } -#else +#else /* CONFIG_PROBE */ static inline int ipc_glb_probe(uint32_t header) { ipc_cmd_err(&ipc_tr, "Probes not enabled by Kconfig."); return -EINVAL; } -#endif +#endif /* CONFIG_PROBE */ /* * Topology IPC Operations. @@ -1490,7 +1490,7 @@ struct ipc_cmd_hdr *ipc_compact_read_msg(void) return NULL; } -#endif +#endif /* CONFIG_CAVS */ /* prepare the message using ABI major layout */ struct ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg) @@ -1539,7 +1539,7 @@ static int ipc_fw_ready(void) * contiguously in the hostbox) */ return platform_boot_complete(0); -#else +#else /* CONFIG_IMX93_A55 */ /* any other platform should not receive SOF_IPC_FW_READY from host */ return -EINVAL; #endif /* CONFIG_IMX93_A55 */ diff --git a/src/ipc/ipc3/helper.c b/src/ipc/ipc3/helper.c index 7fa66228942f..c987000dcd34 100644 --- a/src/ipc/ipc3/helper.c +++ b/src/ipc/ipc3/helper.c @@ -232,7 +232,7 @@ static int comp_specific_builder(struct sof_ipc_comp *comp, config->file.module_header.data = (uint8_t *)proc->data - sizeof(struct ipc_config_process); break; -#endif +#endif /* CONFIG_LIBRARY */ case SOF_COMP_HOST: case SOF_COMP_SG_HOST: if (IPC_TAIL_IS_SIZE_INVALID(*host)) diff --git a/src/ipc/ipc3/host-page-table.c b/src/ipc/ipc3/host-page-table.c index dbd0fd0fe030..8a90c8919a49 100644 --- a/src/ipc/ipc3/host-page-table.c +++ b/src/ipc/ipc3/host-page-table.c @@ -164,7 +164,7 @@ static int ipc_get_page_descriptors(struct sof_dma *dmac, uint8_t *page_table, return ret; } -#else +#else /* CONFIG_ZEPHYR_NATIVE_DRIVERS */ static int ipc_get_page_descriptors(struct dma *dmac, uint8_t *page_table, struct sof_ipc_host_buffer *ring) { diff --git a/src/ipc/ipc4/dai.c b/src/ipc/ipc4/dai.c index c0ed1f52c3a1..997916aa7854 100644 --- a/src/ipc/ipc4/dai.c +++ b/src/ipc/ipc4/dai.c @@ -74,7 +74,7 @@ void dai_set_link_hda_config(uint16_t *link_config, return; } *link_config = link_cfg.full; -#endif +#endif /* ACE_VERSION > ACE_VERSION_1_5 */ } int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void *spec_config) diff --git a/src/ipc/ipc4/handler-kernel.c b/src/ipc/ipc4/handler-kernel.c index f8d340af2e1c..9970904df938 100644 --- a/src/ipc/ipc4/handler-kernel.c +++ b/src/ipc/ipc4/handler-kernel.c @@ -97,7 +97,7 @@ static inline void ipc4_send_reply(struct ipc4_message_reply *reply) ret = memcpy_s(ipc->comp_data, sizeof(*reply), reply, sizeof(*reply)); assert(!ret); } -#else +#else /* CONFIG_LIBRARY */ static inline struct ipc4_message_request *ipc4_get_message_request(void) { /* ignoring _hdr as it does not contain valid data in IPC4/IDC case */ @@ -112,7 +112,7 @@ static inline void ipc4_send_reply(struct ipc4_message_reply *reply) ipc_msg_send(&msg_reply, data, true); } -#endif +#endif /* CONFIG_LIBRARY */ __cold static bool is_any_ppl_active(void) { @@ -186,7 +186,7 @@ void z_vrfy_ipc_compound_post_start(uint32_t msg_id, int ret, bool delayed) z_impl_ipc_compound_post_start(msg_id, ret, delayed); } #include -#endif +#endif /* CONFIG_USERSPACE */ void ipc_compound_msg_done(uint32_t msg_id, int error) { @@ -247,7 +247,7 @@ int z_vrfy_ipc_wait_for_compound_msg(void) } #include #endif -#endif +#endif /* CONFIG_LIBRARY */ #if CONFIG_LIBRARY_MANAGER __cold static int ipc4_load_library(struct ipc4_message_request *ipc4) @@ -266,7 +266,7 @@ __cold static int ipc4_load_library(struct ipc4_message_request *ipc4) return IPC4_SUCCESS; } -#endif +#endif /* CONFIG_LIBRARY_MANAGER */ static int ipc4_process_glb_message(struct ipc4_message_request *ipc4) { @@ -564,7 +564,7 @@ void ipc_send_buffer_status_notify(void) ipc_msg_send(&msg_notify, NULL, true); } -#endif +#endif /* CONFIG_LOG_BACKEND_ADSP_MTRACE */ void z_impl_ipc_msg_reply(struct sof_ipc_reply *reply) { diff --git a/src/ipc/ipc4/handler-user.c b/src/ipc/ipc4/handler-user.c index 5cea1bf7dbe4..c1cca5d7a8b6 100644 --- a/src/ipc/ipc4/handler-user.c +++ b/src/ipc/ipc4/handler-user.c @@ -86,7 +86,7 @@ static inline const struct ipc4_pipeline_set_state_data *ipc4_get_pipeline_data( return ppl_data; } -#endif +#endif /* CONFIG_LIBRARY */ /* * Global IPC Operations. */ @@ -114,7 +114,7 @@ static unsigned int ipc4_user_target_core_module(struct ipc4_message_request *ip return cpu_get_id(); } -#else +#else /* CONFIG_SOF_USERSPACE_LL */ __cold static int ipc4_new_pipeline(struct ipc4_message_request *ipc4) { struct ipc *ipc = ipc_get(); @@ -136,7 +136,7 @@ __cold static int ipc4_delete_pipeline(struct ipc4_message_request *ipc4) return ipc_pipeline_free(ipc, pipe->primary.r.instance_id); } -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ static int ipc4_pcm_params(struct ipc_comp_dev *pcm_dev) { @@ -653,9 +653,9 @@ __cold static int ipc4_process_chain_dma(struct ipc4_message_request *ipc4) return IPC4_INVALID_CHAIN_STATE_TRANSITION; return IPC4_SUCCESS; -#else +#else /* CONFIG_COMP_CHAIN_DMA */ return IPC4_UNAVAILABLE; -#endif +#endif /* CONFIG_COMP_CHAIN_DMA */ } __cold static int ipc4_process_ipcgtw_cmd(struct ipc4_message_request *ipc4) @@ -678,10 +678,10 @@ __cold static int ipc4_process_ipcgtw_cmd(struct ipc4_message_request *ipc4) } return err < 0 ? IPC4_FAILURE : IPC4_SUCCESS; -#else +#else /* CONFIG_IPC4_GATEWAY */ ipc_cmd_err(&ipc_tr, "CONFIG_IPC4_GATEWAY is disabled"); return IPC4_UNAVAILABLE; -#endif +#endif /* CONFIG_IPC4_GATEWAY */ } static int ipc_glb_gdb_debug(struct ipc4_message_request *ipc4) @@ -774,9 +774,9 @@ int ipc4_user_process_glb_message(struct ipc4_message_request *ipc4, } ret = ipc_user_forward_cmd(ipc4->primary.dat, ipc4->extension.dat, ppl->core); } -#else +#else /* CONFIG_SOF_USERSPACE_LL */ ret = ipc4_set_pipeline_state(ipc4); -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ break; case SOF_IPC4_GLB_GET_PIPELINE_STATE: @@ -1599,7 +1599,7 @@ __cold int ipc4_user_process_module_message(struct ipc4_message_request *ipc4, ipc_get()->ipc_user_pdata->init_drv = drv; ret = ipc_user_forward_cmd(ipc4->primary.dat, ipc4->extension.dat, mi->extension.r.core_id); -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ } else { /* * DP module creation starts running in kernel mode and @@ -1659,9 +1659,9 @@ __cold int ipc4_user_process_module_message(struct ipc4_message_request *ipc4, ret = ipc4_get_large_config_module_instance(ipc4); } } -#else +#else /* CONFIG_SOF_USERSPACE_LL */ ret = ipc4_get_large_config_module_instance(ipc4); -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ break; case SOF_IPC4_MOD_LARGE_CONFIG_SET: #ifdef CONFIG_SOF_USERSPACE_LL diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index 6445c834a204..1664c5969464 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -109,7 +109,7 @@ __cold static inline unsigned char *ipc4_get_comp_new_data(void) return (unsigned char *)MAILBOX_HOSTBOX_BASE; } -#endif +#endif /* CONFIG_LIBRARY */ __cold static int ipc4_comp_new_config(struct comp_ipc_config *ipc_config, const struct ipc4_module_init_instance *module_init) @@ -731,7 +731,7 @@ __cold static struct comp_buffer *ipc4_create_buffer(struct comp_dev *src, bool else \ irq_local_enable(flags); \ } while (0) -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ /* Calling both ll_block() and ll_wait_finished_on_core() makes sure LL will not start its * next cycle and its current cycle on specified core has finished. @@ -761,7 +761,7 @@ static int ll_wait_finished_on_core(struct comp_dev *dev) return 0; } -#else +#else /* CONFIG_CROSS_CORE_STREAM */ #if CONFIG_SOF_USERSPACE_LL /* note: cross-core streams are disabled so src_core==dst_core */ @@ -780,7 +780,7 @@ static int ll_wait_finished_on_core(struct comp_dev *dev) #define ll_unblock(src_core, dst_core, flags) irq_local_enable(flags) #endif -#endif +#endif /* CONFIG_CROSS_CORE_STREAM */ /* Only called from ipc4_bind_module_instance(), which is __cold */ __cold int ipc4_comp_connect(struct ipc *ipc, const struct ipc4_module_bind_unbind *bu) @@ -830,7 +830,7 @@ __cold int ipc4_comp_connect(struct ipc *ipc, const struct ipc4_module_bind_unbi dp = NULL; alloc = dp && dp->mod ? dp->mod->priv.resources.alloc : NULL; -#else +#else /* CONFIG_ZEPHYR_DP_SCHEDULER */ alloc = NULL; #endif /* CONFIG_ZEPHYR_DP_SCHEDULER */ @@ -1129,7 +1129,7 @@ __cold int ipc4_comp_disconnect(struct ipc *ipc, const struct ipc4_module_bind_u tr_err(&ipc_tr, "Cross-core binding is disabled"); ll_unblock(src->ipc_config.core, sink->ipc_config.core, flags); return IPC4_FAILURE; -#endif +#endif /* CONFIG_CROSS_CORE_STREAM */ } pipeline_disconnect(src, buffer, PPL_CONN_DIR_COMP_TO_BUFFER); @@ -1222,7 +1222,7 @@ __cold int ipc4_chain_dma_state(struct comp_dev *dev, const struct ipc4_chain_dm } return ret; } -#endif +#endif /* CONFIG_COMP_CHAIN_DMA */ __cold static int ipc4_update_comps_direction(struct ipc *ipc, uint32_t ppl_id) { @@ -1407,7 +1407,7 @@ static const struct comp_driver *ipc4_get_fuzzer_drv(uint32_t module_id) module_id, idx); return NULL; } -#endif +#endif /* defined(CONFIG_ARCH_POSIX_LIBFUZZER) && !defined(RIMAGE_MANIFEST) */ /* * Called from diff --git a/src/ipc/ipc4/logging.c b/src/ipc/ipc4/logging.c index b5361ff5944e..af6845933688 100644 --- a/src/ipc/ipc4/logging.c +++ b/src/ipc/ipc4/logging.c @@ -260,7 +260,7 @@ int ipc4_logging_enable_logs(bool first_block, return IPC4_UNKNOWN_MESSAGE_TYPE; } -#endif +#endif /* CONFIG_LOG_BACKEND_ADSP_MTRACE */ int ipc4_logging_shutdown(void) { diff --git a/src/ipc/ipc4/notification.c b/src/ipc/ipc4/notification.c index 73b44a0665cf..86fb55e4d12f 100644 --- a/src/ipc/ipc4/notification.c +++ b/src/ipc/ipc4/notification.c @@ -113,4 +113,4 @@ static inline bool z_vrfy_send_resource_notif(uint32_t resource_id, uint32_t eve return z_impl_send_resource_notif(resource_id, event_type, resource_type, data, data_size); } #include -#endif +#endif /* CONFIG_USERSPACE */ diff --git a/src/library_manager/llext_manager.c b/src/library_manager/llext_manager.c index 72da2d2a86d5..241e7e45fa6c 100644 --- a/src/library_manager/llext_manager.c +++ b/src/library_manager/llext_manager.c @@ -198,7 +198,7 @@ static int llext_manager_rm_partition(struct k_mem_domain *domain, tr_dbg(&lib_manager_tr, "remove %#zx @ %lx partition", part.size, part.start); return k_mem_domain_remove_partition(domain, &part); } -#endif +#endif /* CONFIG_USERSPACE */ static void llext_manager_unmap_detached_sections(const struct llext_loader *ldr, const struct llext *ext, @@ -230,7 +230,7 @@ static void llext_manager_unmap_detached_sections(const struct llext_loader *ldr ((uint8_t *)region_addr + s_offset), shdr->sh_size, 0); } -#endif +#endif /* CONFIG_MMU */ } #ifdef CONFIG_USERSPACE @@ -1116,7 +1116,7 @@ int llext_manager_rm_domain(const uint32_t component_id, struct k_mem_domain *do return llext_manager_rm_mod_domain(mctx, domain); } -#endif +#endif /* CONFIG_USERSPACE */ int llext_manager_free_module(const uint32_t component_id) { diff --git a/src/schedule/ll_schedule_xtos.c b/src/schedule/ll_schedule_xtos.c index 704a680e144d..08b9a86a25a5 100644 --- a/src/schedule/ll_schedule_xtos.c +++ b/src/schedule/ll_schedule_xtos.c @@ -186,7 +186,7 @@ static inline void dsp_load_check(struct task *task, uint32_t cycles0, uint32_t task->cycles_cnt = 0; } } -#endif +#endif /* CONFIG_SCHEDULE_LOG_CYCLE_STATISTICS */ static void schedule_ll_tasks_execute(struct ll_schedule_data *sch) { @@ -724,7 +724,7 @@ static int reschedule_ll_task(void *data, struct task *task, uint64_t start) return 0; } -#endif +#endif /* CONFIG_SCHEDULE_LL_NO_RESCHEDULE_TASK */ #if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY static void scheduler_free_ll(void *data, uint32_t flags) @@ -742,7 +742,7 @@ static void scheduler_free_ll(void *data, uint32_t flags) irq_local_enable(irq_flags); } -#endif +#endif /* CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY */ static void ll_scheduler_recalculate_tasks(struct ll_schedule_data *sch, struct clock_notify_data *clk_data) diff --git a/src/schedule/zephyr_domain.c b/src/schedule/zephyr_domain.c index c8a9ad760ad4..5ceee36fa98a 100644 --- a/src/schedule/zephyr_domain.c +++ b/src/schedule/zephyr_domain.c @@ -124,7 +124,7 @@ static void zephyr_domain_thread_fn(void *p1, void *p2, void *p3) &zephyr_domain->block_mutex, K_FOREVER); k_mutex_unlock(&zephyr_domain->block_mutex); } -#endif +#endif /* CONFIG_CROSS_CORE_STREAM */ if (dt->handler) dt->handler(dt->arg); @@ -562,7 +562,7 @@ static void zephyr_domain_unblock(struct ll_schedule_domain *domain) k_condvar_broadcast(&zephyr_domain->block_condvar); k_mutex_unlock(&zephyr_domain->block_mutex); } -#endif +#endif /* CONFIG_CROSS_CORE_STREAM */ APP_TASK_DATA static const struct ll_schedule_domain_ops zephyr_domain_ops = { #ifdef CONFIG_SOF_USERSPACE_LL diff --git a/src/schedule/zephyr_dp_schedule_application.c b/src/schedule/zephyr_dp_schedule_application.c index 0cf8c457b9b8..e1d34f0458c8 100644 --- a/src/schedule/zephyr_dp_schedule_application.c +++ b/src/schedule/zephyr_dp_schedule_application.c @@ -689,4 +689,4 @@ void z_vrfy_scheduler_dp_internal_free(struct task *task) return z_impl_scheduler_dp_internal_free(task); } #include -#endif +#endif /* CONFIG_USERSPACE */ diff --git a/src/schedule/zephyr_ll.c b/src/schedule/zephyr_ll.c index 8e55695538ec..1d9c8954f4ac 100644 --- a/src/schedule/zephyr_ll.c +++ b/src/schedule/zephyr_ll.c @@ -87,11 +87,11 @@ void user_ll_assert_locked(int core) assert(core < CONFIG_CORE_COUNT && zephyr_ll_lock_owner[core] == k_current_get()); } -#else +#else /* CONFIG_ASSERT */ static inline void zephyr_ll_lock_acquired(int core) { (void)core; } static inline void zephyr_ll_lock_releasing(int core) { (void)core; } #endif /* CONFIG_ASSERT */ -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ static void zephyr_ll_lock(struct zephyr_ll *sch, uint32_t *flags) { @@ -491,7 +491,7 @@ int z_impl_zephyr_ll_task_sem_alloc(struct task *task) if (ll_tid) k_thread_access_grant(ll_tid, ts->sem); -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ ts->task = task; pdata->sem_p = ts->sem; @@ -557,8 +557,8 @@ static inline int z_vrfy_zephyr_ll_task_sem_free(struct task *task) return z_impl_zephyr_ll_task_sem_free(task); } #include -#endif -#endif +#endif /* CONFIG_USERSPACE */ +#endif /* CONFIG_DYNAMIC_OBJECTS */ /* * This is synchronous - after this returns the object can be destroyed! @@ -682,7 +682,7 @@ static void zephyr_ll_scheduler_free(void *data, uint32_t flags) #endif sof_heap_free(sch->heap, sch); } -#endif +#endif /* CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY */ #if CONFIG_SOF_USERSPACE_LL struct k_thread *zephyr_ll_init_context(void *data, struct task *task) @@ -712,7 +712,7 @@ struct k_thread *zephyr_ll_init_context(void *data, struct task *task) return zephyr_domain_thread_tid(sch->ll_domain); } -#endif +#endif /* CONFIG_SOF_USERSPACE_LL */ static const struct scheduler_ops zephyr_ll_ops = { .schedule_task = zephyr_ll_task_schedule,