ptp: ptp_clockmatrix: initialize variables
Subsystems (3)
PATCH 1/1 ptp: ptp_clockmatrix: initialize variables
From: Tom Rix <[email protected]>
Clang static analysis reports this representative problem
ptp_clockmatrix.c:1852:2: warning: 5th function call argument
is an uninitialized value
snprintf(idtcm->version, sizeof(idtcm->version), "%u.%u.%u",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~idtcm_display_version_info() calls several idtcm_read_*'s without checking a return status. Initialize the read variables so if a read fails, a garbage value is not displayed.
--- drivers/ptp/ptp_clockmatrix.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/ptp/ptp_clockmatrix.c +6 -6
@@ -1832,12 +1832,12 @@ static int idtcm_enable_tod(struct idtcm_channel *channel)static void idtcm_display_version_info (struct idtcm *idtcm) { -u8 major; -u8 minor; -u8 hotfix; -u16 product_id; -u8 hw_rev_id; -u8 config_select; +u8 major =0 ; +u8 minor =0 ; +u8 hotfix =0 ; +u16 product_id =0 ; +u8 hw_rev_id =0 ; +u8 config_select =0 ;char *fmt ="%d.%d.%d, Id: 0x%04x HW Rev: %d OTP Config Select: %d\n" ;idtcm_read_major_release (idtcm, &major);
Signature · 1 line
2.18.1
Richard Cochran
maintainerQuoted 11 lines · On Sun, Oct 11, 2020 at 01:09:55PM -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
Clang static analysis reports this representative problem
ptp_clockmatrix.c:1852:2: warning: 5th function call argument
is an uninitialized valuesnprintf(idtcm->version, sizeof(idtcm->version), "%u.%u.%u", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
idtcm_display_version_info()calls several idtcm_read_*'s without checking a return status.
So why not check the return status?
Your patch papers over the issue.
Thanks,
Richard
Quoted 5 lines · Richard Cochran
Quoted 4 lines · On Sun, Oct 11, 2020 at 01:09:55PM -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
Clang static analysis reports this representative problem
Quoted 8 lines
Quoted 7 lines
ptp_clockmatrix.c:1852:2: warning: 5th function call argument
is an uninitialized valuesnprintf(idtcm->version, sizeof(idtcm->version), "%u.%u.%u", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
idtcm_display_version_info()calls several idtcm_read_*'s without checking a return status.So why not check the return status?
calling function is a print information only function that returns void.
I do think not adding error handling is worth it.
I could change the return and then the calls if if you like.
Tom
Quoted 6 lines
Your patch papers over the issue.
Thanks,
Richard
Richard Cochran
maintainerQuoted 1 line · Tom Rix
calling function is a print information only function that returns void.
That is fine.
Quoted 3 lines
I do think not adding error handling is worth it.
I could change the return and then the calls if if you like.
How about printing the version string when readable, and otherwise print an appropriate informative error message?
Thanks,
Richard