lib: Handle empty saved configuration values
PATCH 1/1 lib: Handle empty saved configuration values
From: Andrea Cervesato <[email protected]>
Empty string module parameters return EOF on older kernels, causing fw_load02 to abort with TBROK on v4.4.
Accept empty values while retaining read-error handling and the original errno. Restore empty strings with a NUL byte: an empty write does not invoke the sysfs setter, while a newline would change the saved value.
---
Fix the following behaviour on kernel < 4.14 96802e6b1dbf
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_security.c:115: TINFO: SecureBoot sysfs file not available
tst_security.c:94: TINFO: Unable to determine system lockdown state
tst_security.c:115: TINFO: SecureBoot sysfs file not available
tst_tmpdir.c:309: TINFO: Using /tmp/LTP_fw_ZRzLML as tmpdir (btrfs filesystem) tst_sys_conf.c:103: TBROK: Failed to read anything from '/sys/module/firmware_class/parameters/path': SUCCESS (0)
Summary:
passed 0 failed 0 broken 1 skipped 0 warnings 0 --- lib/tst_sys_conf.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
lib/tst_sys_conf.c +22 -5
@@ -56,6 +56,7 @@ int tst_sys_conf_save(const struct tst_path_val *conf) {char line[PATH_MAX ];int ttype, iret; +int read_err, saved_errno;FILE *fp;void *ret;
@@ -93,14 +94,23 @@ int tst_sys_conf_save(const struct tst_path_val *conf) } ret =fgets (line,sizeof (line), fp); + saved_errno = errno; + read_err =ferror (fp); +fclose (fp);if (ret ==NULL ) { -if (conf->flags &TST_SR_IGNORE_ERR ) -return 1 ; +if (read_err) { +if (conf->flags &TST_SR_IGNORE_ERR ) +return 1 ; + + errno = saved_errno; +tst_brk (TBROK |TERRNO ,"Failed to read anything from '%s'" , + conf->path); + } -tst_brk (TBROK |TERRNO ,"Failed to read anything from '%s'" , - conf->path); +/* Empty string module parameters can return EOF on older kernels. */ + line[0 ] ='\0' ; }tst_sys_conf_save_str (conf->path, line);
@@ -142,7 +152,14 @@ void tst_sys_conf_restore(int verbose)tst_res (TINFO ,"Restoring conf.: %s -> %s\n" , i->path, i->value); } -FILE_PRINTF (i->path,"%s" , i->value); +/* +* A zero-length write does not invoke the sysfs store callback. +* Write a NUL byte to restore an empty string module parameter. +*/ +if (!i->value[0 ]) +FILE_PRINTF (i->path,"%c" ,'\0' ); +else +FILE_PRINTF (i->path,"%s" , i->value); } }
---
base-commit: 0596b09f22f449cb300e8ad2d08d8b186f551a05
change-id: 20260929-fix_fw_load02-6b0305f6bd7b
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Andrea,
Quoted 6 lines
Empty string module parameters return EOF on older kernels, causing
fw_load02to abort with TBROK on v4.4.Accept empty values while retaining read-error handling and the original errno. Restore empty strings with a NUL byte: an empty write does not invoke the sysfs setter, while a newline would change the saved value.
Thanks for the fix, LGTM.
Quoted 3 lines
Signed-off-by Andrea Cervesato <[email protected]>---
Fix the following behaviour on kernel < 4.1496802e6b1dbf
Could you please put kernel version and git hash to the commit message?
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
one suggestion below.
Quoted 61 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Empty string module parameters return EOF on older kernels, causing
fw_load02to abort with TBROK on v4.4.Accept empty values while retaining read-error handling and the original errno. Restore empty strings with a NUL byte: an empty write does not invoke the sysfs setter, while a newline would change the saved value.
Signed-off-by Andrea Cervesato <[email protected]>---
Fix the following behaviour on kernel < 4.1496802e6b1dbftst_kconfig.c:90: TINFO: Parsing kernel config '
/proc/config.gz'
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_security.c:115: TINFO: SecureBoot sysfs file not available
tst_security.c:94: TINFO: Unable to determine system lockdown state
tst_security.c:115: TINFO: SecureBoot sysfs file not available
tst_tmpdir.c:309: TINFO: Using/tmp/LTP_fw_ZRzLMLas tmpdir (btrfs filesystem) tst_sys_conf.c:103: TBROK: Failed to read anything from '/sys/module/firmware_class/parameters/path': SUCCESS (0)Summary:
passed 0 failed 0 broken 1 skipped 0 warnings 0 --- lib/tst_sys_conf.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)lib/tst_sys_conf.c +9
-2@@ -56,6 +56,7 @@ int tst_sys_conf_save(const struct tst_path_val *conf) {char line[PATH_MAX ];int ttype, iret; +int read_err, saved_errno;FILE *fp;void *ret;@@ -93,14 +94,23 @@ int tst_sys_conf_save(const struct tst_path_val *conf) } ret =fgets (line,sizeof (line), fp); + saved_errno = errno; + read_err =ferror (fp); +fclose (fp);if (ret ==NULL ) { -if (conf->flags &TST_SR_IGNORE_ERR ) -return 1 ; +if (read_err) { +if (conf->flags &TST_SR_IGNORE_ERR ) +return 1 ; + + errno = saved_errno;
lib/tst_sys_conf.c int tst_sys_conf_save(const struct tst_path_val *conf) · line 115
Quoted 10 lines
lib/tst_sys_conf.c +5
-2+tst_brk (TBROK |TERRNO ,"Failed to read anything from '%s'" , + conf->path); + } -tst_brk (TBROK |TERRNO ,"Failed to read anything from '%s'" , - conf->path); +/* Empty string module parameters can return EOF on older kernels. */ + line[0 ] ='\0' ; }
I think you can drop most of this chunk and do two things instead:
1) char line[PATH_MAX] = {};
2) if (ret == NULL) -> if (read_err).
Signature · 10 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Andrea,
Quoted 1 line · Andrea Cervesato
lib: Handle empty saved configuration values
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp