Skip to content

Commit bc7c58f

Browse files
author
Hangbin Liu
committed
tools/net/ynl: ethtool: fix crash when Hardware Clock info is missing
JIRA: https://issues.redhat.com/browse/RHEL-78772 Upstream Status: net.git commit 4537581 commit 4537581 Author: Hangbin Liu <liuhangbin@gmail.com> Date: Thu May 8 03:54:14 2025 +0000 tools/net/ynl: ethtool: fix crash when Hardware Clock info is missing 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> Signed-off-by: Hangbin Liu <haliu@redhat.com>
1 parent 82f03bd commit bc7c58f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tools/net/ynl/pyynl/ethtool.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,24 @@ def main():
338338
print('Capabilities:')
339339
[print(f'\t{v}') for v in bits_to_dict(tsinfo['timestamping'])]
340340

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

343-
print('Hardware Transmit Timestamp Modes:')
344-
[print(f'\t{v}') for v in bits_to_dict(tsinfo['tx-types'])]
343+
if 'tx-types' in tsinfo:
344+
print('Hardware Transmit Timestamp Modes:')
345+
[print(f'\t{v}') for v in bits_to_dict(tsinfo['tx-types'])]
346+
else:
347+
print('Hardware Transmit Timestamp Modes: none')
348+
349+
if 'rx-filters' in tsinfo:
350+
print('Hardware Receive Filter Modes:')
351+
[print(f'\t{v}') for v in bits_to_dict(tsinfo['rx-filters'])]
352+
else:
353+
print('Hardware Receive Filter Modes: none')
345354

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

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

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

0 commit comments

Comments
 (0)