@@ -106,8 +106,7 @@ int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin,
106
106
107
107
int ptp_open (struct posix_clock_context * pccontext , fmode_t fmode )
108
108
{
109
- struct ptp_clock * ptp =
110
- container_of (pccontext -> clk , struct ptp_clock , clock );
109
+ struct ptp_clock * ptp = container_of (pccontext -> clk , struct ptp_clock , clock );
111
110
struct timestamp_event_queue * queue ;
112
111
char debugfsname [32 ];
113
112
@@ -536,67 +535,46 @@ __poll_t ptp_poll(struct posix_clock_context *pccontext, struct file *fp,
536
535
ssize_t ptp_read (struct posix_clock_context * pccontext , uint rdflags ,
537
536
char __user * buf , size_t cnt )
538
537
{
539
- struct ptp_clock * ptp =
540
- container_of (pccontext -> clk , struct ptp_clock , clock );
538
+ struct ptp_clock * ptp = container_of (pccontext -> clk , struct ptp_clock , clock );
541
539
struct timestamp_event_queue * queue ;
542
540
struct ptp_extts_event * event ;
543
- int result ;
541
+ ssize_t result ;
544
542
545
543
queue = pccontext -> private_clkdata ;
546
- if (!queue ) {
547
- result = - EINVAL ;
548
- goto exit ;
549
- }
544
+ if (!queue )
545
+ return - EINVAL ;
550
546
551
- if (cnt % sizeof (struct ptp_extts_event ) != 0 ) {
552
- result = - EINVAL ;
553
- goto exit ;
554
- }
547
+ if (cnt % sizeof (* event ) != 0 )
548
+ return - EINVAL ;
555
549
556
550
if (cnt > EXTTS_BUFSIZE )
557
551
cnt = EXTTS_BUFSIZE ;
558
552
559
- cnt = cnt / sizeof (struct ptp_extts_event );
560
-
561
- if (wait_event_interruptible (ptp -> tsev_wq ,
562
- ptp -> defunct || queue_cnt (queue ))) {
553
+ if (wait_event_interruptible (ptp -> tsev_wq , ptp -> defunct || queue_cnt (queue )))
563
554
return - ERESTARTSYS ;
564
- }
565
555
566
- if (ptp -> defunct ) {
567
- result = - ENODEV ;
568
- goto exit ;
569
- }
556
+ if (ptp -> defunct )
557
+ return - ENODEV ;
570
558
571
559
event = kmalloc (EXTTS_BUFSIZE , GFP_KERNEL );
572
- if (!event ) {
573
- result = - ENOMEM ;
574
- goto exit ;
575
- }
560
+ if (!event )
561
+ return - ENOMEM ;
576
562
577
563
scoped_guard (spinlock_irq , & queue -> lock ) {
578
- size_t qcnt = queue_cnt (queue );
579
-
580
- if (cnt > qcnt )
581
- cnt = qcnt ;
564
+ size_t qcnt = min ((size_t )queue_cnt (queue ), cnt / sizeof (* event ));
582
565
583
- for (size_t i = 0 ; i < cnt ; i ++ ) {
566
+ for (size_t i = 0 ; i < qcnt ; i ++ ) {
584
567
event [i ] = queue -> buf [queue -> head ];
585
568
/* Paired with READ_ONCE() in queue_cnt() */
586
569
WRITE_ONCE (queue -> head , (queue -> head + 1 ) % PTP_MAX_TIMESTAMPS );
587
570
}
571
+ cnt = qcnt * sizeof (* event );
588
572
}
589
573
590
- cnt = cnt * sizeof (struct ptp_extts_event );
591
-
592
574
result = cnt ;
593
- if (copy_to_user (buf , event , cnt )) {
575
+ if (copy_to_user (buf , event , cnt ))
594
576
result = - EFAULT ;
595
- goto free_event ;
596
- }
597
577
598
- free_event :
599
578
kfree (event );
600
- exit :
601
579
return result ;
602
580
}
0 commit comments