linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ptp: ptp_clockmatrix: initialize variables
@ 2020-10-11 20:09 trix
  2020-10-12 22:01 ` Richard Cochran
  0 siblings, 1 reply; 4+ messages in thread
From: trix @ 2020-10-11 20:09 UTC (permalink / raw)
  To: richardcochran, natechancellor, ndesaulniers
  Cc: netdev, linux-kernel, clang-built-linux, Tom Rix

From: Tom Rix <trix@redhat.com>

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.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/ptp/ptp_clockmatrix.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/ptp/ptp_clockmatrix.c b/drivers/ptp/ptp_clockmatrix.c
index e020faff7da5..47e5e62da5d2 100644
--- a/drivers/ptp/ptp_clockmatrix.c
+++ b/drivers/ptp/ptp_clockmatrix.c
@@ -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);
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ptp: ptp_clockmatrix: initialize variables
  2020-10-11 20:09 [PATCH] ptp: ptp_clockmatrix: initialize variables trix
@ 2020-10-12 22:01 ` Richard Cochran
  2020-10-13  4:07   ` Tom Rix
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Cochran @ 2020-10-12 22:01 UTC (permalink / raw)
  To: trix
  Cc: natechancellor, ndesaulniers, netdev, linux-kernel, clang-built-linux

On Sun, Oct 11, 2020 at 01:09:55PM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> 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.

So why not check the return status?

Your patch papers over the issue.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ptp: ptp_clockmatrix: initialize variables
  2020-10-12 22:01 ` Richard Cochran
@ 2020-10-13  4:07   ` Tom Rix
  2020-10-13 12:40     ` Richard Cochran
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Rix @ 2020-10-13  4:07 UTC (permalink / raw)
  To: Richard Cochran
  Cc: natechancellor, ndesaulniers, netdev, linux-kernel, clang-built-linux


On 10/12/20 3:01 PM, Richard Cochran wrote:
> On Sun, Oct 11, 2020 at 01:09:55PM -0700, trix@redhat.com wrote:
>> From: Tom Rix <trix@redhat.com>
>>
>> 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.
> 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

>
> Your patch papers over the issue.
>
> Thanks,
> Richard
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ptp: ptp_clockmatrix: initialize variables
  2020-10-13  4:07   ` Tom Rix
@ 2020-10-13 12:40     ` Richard Cochran
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Cochran @ 2020-10-13 12:40 UTC (permalink / raw)
  To: Tom Rix
  Cc: natechancellor, ndesaulniers, netdev, linux-kernel, clang-built-linux

On Mon, Oct 12, 2020 at 09:07:30PM -0700, Tom Rix wrote:
> calling function is a print information only function that returns void.

That is fine.

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-13 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-11 20:09 [PATCH] ptp: ptp_clockmatrix: initialize variables trix
2020-10-12 22:01 ` Richard Cochran
2020-10-13  4:07   ` Tom Rix
2020-10-13 12:40     ` Richard Cochran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).