Skip to content

Commit d4d57b5

Browse files
committed
tools/net/ynl: ethtool: fix crash when Hardware Clock info is missing
JIRA: https://issues.redhat.com/browse/RHEL-89014 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: Mohammad Heib <mheib@redhat.com>
1 parent 34100f2 commit d4d57b5

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tools/net/ynl/ethtool.py

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

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

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

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

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

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

0 commit comments

Comments
 (0)