diff mbox series

ice: check the return of ice_ptp_gettimex64

Message ID 20220214143327.2884183-1-trix@redhat.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series ice: check the return of ice_ptp_gettimex64 | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Tom Rix Feb. 14, 2022, 2:33 p.m. UTC
From: Tom Rix <trix@redhat.com>

Clang static analysis reports this issue
time64.h:69:50: warning: The left operand of '+'
  is a garbage value
  set_normalized_timespec64(&ts_delta, lhs.tv_sec + rhs.tv_sec,
                                       ~~~~~~~~~~ ^
In ice_ptp_adjtime_nonatomic(), the timespec64 variable 'now'
is set by ice_ptp_gettimex64().  This function can fail
with -EBUSY, so 'now' can have a gargbage value.
So check the return.

Fixes: 06c16d89d2cb ("ice: register 1588 PTP clock device object for E810 devices")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/net/ethernet/intel/ice/ice_ptp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jacob Keller Feb. 14, 2022, 6:16 p.m. UTC | #1
> -----Original Message-----
> From: trix@redhat.com <trix@redhat.com>
> Sent: Monday, February 14, 2022 6:33 AM
> To: Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; davem@davemloft.net; kuba@kernel.org;
> nathan@kernel.org; ndesaulniers@google.com; Keller, Jacob E
> <jacob.e.keller@intel.com>
> Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; llvm@lists.linux.dev; Tom Rix <trix@redhat.com>
> Subject: [PATCH] ice: check the return of ice_ptp_gettimex64
> 
> From: Tom Rix <trix@redhat.com>
> 
> Clang static analysis reports this issue
> time64.h:69:50: warning: The left operand of '+'
>   is a garbage value
>   set_normalized_timespec64(&ts_delta, lhs.tv_sec + rhs.tv_sec,
>                                        ~~~~~~~~~~ ^
> In ice_ptp_adjtime_nonatomic(), the timespec64 variable 'now'
> is set by ice_ptp_gettimex64().  This function can fail
> with -EBUSY, so 'now' can have a gargbage value.
> So check the return.
> 
> Fixes: 06c16d89d2cb ("ice: register 1588 PTP clock device object for E810 devices")
> Signed-off-by: Tom Rix <trix@redhat.com>

Ahhh yep. Good fix. Thanks!

> ---
>  drivers/net/ethernet/intel/ice/ice_ptp.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c
> b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index ae291d442539..000c39d163a2 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> @@ -1533,9 +1533,12 @@ ice_ptp_settime64(struct ptp_clock_info *info, const
> struct timespec64 *ts)
>  static int ice_ptp_adjtime_nonatomic(struct ptp_clock_info *info, s64 delta)
>  {
>  	struct timespec64 now, then;
> +	int ret;
> 
>  	then = ns_to_timespec64(delta);
> -	ice_ptp_gettimex64(info, &now, NULL);
> +	ret = ice_ptp_gettimex64(info, &now, NULL);
> +	if (ret)
> +		return ret;
>  	now = timespec64_add(now, then);
> 
>  	return ice_ptp_settime64(info, (const struct timespec64 *)&now);
> --
> 2.26.3
G, GurucharanX Feb. 18, 2022, 6:01 p.m. UTC | #2
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> trix@redhat.com
> Sent: Monday, February 14, 2022 8:03 PM
> To: Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; davem@davemloft.net; kuba@kernel.org;
> nathan@kernel.org; ndesaulniers@google.com; Keller, Jacob E
> <jacob.e.keller@intel.com>
> Cc: netdev@vger.kernel.org; llvm@lists.linux.dev; intel-wired-
> lan@lists.osuosl.org; linux-kernel@vger.kernel.org; Tom Rix
> <trix@redhat.com>
> Subject: [Intel-wired-lan] [PATCH] ice: check the return of
> ice_ptp_gettimex64
> 
> From: Tom Rix <trix@redhat.com>
> 
> Clang static analysis reports this issue
> time64.h:69:50: warning: The left operand of '+'
>   is a garbage value
>   set_normalized_timespec64(&ts_delta, lhs.tv_sec + rhs.tv_sec,
>                                        ~~~~~~~~~~ ^ In ice_ptp_adjtime_nonatomic(), the
> timespec64 variable 'now'
> is set by ice_ptp_gettimex64().  This function can fail with -EBUSY, so 'now'
> can have a gargbage value.
> So check the return.
> 
> Fixes: 06c16d89d2cb ("ice: register 1588 PTP clock device object for E810
> devices")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/net/ethernet/intel/ice/ice_ptp.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 

Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
index ae291d442539..000c39d163a2 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -1533,9 +1533,12 @@  ice_ptp_settime64(struct ptp_clock_info *info, const struct timespec64 *ts)
 static int ice_ptp_adjtime_nonatomic(struct ptp_clock_info *info, s64 delta)
 {
 	struct timespec64 now, then;
+	int ret;
 
 	then = ns_to_timespec64(delta);
-	ice_ptp_gettimex64(info, &now, NULL);
+	ret = ice_ptp_gettimex64(info, &now, NULL);
+	if (ret)
+		return ret;
 	now = timespec64_add(now, then);
 
 	return ice_ptp_settime64(info, (const struct timespec64 *)&now);