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

ptp: ocp: Refactor signal_show() and fix %ptT misuse

Refactor signal_show() to avoid sequential calls to sysfs_emit*()
and use the same pattern to get the index of a signal as it's done
in signal_store().

While at it, fix wrong use of %ptT against struct timespec64.
It's kinda lucky that it worked just because the first member
there 64-bit and it's of time64_t type. Now with %ptS it may
be used correctly.

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20251124084816.205035-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Andy Shevchenko and committed by
Jakub Kicinski
622cc66e b796632f

+5 -9
+5 -9
drivers/ptp/ptp_ocp.c
··· 3250 3250 struct dev_ext_attribute *ea = to_ext_attr(attr); 3251 3251 struct ptp_ocp *bp = dev_get_drvdata(dev); 3252 3252 struct ptp_ocp_signal *signal; 3253 + int gen = (uintptr_t)ea->var; 3253 3254 struct timespec64 ts; 3254 - ssize_t count; 3255 - int i; 3256 3255 3257 - i = (uintptr_t)ea->var; 3258 - signal = &bp->signal[i]; 3259 - 3260 - count = sysfs_emit(buf, "%llu %d %llu %d", signal->period, 3261 - signal->duty, signal->phase, signal->polarity); 3256 + signal = &bp->signal[gen]; 3262 3257 3263 3258 ts = ktime_to_timespec64(signal->start); 3264 - count += sysfs_emit_at(buf, count, " %ptT TAI\n", &ts); 3265 3259 3266 - return count; 3260 + return sysfs_emit(buf, "%llu %d %llu %d %ptT TAI\n", 3261 + signal->period, signal->duty, signal->phase, signal->polarity, 3262 + &ts.tv_sec); 3267 3263 } 3268 3264 static EXT_ATTR_RW(signal, signal, 0); 3269 3265 static EXT_ATTR_RW(signal, signal, 1);