[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <36a40fe2-43ad-4fd9-8c3f-ec661ff4b7f1@linux.dev>
Date: Sat, 21 Jun 2025 21:25:26 +0100
From: Vadim Fedorenko <vadim.fedorenko@...ux.dev>
To: Thomas Gleixner <tglx@...utronix.de>, LKML <linux-kernel@...r.kernel.org>
Cc: Richard Cochran <richardcochran@...il.com>, netdev@...r.kernel.org
Subject: Re: [patch 04/13] ptp: Split out PTP_ENABLE_PPS ioctl code
On 20/06/2025 14:24, Thomas Gleixner wrote:
> 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 <tglx@...utronix.de>
> ---
> drivers/ptp/ptp_chardev.c | 33 ++++++++++++++++-----------------
> 1 file changed, 16 insertions(+), 17 deletions(-)
>
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -278,6 +278,18 @@ static long ptp_perout_request(struct pt
> return ops->enable(ops, &req, perout->period.sec || perout->period.nsec);
> }
>
> +static long ptp_enable_pps(struct ptp_clock *ptp, bool enable)
> +{
> + struct ptp_clock_request req = { .type = PTP_CLK_REQ_PPS };
> + struct ptp_clock_info *ops = ptp->info;
> +
> + if (!capable(CAP_SYS_TIME))
> + return -EPERM;
> +
> + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &ptp->pincfg_mux)
> + return ops->enable(ops, &req, enable);
> +}
> +
> long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
> unsigned long arg)
> {
> @@ -290,13 +302,12 @@ long ptp_ioctl(struct posix_clock_contex
> struct ptp_sys_offset *sysoff = NULL;
> struct timestamp_event_queue *tsevq;
> struct ptp_system_timestamp sts;
> - struct ptp_clock_request req;
> struct ptp_clock_time *pct;
> unsigned int i, pin_index;
> struct ptp_pin_desc pd;
> struct timespec64 ts;
> - int enable, err = 0;
> void __user *argptr;
> + int err = 0;
>
> if (in_compat_syscall() && cmd != PTP_ENABLE_PPS && cmd != PTP_ENABLE_PPS2)
> arg = (unsigned long)compat_ptr(arg);
> @@ -323,21 +334,9 @@ long ptp_ioctl(struct posix_clock_contex
>
> case PTP_ENABLE_PPS:
> case PTP_ENABLE_PPS2:
> - if ((pccontext->fp->f_mode & FMODE_WRITE) == 0) {
> - err = -EACCES;
> - break;
> - }
> - memset(&req, 0, sizeof(req));
> -
> - if (!capable(CAP_SYS_TIME))
> - return -EPERM;
> - req.type = PTP_CLK_REQ_PPS;
> - enable = arg ? 1 : 0;
> - if (mutex_lock_interruptible(&ptp->pincfg_mux))
> - return -ERESTARTSYS;
> - err = ops->enable(ops, &req, enable);
> - mutex_unlock(&ptp->pincfg_mux);
> - break;
> + if ((pccontext->fp->f_mode & FMODE_WRITE) == 0)
> + return -EACCES;
> + return ptp_enable_pps(ptp, !!arg);
>
> case PTP_SYS_OFFSET_PRECISE:
> case PTP_SYS_OFFSET_PRECISE2:
>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@...ux.dev>
Powered by blists - more mailing lists