@@ -110,7 +110,6 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
110
110
container_of (pccontext -> clk , struct ptp_clock , clock );
111
111
struct timestamp_event_queue * queue ;
112
112
char debugfsname [32 ];
113
- unsigned long flags ;
114
113
115
114
queue = kzalloc (sizeof (* queue ), GFP_KERNEL );
116
115
if (!queue )
@@ -122,9 +121,8 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
122
121
}
123
122
bitmap_set (queue -> mask , 0 , PTP_MAX_CHANNELS );
124
123
spin_lock_init (& queue -> lock );
125
- spin_lock_irqsave (& ptp -> tsevqs_lock , flags );
126
- list_add_tail (& queue -> qlist , & ptp -> tsevqs );
127
- spin_unlock_irqrestore (& ptp -> tsevqs_lock , flags );
124
+ scoped_guard (spinlock_irq , & ptp -> tsevqs_lock )
125
+ list_add_tail (& queue -> qlist , & ptp -> tsevqs );
128
126
pccontext -> private_clkdata = queue ;
129
127
130
128
/* Debugfs contents */
@@ -143,15 +141,13 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
143
141
int ptp_release (struct posix_clock_context * pccontext )
144
142
{
145
143
struct timestamp_event_queue * queue = pccontext -> private_clkdata ;
146
- unsigned long flags ;
147
144
struct ptp_clock * ptp =
148
145
container_of (pccontext -> clk , struct ptp_clock , clock );
149
146
150
147
debugfs_remove (queue -> debugfs_instance );
151
148
pccontext -> private_clkdata = NULL ;
152
- spin_lock_irqsave (& ptp -> tsevqs_lock , flags );
153
- list_del (& queue -> qlist );
154
- spin_unlock_irqrestore (& ptp -> tsevqs_lock , flags );
149
+ scoped_guard (spinlock_irq , & ptp -> tsevqs_lock )
150
+ list_del (& queue -> qlist );
155
151
bitmap_free (queue -> mask );
156
152
kfree (queue );
157
153
return 0 ;
@@ -544,8 +540,6 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags,
544
540
container_of (pccontext -> clk , struct ptp_clock , clock );
545
541
struct timestamp_event_queue * queue ;
546
542
struct ptp_extts_event * event ;
547
- unsigned long flags ;
548
- size_t qcnt , i ;
549
543
int result ;
550
544
551
545
queue = pccontext -> private_clkdata ;
@@ -580,21 +574,19 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags,
580
574
goto exit ;
581
575
}
582
576
583
- spin_lock_irqsave (& queue -> lock , flags );
577
+ scoped_guard (spinlock_irq , & queue -> lock ) {
578
+ size_t qcnt = queue_cnt (queue );
584
579
585
- qcnt = queue_cnt (queue );
580
+ if (cnt > qcnt )
581
+ cnt = qcnt ;
586
582
587
- if (cnt > qcnt )
588
- cnt = qcnt ;
589
-
590
- for (i = 0 ; i < cnt ; i ++ ) {
591
- event [i ] = queue -> buf [queue -> head ];
592
- /* Paired with READ_ONCE() in queue_cnt() */
593
- WRITE_ONCE (queue -> head , (queue -> head + 1 ) % PTP_MAX_TIMESTAMPS );
583
+ for (size_t i = 0 ; i < cnt ; i ++ ) {
584
+ event [i ] = queue -> buf [queue -> head ];
585
+ /* Paired with READ_ONCE() in queue_cnt() */
586
+ WRITE_ONCE (queue -> head , (queue -> head + 1 ) % PTP_MAX_TIMESTAMPS );
587
+ }
594
588
}
595
589
596
- spin_unlock_irqrestore (& queue -> lock , flags );
597
-
598
590
cnt = cnt * sizeof (struct ptp_extts_event );
599
591
600
592
result = cnt ;
0 commit comments