summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Dooley <[email protected]>2025-07-07 13:13:33 +0100
committerLeo Yu-Chi Liang <[email protected]>2025-07-17 14:37:26 +0800
commitb052fba5993e7ee3f2af844467f682a0d8aa9515 (patch)
treeb1141207541b1e96465dfe53a0511c4d98ff54c6
parent3b4604a40b9fd61b87e9d059fc56f04d36f1a380 (diff)
board: mpfs_icicle: fix board_fit_config_name_match()
The loop in the icicle implementation of board_fit_config_name_match() runs strtok() to split off the vendor portion of the compatible string using , as the delimiter. strtok() modifies a string in place, so where the first config and compatible do not match, the compatible has been modified by the time the loop hits the second iteration. Since stringlists in dt land are null separated strings, the nulls strtok() inserts to replace the delimiter increase the number of strings in the compatible list. When the second iteration of the loop calls fdt_stringlist_get(), it gets the vendorless portion of the first compatible string, rather than the second compatible string. Copy each compatible before calling strtok() to avoid this problem. The temporary string the compatible is copied to is statically allocated, as attempts to dynamically allocate it at this stage of boot were met with "alloc space exhausted" errors. Fixes: 7c16ebba1ed ("board: mpfs_icicle: implement board_fdt_blob_setup()/board_fit_config_name_match()") Signed-off-by: Conor Dooley <[email protected]> Reviewed-by: Leo Yu-Chi Liang <[email protected]>
-rw-r--r--board/microchip/mpfs_icicle/mpfs_icicle.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/board/microchip/mpfs_icicle/mpfs_icicle.c b/board/microchip/mpfs_icicle/mpfs_icicle.c
index 6b6984eae3f..ba622e38ee5 100644
--- a/board/microchip/mpfs_icicle/mpfs_icicle.c
+++ b/board/microchip/mpfs_icicle/mpfs_icicle.c
@@ -73,13 +73,22 @@ int board_fit_config_name_match(const char *name)
for (int i = 0; i < list_len; i++) {
int len, match;
const char *compat;
+ char copy[64];
char *devendored;
compat = fdt_stringlist_get(fdt, 0, "compatible", i, &len);
if (!compat)
return -EINVAL;
- strtok((char *)compat, ",");
+ /*
+ * The naming scheme for compatibles doesn't produce anything
+ * close to this long.
+ */
+ if (len >= 64)
+ return -EINVAL;
+
+ strncpy(copy, compat, 64);
+ strtok(copy, ",");
devendored = strtok(NULL, ",");
if (!devendored)