summaryrefslogtreecommitdiff
path: root/drivers/ptp
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2025-06-25 13:52:30 +0200
committerJakub Kicinski <kuba@kernel.org>2025-06-26 17:54:05 -0700
commit37e42f8dd07d651d7dbd545115159fa4bc1baf54 (patch)
tree305cc6592369f0334ebf6a7d78225a2b3cf6df0a /drivers/ptp
parente4355e314c94b34cb1a90bda0a2932584a0722ab (diff)
ptp: Split out PTP_SYS_OFFSET_EXTENDED ioctl code
Continue the ptp_ioctl() cleanup by splitting out the PTP_SYS_OFFSET_EXTENDED ioctl code into a helper function. Convert it to __free() to avoid gotos. 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.050445505@linutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'drivers/ptp')
-rw-r--r--drivers/ptp/ptp_chardev.c75
1 files changed, 39 insertions, 36 deletions
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index 9a4036dcbc2d..3e07b6d96536 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -318,16 +318,52 @@ static long ptp_sys_offset_precise(struct ptp_clock *ptp, void __user *arg)
return copy_to_user(arg, &precise_offset, sizeof(precise_offset)) ? -EFAULT : 0;
}
+static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg)
+{
+ struct ptp_sys_offset_extended *extoff __free(kfree) = NULL;
+ struct ptp_system_timestamp sts;
+
+ if (!ptp->info->gettimex64)
+ return -EOPNOTSUPP;
+
+ extoff = memdup_user(arg, sizeof(*extoff));
+ if (IS_ERR(extoff))
+ return PTR_ERR(extoff);
+
+ if (extoff->n_samples > PTP_MAX_SAMPLES ||
+ extoff->rsv[0] || extoff->rsv[1] ||
+ (extoff->clockid != CLOCK_REALTIME &&
+ extoff->clockid != CLOCK_MONOTONIC &&
+ extoff->clockid != CLOCK_MONOTONIC_RAW))
+ return -EINVAL;
+
+ sts.clockid = extoff->clockid;
+ for (unsigned int i = 0; i < extoff->n_samples; i++) {
+ struct timespec64 ts;
+ int err;
+
+ err = ptp->info->gettimex64(ptp->info, &ts, &sts);
+ if (err)
+ return err;
+ extoff->ts[i][0].sec = sts.pre_ts.tv_sec;
+ extoff->ts[i][0].nsec = sts.pre_ts.tv_nsec;
+ extoff->ts[i][1].sec = ts.tv_sec;
+ extoff->ts[i][1].nsec = ts.tv_nsec;
+ extoff->ts[i][2].sec = sts.post_ts.tv_sec;
+ extoff->ts[i][2].nsec = sts.post_ts.tv_nsec;
+ }
+
+ return copy_to_user(arg, extoff, sizeof(*extoff)) ? -EFAULT : 0;
+}
+
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_sys_offset_extended *extoff = NULL;
struct ptp_clock_info *ops = ptp->info;
struct ptp_sys_offset *sysoff = NULL;
struct timestamp_event_queue *tsevq;
- struct ptp_system_timestamp sts;
struct ptp_clock_time *pct;
unsigned int i, pin_index;
struct ptp_pin_desc pd;
@@ -370,39 +406,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
case PTP_SYS_OFFSET_EXTENDED:
case PTP_SYS_OFFSET_EXTENDED2:
- if (!ptp->info->gettimex64) {
- err = -EOPNOTSUPP;
- break;
- }
- extoff = memdup_user((void __user *)arg, sizeof(*extoff));
- if (IS_ERR(extoff)) {
- err = PTR_ERR(extoff);
- extoff = NULL;
- break;
- }
- if (extoff->n_samples > PTP_MAX_SAMPLES ||
- extoff->rsv[0] || extoff->rsv[1] ||
- (extoff->clockid != CLOCK_REALTIME &&
- extoff->clockid != CLOCK_MONOTONIC &&
- extoff->clockid != CLOCK_MONOTONIC_RAW)) {
- err = -EINVAL;
- break;
- }
- sts.clockid = extoff->clockid;
- for (i = 0; i < extoff->n_samples; i++) {
- err = ptp->info->gettimex64(ptp->info, &ts, &sts);
- if (err)
- goto out;
- extoff->ts[i][0].sec = sts.pre_ts.tv_sec;
- extoff->ts[i][0].nsec = sts.pre_ts.tv_nsec;
- extoff->ts[i][1].sec = ts.tv_sec;
- extoff->ts[i][1].nsec = ts.tv_nsec;
- extoff->ts[i][2].sec = sts.post_ts.tv_sec;
- extoff->ts[i][2].nsec = sts.post_ts.tv_nsec;
- }
- if (copy_to_user((void __user *)arg, extoff, sizeof(*extoff)))
- err = -EFAULT;
- break;
+ return ptp_sys_offset_extended(ptp, argptr);
case PTP_SYS_OFFSET:
case PTP_SYS_OFFSET2:
@@ -527,7 +531,6 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
}
out:
- kfree(extoff);
kfree(sysoff);
return err;
}