@@ -318,16 +318,52 @@ static long ptp_sys_offset_precise(struct ptp_clock *ptp, void __user *arg)
318
318
return copy_to_user (arg , & precise_offset , sizeof (precise_offset )) ? - EFAULT : 0 ;
319
319
}
320
320
321
+ static long ptp_sys_offset_extended (struct ptp_clock * ptp , void __user * arg )
322
+ {
323
+ struct ptp_sys_offset_extended * extoff __free (kfree ) = NULL ;
324
+ struct ptp_system_timestamp sts ;
325
+
326
+ if (!ptp -> info -> gettimex64 )
327
+ return - EOPNOTSUPP ;
328
+
329
+ extoff = memdup_user (arg , sizeof (* extoff ));
330
+ if (IS_ERR (extoff ))
331
+ return PTR_ERR (extoff );
332
+
333
+ if (extoff -> n_samples > PTP_MAX_SAMPLES ||
334
+ extoff -> rsv [0 ] || extoff -> rsv [1 ] ||
335
+ (extoff -> clockid != CLOCK_REALTIME &&
336
+ extoff -> clockid != CLOCK_MONOTONIC &&
337
+ extoff -> clockid != CLOCK_MONOTONIC_RAW ))
338
+ return - EINVAL ;
339
+
340
+ sts .clockid = extoff -> clockid ;
341
+ for (unsigned int i = 0 ; i < extoff -> n_samples ; i ++ ) {
342
+ struct timespec64 ts ;
343
+ int err ;
344
+
345
+ err = ptp -> info -> gettimex64 (ptp -> info , & ts , & sts );
346
+ if (err )
347
+ return err ;
348
+ extoff -> ts [i ][0 ].sec = sts .pre_ts .tv_sec ;
349
+ extoff -> ts [i ][0 ].nsec = sts .pre_ts .tv_nsec ;
350
+ extoff -> ts [i ][1 ].sec = ts .tv_sec ;
351
+ extoff -> ts [i ][1 ].nsec = ts .tv_nsec ;
352
+ extoff -> ts [i ][2 ].sec = sts .post_ts .tv_sec ;
353
+ extoff -> ts [i ][2 ].nsec = sts .post_ts .tv_nsec ;
354
+ }
355
+
356
+ return copy_to_user (arg , extoff , sizeof (* extoff )) ? - EFAULT : 0 ;
357
+ }
358
+
321
359
long ptp_ioctl (struct posix_clock_context * pccontext , unsigned int cmd ,
322
360
unsigned long arg )
323
361
{
324
362
struct ptp_clock * ptp =
325
363
container_of (pccontext -> clk , struct ptp_clock , clock );
326
- struct ptp_sys_offset_extended * extoff = NULL ;
327
364
struct ptp_clock_info * ops = ptp -> info ;
328
365
struct ptp_sys_offset * sysoff = NULL ;
329
366
struct timestamp_event_queue * tsevq ;
330
- struct ptp_system_timestamp sts ;
331
367
struct ptp_clock_time * pct ;
332
368
unsigned int i , pin_index ;
333
369
struct ptp_pin_desc pd ;
@@ -370,39 +406,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
370
406
371
407
case PTP_SYS_OFFSET_EXTENDED :
372
408
case PTP_SYS_OFFSET_EXTENDED2 :
373
- if (!ptp -> info -> gettimex64 ) {
374
- err = - EOPNOTSUPP ;
375
- break ;
376
- }
377
- extoff = memdup_user ((void __user * )arg , sizeof (* extoff ));
378
- if (IS_ERR (extoff )) {
379
- err = PTR_ERR (extoff );
380
- extoff = NULL ;
381
- break ;
382
- }
383
- if (extoff -> n_samples > PTP_MAX_SAMPLES ||
384
- extoff -> rsv [0 ] || extoff -> rsv [1 ] ||
385
- (extoff -> clockid != CLOCK_REALTIME &&
386
- extoff -> clockid != CLOCK_MONOTONIC &&
387
- extoff -> clockid != CLOCK_MONOTONIC_RAW )) {
388
- err = - EINVAL ;
389
- break ;
390
- }
391
- sts .clockid = extoff -> clockid ;
392
- for (i = 0 ; i < extoff -> n_samples ; i ++ ) {
393
- err = ptp -> info -> gettimex64 (ptp -> info , & ts , & sts );
394
- if (err )
395
- goto out ;
396
- extoff -> ts [i ][0 ].sec = sts .pre_ts .tv_sec ;
397
- extoff -> ts [i ][0 ].nsec = sts .pre_ts .tv_nsec ;
398
- extoff -> ts [i ][1 ].sec = ts .tv_sec ;
399
- extoff -> ts [i ][1 ].nsec = ts .tv_nsec ;
400
- extoff -> ts [i ][2 ].sec = sts .post_ts .tv_sec ;
401
- extoff -> ts [i ][2 ].nsec = sts .post_ts .tv_nsec ;
402
- }
403
- if (copy_to_user ((void __user * )arg , extoff , sizeof (* extoff )))
404
- err = - EFAULT ;
405
- break ;
409
+ return ptp_sys_offset_extended (ptp , argptr );
406
410
407
411
case PTP_SYS_OFFSET :
408
412
case PTP_SYS_OFFSET2 :
@@ -527,7 +531,6 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
527
531
}
528
532
529
533
out :
530
- kfree (extoff );
531
534
kfree (sysoff );
532
535
return err ;
533
536
}
0 commit comments