Skip to content

Commit 7808e69

Browse files
committed
✨ Add check for module ID limit
Problem: - The MIPI-SyST spec allows 7 bits for the module ID field. A codebase could accidentally exceed this limit, leading to unpredictable effects. Solution: - Check the max value of a module is not exceeded. - Allow the max value to be customized so that alternative backends can provide alternative limits.
1 parent 3232be1 commit 7808e69

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cmake/string_catalog.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ function(gen_str_catalog)
99
CLIENT_NAME
1010
VERSION
1111
GUID_ID
12-
GUID_MASK)
12+
GUID_MASK
13+
MODULE_ID_MAX)
1314
set(multiValueArgs INPUT_JSON INPUT_LIBS INPUT_HEADERS STABLE_JSON)
1415
cmake_parse_arguments(SC "${options}" "${oneValueArgs}" "${multiValueArgs}"
1516
${ARGN})
@@ -63,6 +64,9 @@ function(gen_str_catalog)
6364
if(SC_GUID_MASK)
6465
set(GUID_MASK_ARG --guid_mask ${SC_GUID_MASK})
6566
endif()
67+
if(SC_MODULE_ID_MAX)
68+
set(MODULE_ID_MAX_ARG --module_id_max ${SC_MODULE_ID_MAX})
69+
endif()
6670
if(NOT SC_GEN_STR_CATALOG)
6771
set(SC_GEN_STR_CATALOG ${GEN_STR_CATALOG})
6872
endif()
@@ -75,7 +79,7 @@ function(gen_str_catalog)
7579
--cpp_output ${SC_OUTPUT_CPP} --json_output ${SC_OUTPUT_JSON}
7680
--xml_output ${SC_OUTPUT_XML} --stable_json ${STABLE_JSON}
7781
${FORGET_ARG} ${CLIENT_NAME_ARG} ${VERSION_ARG} ${GUID_ID_ARG}
78-
${GUID_MASK_ARG}
82+
${GUID_MASK_ARG} ${MODULE_ID_MAX_ARG}
7983
DEPENDS ${UNDEFS} ${INPUT_JSON} ${SC_GEN_STR_CATALOG} ${STABLE_JSON}
8084
COMMAND_EXPAND_LISTS)
8185
if(SC_OUTPUT_LIB)

tools/gen_str_catalog.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ def write_xml(
308308
xf.write(xml_string)
309309

310310

311+
def check_module_limit(modules, max):
312+
for m in modules.values():
313+
if m["id"] > max:
314+
raise Exception(
315+
f"Module ({m}) assigned value exceeds the module ID max ({max})."
316+
)
317+
318+
311319
def parse_cmdline():
312320
parser = argparse.ArgumentParser()
313321
parser.add_argument(
@@ -379,6 +387,12 @@ def parse_cmdline():
379387
action="store_true",
380388
help="When on, stable IDs from a previous run are forgotten. By default, those strings are remembered in the output so that they will not be reused in future.",
381389
)
390+
parser.add_argument(
391+
"--module_id_max",
392+
type=int,
393+
default=127,
394+
help="The maximum value of a module ID.",
395+
)
382396
return parser.parse_args()
383397

384398

@@ -415,6 +429,8 @@ def main():
415429
messages=stable_catalog["messages"], modules=stable_catalog["modules"]
416430
)
417431

432+
check_module_limit(modules, args.module_id_max)
433+
418434
if args.json_output is not None:
419435
write_json(messages, modules, args.json_input, args.json_output, stable_output)
420436

0 commit comments

Comments
 (0)