Skip to content

Commit 47aaa73

Browse files
KAGA-KOKOkuba-moo
authored andcommitted
ptp: Split out PTP_ENABLE_PPS ioctl code
Continue the ptp_ioctl() cleanup by splitting out the PTP_ENABLE_PPS ioctl code into a helper function. Convert to a lock guard while at it. 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 3afc2ca commit 47aaa73

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ static long ptp_perout_request(struct ptp_clock *ptp, unsigned int cmd, void __u
278278
return ops->enable(ops, &req, perout->period.sec || perout->period.nsec);
279279
}
280280

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+
281293
long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
282294
unsigned long arg)
283295
{
@@ -290,13 +302,12 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
290302
struct ptp_sys_offset *sysoff = NULL;
291303
struct timestamp_event_queue *tsevq;
292304
struct ptp_system_timestamp sts;
293-
struct ptp_clock_request req;
294305
struct ptp_clock_time *pct;
295306
unsigned int i, pin_index;
296307
struct ptp_pin_desc pd;
297308
struct timespec64 ts;
298-
int enable, err = 0;
299309
void __user *argptr;
310+
int err = 0;
300311

301312
if (in_compat_syscall() && cmd != PTP_ENABLE_PPS && cmd != PTP_ENABLE_PPS2)
302313
arg = (unsigned long)compat_ptr(arg);
@@ -323,21 +334,9 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
323334

324335
case PTP_ENABLE_PPS:
325336
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);
341340

342341
case PTP_SYS_OFFSET_PRECISE:
343342
case PTP_SYS_OFFSET_PRECISE2:

0 commit comments

Comments
 (0)