Skip to content

Commit

Permalink
tools/net/ynl: ethtool: fix crash when Hardware Clock info is missing
Browse files Browse the repository at this point in the history
Fix a crash in the ethtool YNL implementation when Hardware Clock information
is not present in the response. This ensures graceful handling of devices or
drivers that do not provide this optional field. e.g.

  Traceback (most recent call last):
    File "/net/tools/net/ynl/pyynl/./ethtool.py", line 438, in <module>
      main()
      ~~~~^^
    File "/net/tools/net/ynl/pyynl/./ethtool.py", line 341, in main
      print(f'PTP Hardware Clock: {tsinfo["phc-index"]}')
                                   ~~~~~~^^^^^^^^^^^^^
  KeyError: 'phc-index'

Fixes: f3d07b0 ("tools: ynl: ethtool testing tool")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250508035414.82974-1-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Hangbin Liu authored and Jakub Kicinski committed May 9, 2025
1 parent 12f4ee3 commit 4537581
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tools/net/ynl/pyynl/ethtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,24 @@ def main():
print('Capabilities:')
[print(f'\t{v}') for v in bits_to_dict(tsinfo['timestamping'])]

print(f'PTP Hardware Clock: {tsinfo["phc-index"]}')
print(f'PTP Hardware Clock: {tsinfo.get("phc-index", "none")}')

print('Hardware Transmit Timestamp Modes:')
[print(f'\t{v}') for v in bits_to_dict(tsinfo['tx-types'])]
if 'tx-types' in tsinfo:
print('Hardware Transmit Timestamp Modes:')
[print(f'\t{v}') for v in bits_to_dict(tsinfo['tx-types'])]
else:
print('Hardware Transmit Timestamp Modes: none')

if 'rx-filters' in tsinfo:
print('Hardware Receive Filter Modes:')
[print(f'\t{v}') for v in bits_to_dict(tsinfo['rx-filters'])]
else:
print('Hardware Receive Filter Modes: none')

print('Hardware Receive Filter Modes:')
[print(f'\t{v}') for v in bits_to_dict(tsinfo['rx-filters'])]
if 'stats' in tsinfo and tsinfo['stats']:
print('Statistics:')
[print(f'\t{k}: {v}') for k, v in tsinfo['stats'].items()]

print('Statistics:')
[print(f'\t{k}: {v}') for k, v in tsinfo['stats'].items()]
return

print(f'Settings for {args.device}:')
Expand Down

0 comments on commit 4537581

Please sign in to comment.