Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Signed-off-by: Tom Rix <trix@redhat.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Sasha Neftin <sasha.neftin@intel.com>
Tested-by: Naama Meir <naamax.meir@linux.intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Link: https://lore.kernel.org/r/20230131215437.1528994-1-anthony.l.nguyen@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Tom Rix and committed by
Jakub Kicinski
a2df8463 9c6b9cba

+9 -5
+9 -5
drivers/net/ethernet/intel/igc/igc_ptp.c
··· 417 417 * 418 418 * We need to convert the system time value stored in the RX/TXSTMP registers 419 419 * into a hwtstamp which can be used by the upper level timestamping functions. 420 + * 421 + * Returns 0 on success. 420 422 **/ 421 - static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, 422 - struct skb_shared_hwtstamps *hwtstamps, 423 - u64 systim) 423 + static int igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, 424 + struct skb_shared_hwtstamps *hwtstamps, 425 + u64 systim) 424 426 { 425 427 switch (adapter->hw.mac.type) { 426 428 case igc_i225: ··· 432 430 systim & 0xFFFFFFFF); 433 431 break; 434 432 default: 435 - break; 433 + return -EINVAL; 436 434 } 435 + return 0; 437 436 } 438 437 439 438 /** ··· 655 652 656 653 regval = rd32(IGC_TXSTMPL); 657 654 regval |= (u64)rd32(IGC_TXSTMPH) << 32; 658 - igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval); 655 + if (igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval)) 656 + return; 659 657 660 658 switch (adapter->link_speed) { 661 659 case SPEED_10: