summaryrefslogtreecommitdiff
path: root/drivers/ptp
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2025-06-25 13:52:34 +0200
committerJakub Kicinski <kuba@kernel.org>2025-06-26 17:54:06 -0700
commitd713f1ff64d16e6f542acdd5a7819eba0d939094 (patch)
treeb004dcb17100d662f09b5e93a050e68c5183cb9a /drivers/ptp
parentb246e09f5fe189946e50151f5f04cded73593f19 (diff)
ptp: Split out PTP_PIN_SETFUNC ioctl code
Continue the ptp_ioctl() cleanup by splitting out the PTP_PIN_SETFUNC ioctl code into a helper function. Convert to lock guard while at it and remove the pointless memset of the pd::rsv because nothing uses it. No functional change intended. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Link: https://patch.msgid.link/20250625115133.241503804@linutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'drivers/ptp')
-rw-r--r--drivers/ptp/ptp_chardev.c58
1 files changed, 24 insertions, 34 deletions
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index 6348d57252be..176bdfdcc35b 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -415,16 +415,34 @@ static long ptp_pin_getfunc(struct ptp_clock *ptp, unsigned int cmd, void __user
return copy_to_user(arg, &pd, sizeof(pd)) ? -EFAULT : 0;
}
+static long ptp_pin_setfunc(struct ptp_clock *ptp, unsigned int cmd, void __user *arg)
+{
+ struct ptp_clock_info *ops = ptp->info;
+ struct ptp_pin_desc pd;
+ unsigned int pin_index;
+
+ if (copy_from_user(&pd, arg, sizeof(pd)))
+ return -EFAULT;
+
+ if (cmd == PTP_PIN_SETFUNC2 && !mem_is_zero(pd.rsv, sizeof(pd.rsv)))
+ return -EINVAL;
+
+ if (pd.index >= ops->n_pins)
+ return -EINVAL;
+
+ pin_index = array_index_nospec(pd.index, ops->n_pins);
+ scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &ptp->pincfg_mux)
+ return ptp_set_pinfunc(ptp, pin_index, pd.func, pd.chan);
+}
+
long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
unsigned long arg)
{
struct ptp_clock *ptp =
container_of(pccontext->clk, struct ptp_clock, clock);
- struct ptp_clock_info *ops = ptp->info;
struct timestamp_event_queue *tsevq;
- unsigned int i, pin_index;
- struct ptp_pin_desc pd;
void __user *argptr;
+ unsigned int i;
int err = 0;
if (in_compat_syscall() && cmd != PTP_ENABLE_PPS && cmd != PTP_ENABLE_PPS2)
@@ -474,37 +492,9 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
case PTP_PIN_SETFUNC:
case PTP_PIN_SETFUNC2:
- if ((pccontext->fp->f_mode & FMODE_WRITE) == 0) {
- err = -EACCES;
- break;
- }
- if (copy_from_user(&pd, (void __user *)arg, sizeof(pd))) {
- err = -EFAULT;
- break;
- }
- if ((pd.rsv[0] || pd.rsv[1] || pd.rsv[2]
- || pd.rsv[3] || pd.rsv[4])
- && cmd == PTP_PIN_SETFUNC2) {
- err = -EINVAL;
- break;
- } else if (cmd == PTP_PIN_SETFUNC) {
- pd.rsv[0] = 0;
- pd.rsv[1] = 0;
- pd.rsv[2] = 0;
- pd.rsv[3] = 0;
- pd.rsv[4] = 0;
- }
- pin_index = pd.index;
- if (pin_index >= ops->n_pins) {
- err = -EINVAL;
- break;
- }
- pin_index = array_index_nospec(pin_index, ops->n_pins);
- if (mutex_lock_interruptible(&ptp->pincfg_mux))
- return -ERESTARTSYS;
- err = ptp_set_pinfunc(ptp, pin_index, pd.func, pd.chan);
- mutex_unlock(&ptp->pincfg_mux);
- break;
+ if ((pccontext->fp->f_mode & FMODE_WRITE) == 0)
+ return -EACCES;
+ return ptp_pin_setfunc(ptp, cmd, argptr);
case PTP_MASK_CLEAR_ALL:
bitmap_clear(tsevq->mask, 0, PTP_MAX_CHANNELS);