Skip to contentSkip to conversation

igc: return an error if the mac type is unknown in igc_ptp_systim_to_hwtstamp()

PATCH In review Tom Rix 4 participants 4 messages Jan 14, 2023 – Jan 23, 2023

Subsystems (3)
lore
Share & tools
lore

Tom Rix

author
#0 lore raw

PATCH 1/1 igc: return an error if the mac type is unknown in igc_ptp_systim_to_hwtstamp()

clang static analysis reports drivers/net/ethernet/intel/igc/igc_ptp.c:673:3: warning: The left operand of
'+' is a garbage value [core.UndefinedBinaryOperatorResult]
ktime_add_ns(shhwtstamps.hwtstamp, adjust);
^ ~~~~~~~~~~~~~~~~~~~~

igc_ptp_systim_to_hwtstamp() silently returns without setting the hwtstamp if the mac type is unknown. This should be treated as an error.

Fixes 81b055205e8b ("igc: Add support for RX timestamping")
---
 drivers/net/ethernet/intel/igc/igc_ptp.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/igc/igc_ptp.c +9 -5
index c34734d432e0..4e10ced736db 100644
@@ -417,10 +417,12 @@ static int igc_ptp_verify_pin(struct ptp_clock_info *ptp, unsigned int pin,
  *
  * We need to convert the system time value stored in the RX/TXSTMP registers
  * into a hwtstamp which can be used by the upper level timestamping functions.
+ *
+ * Returns 0 on success.
  **/
-static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
-				       struct skb_shared_hwtstamps *hwtstamps,
-				       u64 systim)
+static int igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
+				      struct skb_shared_hwtstamps *hwtstamps,
+				      u64 systim)
 {
 	switch (adapter->hw.mac.type) {
 	case igc_i225:
@@ -430,8 +432,9 @@ static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
 						systim & 0xFFFFFFFF);
 		break;
 	default:
-		break;
+		return -EINVAL;
 	}
+	return 0;
 }
 
 /**
@@ -652,7 +655,8 @@ static void igc_ptp_tx_hwtstamp(struct igc_adapter *adapter)
 
 	regval = rd32(IGC_TXSTMPL);
 	regval |= (u64)rd32(IGC_TXSTMPH) << 32;
-	igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
+	if (igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval))
+		return;
 
 	switch (adapter->link_speed) {
 	case SPEED_10:
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Tom Rix

clang static analysis reports drivers/net/ethernet/intel/igc/igc_ptp.c:673:3: warning: The left operand of
'+' is a garbage value [core.UndefinedBinaryOperatorResult]

   ktime_add_ns(shhwtstamps.hwtstamp, adjust);
   ^            ~~~~~~~~~~~~~~~~~~~~

igc_ptp_systim_to_hwtstamp() silently returns without setting the hwtstamp if the mac type is unknown. This should be treated as an error.

Fixes 81b055205e8b ("igc: Add support for RX timestamping")
Acked-by on v1 1/1
#2 lore raw
In reply to Tom Rix
Quoted 47 lines · Tom Rix

clang static analysis reports drivers/net/ethernet/intel/igc/igc_ptp.c:673:3: warning: The left operand of
'+' is a garbage value [core.UndefinedBinaryOperatorResult]

    ktime_add_ns(shhwtstamps.hwtstamp, adjust);
    ^            ~~~~~~~~~~~~~~~~~~~~

igc_ptp_systim_to_hwtstamp() silently returns without setting the hwtstamp if the mac type is unknown. This should be treated as an error.

Fixes 81b055205e8b ("igc: Add support for RX timestamping")
---
  drivers/net/ethernet/intel/igc/igc_ptp.c | 14 +++++++++-----
  1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/igc/igc_ptp.c +7 -4
index c34734d432e0..4e10ced736db 100644
@@ -417,10 +417,12 @@ static int igc_ptp_verify_pin(struct ptp_clock_info *ptp, unsigned int pin,
   *
   * We need to convert the system time value stored in the RX/TXSTMP registers
   * into a hwtstamp which can be used by the upper level timestamping functions.
+ *
+ * Returns 0 on success.
   **/
-static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
-				       struct skb_shared_hwtstamps *hwtstamps,
-				       u64 systim)
+static int igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
+				      struct skb_shared_hwtstamps *hwtstamps,
+				      u64 systim)
  {
  	switch (adapter->hw.mac.type) {
  	case igc_i225:
@@ -430,8 +432,9 @@ static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
  						systim & 0xFFFFFFFF);
  		break;
  	default:
-		break;
+		return -EINVAL;
  	}
+	return 0;
  }
 
  /**

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_tx_hwtstamp(struct igc_adapter *adapter) · line 662

Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +2 -1
@@ -652,7 +655,8 @@ static void igc_ptp_tx_hwtstamp(struct igc_adapter *adapter)
 
  	regval = rd32(IGC_TXSTMPL);
  	regval |= (u64)rd32(IGC_TXSTMPH) << 32;
-	igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
+	if (igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval))
+		return;
 
  	switch (adapter->link_speed) {
  	case SPEED_10:
Tested-by on v1 1/1
#3 lore raw
In reply to Tom Rix
Quoted 6 lines · Tom Rix

clang static analysis reports drivers/net/ethernet/intel/igc/igc_ptp.c:673:3: warning: The left operand of
'+' is a garbage value [core.UndefinedBinaryOperatorResult]

    ktime_add_ns(shhwtstamps.hwtstamp, adjust);
    ^            ~~~~~~~~~~~~~~~~~~~~
Quoted 8 lines

igc_ptp_systim_to_hwtstamp() silently returns without setting the hwtstamp if the mac type is unknown. This should be treated as an error.

Fixes 81b055205e8b ("igc: Add support for RX timestamping")
---
  drivers/net/ethernet/intel/igc/igc_ptp.c | 14 +++++++++-----
  1 file changed, 9 insertions(+), 5 deletions(-)