Skip to content

Commit e4355e3

Browse files
KAGA-KOKOkuba-moo
authored andcommitted
ptp: Split out PTP_SYS_OFFSET_PRECISE ioctl code
Continue the ptp_ioctl() cleanup by splitting out the PTP_SYS_OFFSET_PRECISE ioctl code into a helper function. No functional change intended. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Vadim Fedorenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 47aaa73 commit e4355e3

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,40 @@ static long ptp_enable_pps(struct ptp_clock *ptp, bool enable)
290290
return ops->enable(ops, &req, enable);
291291
}
292292

293+
static long ptp_sys_offset_precise(struct ptp_clock *ptp, void __user *arg)
294+
{
295+
struct ptp_sys_offset_precise precise_offset;
296+
struct system_device_crosststamp xtstamp;
297+
struct timespec64 ts;
298+
int err;
299+
300+
if (!ptp->info->getcrosststamp)
301+
return -EOPNOTSUPP;
302+
303+
err = ptp->info->getcrosststamp(ptp->info, &xtstamp);
304+
if (err)
305+
return err;
306+
307+
memset(&precise_offset, 0, sizeof(precise_offset));
308+
ts = ktime_to_timespec64(xtstamp.device);
309+
precise_offset.device.sec = ts.tv_sec;
310+
precise_offset.device.nsec = ts.tv_nsec;
311+
ts = ktime_to_timespec64(xtstamp.sys_realtime);
312+
precise_offset.sys_realtime.sec = ts.tv_sec;
313+
precise_offset.sys_realtime.nsec = ts.tv_nsec;
314+
ts = ktime_to_timespec64(xtstamp.sys_monoraw);
315+
precise_offset.sys_monoraw.sec = ts.tv_sec;
316+
precise_offset.sys_monoraw.nsec = ts.tv_nsec;
317+
318+
return copy_to_user(arg, &precise_offset, sizeof(precise_offset)) ? -EFAULT : 0;
319+
}
320+
293321
long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
294322
unsigned long arg)
295323
{
296324
struct ptp_clock *ptp =
297325
container_of(pccontext->clk, struct ptp_clock, clock);
298326
struct ptp_sys_offset_extended *extoff = NULL;
299-
struct ptp_sys_offset_precise precise_offset;
300-
struct system_device_crosststamp xtstamp;
301327
struct ptp_clock_info *ops = ptp->info;
302328
struct ptp_sys_offset *sysoff = NULL;
303329
struct timestamp_event_queue *tsevq;
@@ -340,28 +366,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
340366

341367
case PTP_SYS_OFFSET_PRECISE:
342368
case PTP_SYS_OFFSET_PRECISE2:
343-
if (!ptp->info->getcrosststamp) {
344-
err = -EOPNOTSUPP;
345-
break;
346-
}
347-
err = ptp->info->getcrosststamp(ptp->info, &xtstamp);
348-
if (err)
349-
break;
350-
351-
memset(&precise_offset, 0, sizeof(precise_offset));
352-
ts = ktime_to_timespec64(xtstamp.device);
353-
precise_offset.device.sec = ts.tv_sec;
354-
precise_offset.device.nsec = ts.tv_nsec;
355-
ts = ktime_to_timespec64(xtstamp.sys_realtime);
356-
precise_offset.sys_realtime.sec = ts.tv_sec;
357-
precise_offset.sys_realtime.nsec = ts.tv_nsec;
358-
ts = ktime_to_timespec64(xtstamp.sys_monoraw);
359-
precise_offset.sys_monoraw.sec = ts.tv_sec;
360-
precise_offset.sys_monoraw.nsec = ts.tv_nsec;
361-
if (copy_to_user((void __user *)arg, &precise_offset,
362-
sizeof(precise_offset)))
363-
err = -EFAULT;
364-
break;
369+
return ptp_sys_offset_precise(ptp, argptr);
365370

366371
case PTP_SYS_OFFSET_EXTENDED:
367372
case PTP_SYS_OFFSET_EXTENDED2:

0 commit comments

Comments
 (0)