Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware_loader: Strip off \n from customized path

Having helped an user recently figure out why the customized path being
specified was not taken into account landed on a subtle difference
between using:

echo "/xyz/firmware" > /sys/module/firmware_class/parameters/path

which inserts an additional newline which is passed as is down to
fw_get_filesystem_firmware() and ultimately kernel_read_file_from_path()
and fails.

Strip off \n from the customized firmware path such that users do not
run into these hard to debug situations.

Link: https://lore.kernel.org/all/20230402135423.3235-1-f.fainelli@gmail.com/
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20230413191757.1949088-1-f.fainelli@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Florian Fainelli and committed by
Greg Kroah-Hartman
495ff363 a7b3a470

+13 -4
+13 -4
drivers/base/firmware_loader/main.c
··· 493 493 const void *in_buffer)) 494 494 { 495 495 size_t size; 496 - int i, len; 496 + int i, len, maxlen = 0; 497 497 int rc = -ENOENT; 498 - char *path; 498 + char *path, *nt = NULL; 499 499 size_t msize = INT_MAX; 500 500 void *buffer = NULL; 501 501 ··· 518 518 if (!fw_path[i][0]) 519 519 continue; 520 520 521 - len = snprintf(path, PATH_MAX, "%s/%s%s", 522 - fw_path[i], fw_priv->fw_name, suffix); 521 + /* strip off \n from customized path */ 522 + maxlen = strlen(fw_path[i]); 523 + if (i == 0) { 524 + nt = strchr(fw_path[i], '\n'); 525 + if (nt) 526 + maxlen = nt - fw_path[i]; 527 + } 528 + 529 + len = snprintf(path, PATH_MAX, "%.*s/%s%s", 530 + maxlen, fw_path[i], 531 + fw_priv->fw_name, suffix); 523 532 if (len >= PATH_MAX) { 524 533 rc = -ENAMETOOLONG; 525 534 break;