@@ -278,6 +278,18 @@ static long ptp_perout_request(struct ptp_clock *ptp, unsigned int cmd, void __u
278
278
return ops -> enable (ops , & req , perout -> period .sec || perout -> period .nsec );
279
279
}
280
280
281
+ static long ptp_enable_pps (struct ptp_clock * ptp , bool enable )
282
+ {
283
+ struct ptp_clock_request req = { .type = PTP_CLK_REQ_PPS };
284
+ struct ptp_clock_info * ops = ptp -> info ;
285
+
286
+ if (!capable (CAP_SYS_TIME ))
287
+ return - EPERM ;
288
+
289
+ scoped_cond_guard (mutex_intr , return - ERESTARTSYS , & ptp -> pincfg_mux )
290
+ return ops -> enable (ops , & req , enable );
291
+ }
292
+
281
293
long ptp_ioctl (struct posix_clock_context * pccontext , unsigned int cmd ,
282
294
unsigned long arg )
283
295
{
@@ -290,13 +302,12 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
290
302
struct ptp_sys_offset * sysoff = NULL ;
291
303
struct timestamp_event_queue * tsevq ;
292
304
struct ptp_system_timestamp sts ;
293
- struct ptp_clock_request req ;
294
305
struct ptp_clock_time * pct ;
295
306
unsigned int i , pin_index ;
296
307
struct ptp_pin_desc pd ;
297
308
struct timespec64 ts ;
298
- int enable , err = 0 ;
299
309
void __user * argptr ;
310
+ int err = 0 ;
300
311
301
312
if (in_compat_syscall () && cmd != PTP_ENABLE_PPS && cmd != PTP_ENABLE_PPS2 )
302
313
arg = (unsigned long )compat_ptr (arg );
@@ -323,21 +334,9 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
323
334
324
335
case PTP_ENABLE_PPS :
325
336
case PTP_ENABLE_PPS2 :
326
- if ((pccontext -> fp -> f_mode & FMODE_WRITE ) == 0 ) {
327
- err = - EACCES ;
328
- break ;
329
- }
330
- memset (& req , 0 , sizeof (req ));
331
-
332
- if (!capable (CAP_SYS_TIME ))
333
- return - EPERM ;
334
- req .type = PTP_CLK_REQ_PPS ;
335
- enable = arg ? 1 : 0 ;
336
- if (mutex_lock_interruptible (& ptp -> pincfg_mux ))
337
- return - ERESTARTSYS ;
338
- err = ops -> enable (ops , & req , enable );
339
- mutex_unlock (& ptp -> pincfg_mux );
340
- break ;
337
+ if ((pccontext -> fp -> f_mode & FMODE_WRITE ) == 0 )
338
+ return - EACCES ;
339
+ return ptp_enable_pps (ptp , !!arg );
341
340
342
341
case PTP_SYS_OFFSET_PRECISE :
343
342
case PTP_SYS_OFFSET_PRECISE2 :
0 commit comments