Skip to content

Commit b246e09

Browse files
KAGA-KOKOkuba-moo
authored andcommitted
ptp: Split out PTP_PIN_GETFUNC ioctl code
Continue the ptp_ioctl() cleanup by splitting out the PTP_PIN_GETFUNC 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 <[email protected]> Reviewed-by: Vadim Fedorenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4b676af commit b246e09

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,26 @@ static long ptp_sys_offset(struct ptp_clock *ptp, void __user *arg)
395395
return copy_to_user(arg, sysoff, sizeof(*sysoff)) ? -EFAULT : 0;
396396
}
397397

398+
static long ptp_pin_getfunc(struct ptp_clock *ptp, unsigned int cmd, void __user *arg)
399+
{
400+
struct ptp_clock_info *ops = ptp->info;
401+
struct ptp_pin_desc pd;
402+
403+
if (copy_from_user(&pd, arg, sizeof(pd)))
404+
return -EFAULT;
405+
406+
if (cmd == PTP_PIN_GETFUNC2 && !mem_is_zero(pd.rsv, sizeof(pd.rsv)))
407+
return -EINVAL;
408+
409+
if (pd.index >= ops->n_pins)
410+
return -EINVAL;
411+
412+
scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &ptp->pincfg_mux)
413+
pd = ops->pin_config[array_index_nospec(pd.index, ops->n_pins)];
414+
415+
return copy_to_user(arg, &pd, sizeof(pd)) ? -EFAULT : 0;
416+
}
417+
398418
long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
399419
unsigned long arg)
400420
{
@@ -450,35 +470,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
450470

451471
case PTP_PIN_GETFUNC:
452472
case PTP_PIN_GETFUNC2:
453-
if (copy_from_user(&pd, (void __user *)arg, sizeof(pd))) {
454-
err = -EFAULT;
455-
break;
456-
}
457-
if ((pd.rsv[0] || pd.rsv[1] || pd.rsv[2]
458-
|| pd.rsv[3] || pd.rsv[4])
459-
&& cmd == PTP_PIN_GETFUNC2) {
460-
err = -EINVAL;
461-
break;
462-
} else if (cmd == PTP_PIN_GETFUNC) {
463-
pd.rsv[0] = 0;
464-
pd.rsv[1] = 0;
465-
pd.rsv[2] = 0;
466-
pd.rsv[3] = 0;
467-
pd.rsv[4] = 0;
468-
}
469-
pin_index = pd.index;
470-
if (pin_index >= ops->n_pins) {
471-
err = -EINVAL;
472-
break;
473-
}
474-
pin_index = array_index_nospec(pin_index, ops->n_pins);
475-
if (mutex_lock_interruptible(&ptp->pincfg_mux))
476-
return -ERESTARTSYS;
477-
pd = ops->pin_config[pin_index];
478-
mutex_unlock(&ptp->pincfg_mux);
479-
if (!err && copy_to_user((void __user *)arg, &pd, sizeof(pd)))
480-
err = -EFAULT;
481-
break;
473+
return ptp_pin_getfunc(ptp, cmd, argptr);
482474

483475
case PTP_PIN_SETFUNC:
484476
case PTP_PIN_SETFUNC2:

0 commit comments

Comments
 (0)