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

Configure Feed

Select the types of activity you want to include in your feed.

selftests: ptp: treat unsupported PHC operations as skip

Some PTP hardware clock (PHC) devices may return -EOPNOTSUPP for
operations like settime, adjtime, or adjfreq. This commonly occurs
with timestamp-only PHC implementations that don't support full clock
control.

For background, syzbot previously exposed a crash risk when PTP clock
drivers lacked required callbacks[1]. Subsequent work[2] made callback
presence a registration requirement. As a result, some drivers (like
iwlwifi MVM/MLD[3]) now provide stub callbacks that return -EOPNOTSUPP
for unsupported operations.

When phc_ctl encounters such devices, the "Operation not supported"
error should be treated as a skip (device limitation) rather than a
test failure. This patch:
- Adds [SKIP] output handling in log_test()
- Detects "Operation not supported" from phc_ctl and returns ksft_skip
- Returns ksft_skip if all tests are skipped, preventing false-positive
results when testing timestamp-only PHC implementations

Link: https://lore.kernel.org/netdev/20251028043216.1971292-1-junjie.cao@intel.com/ [1]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=dfb073d32cac [2]
Link: https://lore.kernel.org/netdev/20251204123204.9316-1-ziyao@disroot.org/ [3]
Signed-off-by: Junjie Cao <junjie.cao@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260126061532.12532-2-junjie.cao@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Junjie Cao and committed by
Jakub Kicinski
239f09e2 166e664e

+37 -12
+37 -12
tools/testing/selftests/ptp/phc.sh
··· 52 52 53 53 # Exit status to return at the end. Set in case one of the tests fails. 54 54 EXIT_STATUS=0 55 + PASS_COUNT=0 55 56 # Per-test return value. Clear at the beginning of each test. 56 57 RET=0 57 58 ··· 69 68 { 70 69 local test_name=$1 71 70 71 + if [[ $RET -eq $ksft_skip ]]; then 72 + printf "TEST: %-60s [SKIP]\n" "$test_name" 73 + return 0 74 + fi 75 + 72 76 if [[ $RET -ne 0 ]]; then 73 77 EXIT_STATUS=1 74 78 printf "TEST: %-60s [FAIL]\n" "$test_name" 75 79 return 1 76 80 fi 77 81 82 + ((PASS_COUNT++)) 78 83 printf "TEST: %-60s [ OK ]\n" "$test_name" 79 84 return 0 80 85 } ··· 99 92 100 93 settime_do() 101 94 { 102 - local res 95 + local res out 103 96 104 - res=$(phc_ctl $DEV set 0 wait 120.5 get 2> /dev/null \ 105 - | awk '/clock time is/{print $5}' \ 106 - | awk -F. '{print $1}') 97 + out=$(LC_ALL=C phc_ctl $DEV set 0 wait 120.5 get 2>&1) 98 + if [[ $? -ne 0 ]]; then 99 + if echo "$out" | grep -qi "Operation not supported"; then 100 + return $ksft_skip 101 + fi 102 + return 1 103 + fi 104 + res=$(echo "$out" | awk '/clock time is/{print $5}' | awk -F. '{print $1}') 107 105 108 106 (( res == 120 )) 109 107 } 110 108 111 109 adjtime_do() 112 110 { 113 - local res 111 + local res out 114 112 115 - res=$(phc_ctl $DEV set 0 adj 10 get 2> /dev/null \ 116 - | awk '/clock time is/{print $5}' \ 117 - | awk -F. '{print $1}') 113 + out=$(LC_ALL=C phc_ctl $DEV set 0 adj 10 get 2>&1) 114 + if [[ $? -ne 0 ]]; then 115 + if echo "$out" | grep -qi "Operation not supported"; then 116 + return $ksft_skip 117 + fi 118 + return 1 119 + fi 120 + res=$(echo "$out" | awk '/clock time is/{print $5}' | awk -F. '{print $1}') 118 121 119 122 (( res == 10 )) 120 123 } 121 124 122 125 adjfreq_do() 123 126 { 124 - local res 127 + local res out 125 128 126 129 # Set the clock to be 1% faster 127 - res=$(phc_ctl $DEV freq 10000000 set 0 wait 100.5 get 2> /dev/null \ 128 - | awk '/clock time is/{print $5}' \ 129 - | awk -F. '{print $1}') 130 + out=$(LC_ALL=C phc_ctl $DEV freq 10000000 set 0 wait 100.5 get 2>&1) 131 + if [[ $? -ne 0 ]]; then 132 + if echo "$out" | grep -qi "Operation not supported"; then 133 + return $ksft_skip 134 + fi 135 + return 1 136 + fi 137 + res=$(echo "$out" | awk '/clock time is/{print $5}' | awk -F. '{print $1}') 130 138 131 139 (( res == 101 )) 132 140 } ··· 188 166 189 167 tests_run 190 168 169 + if [[ $EXIT_STATUS -eq 0 && $PASS_COUNT -eq 0 ]]; then 170 + exit $ksft_skip 171 + fi 191 172 exit $EXIT_STATUS