From 5f7a33d8ed445d9af4bd2d36f3d97526cd5dfa7a Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Tue, 30 Dec 2025 07:37:25 +0200 Subject: [PATCH 1/3] Pass down the length of the buffer when calculating firmware paths Stop using sizeof(char*) to get the size of the buffer. Instead pass down the correct length. Also removing the hidden knowledge of the buffer being PATH_LEN bytes. Fixes: 4946411bbb8a ("Use firmware load path from sysfs") Signed-off-by: Dmitry Baryshkov --- pd-mapper.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pd-mapper.c b/pd-mapper.c index 893f8b5..1152bb8 100644 --- a/pd-mapper.c +++ b/pd-mapper.c @@ -193,15 +193,15 @@ static int pd_load_map(const char *file) return 0; } -static int concat_path(char *base_path, char *firmware_path, char *path) +static int concat_path(char *base_path, char *firmware_path, char *path, size_t path_len) { - if ((strlen(base_path) > 0) && (strlen(base_path) + 1 + strlen(firmware_path) + 1 < PATH_MAX)) { + if ((strlen(base_path) > 0) && (strlen(base_path) + 1 + strlen(firmware_path) + 1 < path_len)) { strcpy(path, base_path); strcat(path, "/"); strcat(path, firmware_path); return 0; } else { - warn("Path length exceeded %lu\n", sizeof(path)); + warn("Path length exceeded %lu\n", path_len); } return -1; } @@ -210,7 +210,7 @@ static int concat_path(char *base_path, char *firmware_path, char *path) #define FIRMWARE_BASE "/lib/firmware/" #define FIRMWARE_PARAM_PATH "/sys/module/firmware_class/parameters/path" -static DIR *opendir_firmware(char *firmware_path, char *out_path_opened) +static DIR *opendir_firmware(char *firmware_path, char *out_path_opened, size_t out_path_size) { int ret = 0, n; DIR *fw_dir = NULL; @@ -232,7 +232,7 @@ static DIR *opendir_firmware(char *firmware_path, char *out_path_opened) fw_sysfs_path[n - 1] = '\0'; - ret = concat_path(fw_sysfs_path, firmware_path, out_path_opened); + ret = concat_path(fw_sysfs_path, firmware_path, out_path_opened, out_path_size); if (ret) goto err; @@ -242,7 +242,7 @@ static DIR *opendir_firmware(char *firmware_path, char *out_path_opened) return fw_dir; err: - ret = concat_path(fw_sysfs_path, FIRMWARE_BASE, out_path_opened); + ret = concat_path(fw_sysfs_path, FIRMWARE_BASE, out_path_opened, out_path_size); if (ret) return fw_dir; @@ -321,7 +321,7 @@ static int pd_enumerate_jsons(struct assoc *json_set) firmware_value_copy = strdup(firmware_value); firmware_path = dirname(firmware_value_copy); - fw_dir = opendir_firmware(firmware_path, path); + fw_dir = opendir_firmware(firmware_path, path, sizeof(path)); if (!fw_dir) continue; From 8ce2895666780d0c2e830983d334559df3d797cd Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Tue, 30 Dec 2025 07:43:43 +0200 Subject: [PATCH 2/3] Use correct paths when firmware path isn't set in sysfs Swap arguments to concat_path, passing "/lib/firmware" into the first argument and keeping the second one (firmware-path from remoteproc). Fixes: 4946411bbb8a ("Use firmware load path from sysfs") Signed-off-by: Dmitry Baryshkov --- pd-mapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pd-mapper.c b/pd-mapper.c index 1152bb8..a731672 100644 --- a/pd-mapper.c +++ b/pd-mapper.c @@ -242,7 +242,7 @@ static DIR *opendir_firmware(char *firmware_path, char *out_path_opened, size_t return fw_dir; err: - ret = concat_path(fw_sysfs_path, FIRMWARE_BASE, out_path_opened, out_path_size); + ret = concat_path(FIRMWARE_BASE, firmware_path, out_path_opened, out_path_size); if (ret) return fw_dir; From fbace0b23ef74975bdbd8e10972ba64981e0a9d5 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Tue, 30 Dec 2025 07:45:36 +0200 Subject: [PATCH 3/3] Handle "path not set in sysfs" without extra warnings Stop printing the obscure warning about path being too long when the firmware path isn't set in sysfs. Signed-off-by: Dmitry Baryshkov --- pd-mapper.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pd-mapper.c b/pd-mapper.c index a731672..1167e02 100644 --- a/pd-mapper.c +++ b/pd-mapper.c @@ -195,15 +195,16 @@ static int pd_load_map(const char *file) static int concat_path(char *base_path, char *firmware_path, char *path, size_t path_len) { - if ((strlen(base_path) > 0) && (strlen(base_path) + 1 + strlen(firmware_path) + 1 < path_len)) { - strcpy(path, base_path); - strcat(path, "/"); - strcat(path, firmware_path); - return 0; - } else { + if (strlen(base_path) + 1 + strlen(firmware_path) + 1 >= path_len) { warn("Path length exceeded %lu\n", path_len); + return -1; } - return -1; + + strcpy(path, base_path); + strcat(path, "/"); + strcat(path, firmware_path); + + return 0; } #ifndef ANDROID @@ -230,6 +231,10 @@ static DIR *opendir_firmware(char *firmware_path, char *out_path_opened, size_t goto err; } + /* path not set in sysfs */ + if (n <= 1) + goto err; + fw_sysfs_path[n - 1] = '\0'; ret = concat_path(fw_sysfs_path, firmware_path, out_path_opened, out_path_size);