Skip to content

Commit 37e42f8

Browse files
KAGA-KOKOkuba-moo
authored andcommitted
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 <[email protected]> Reviewed-by: Vadim Fedorenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e4355e3 commit 37e42f8

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,52 @@ static long ptp_sys_offset_precise(struct ptp_clock *ptp, void __user *arg)
318318
return copy_to_user(arg, &precise_offset, sizeof(precise_offset)) ? -EFAULT : 0;
319319
}
320320

321+
static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg)
322+
{
323+
struct ptp_sys_offset_extended *extoff __free(kfree) = NULL;
324+
struct ptp_system_timestamp sts;
325+
326+
if (!ptp->info->gettimex64)
327+
return -EOPNOTSUPP;
328+
329+
extoff = memdup_user(arg, sizeof(*extoff));
330+
if (IS_ERR(extoff))
331+
return PTR_ERR(extoff);
332+
333+
if (extoff->n_samples > PTP_MAX_SAMPLES ||
334+
extoff->rsv[0] || extoff->rsv[1] ||
335+
(extoff->clockid != CLOCK_REALTIME &&
336+
extoff->clockid != CLOCK_MONOTONIC &&
337+
extoff->clockid != CLOCK_MONOTONIC_RAW))
338+
return -EINVAL;
339+
340+
sts.clockid = extoff->clockid;
341+
for (unsigned int i = 0; i < extoff->n_samples; i++) {
342+
struct timespec64 ts;
343+
int err;
344+
345+
err = ptp->info->gettimex64(ptp->info, &ts, &sts);
346+
if (err)
347+
return err;
348+
extoff->ts[i][0].sec = sts.pre_ts.tv_sec;
349+
extoff->ts[i][0].nsec = sts.pre_ts.tv_nsec;
350+
extoff->ts[i][1].sec = ts.tv_sec;
351+
extoff->ts[i][1].nsec = ts.tv_nsec;
352+
extoff->ts[i][2].sec = sts.post_ts.tv_sec;
353+
extoff->ts[i][2].nsec = sts.post_ts.tv_nsec;
354+
}
355+
356+
return copy_to_user(arg, extoff, sizeof(*extoff)) ? -EFAULT : 0;
357+
}
358+
321359
long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
322360
unsigned long arg)
323361
{
324362
struct ptp_clock *ptp =
325363
container_of(pccontext->clk, struct ptp_clock, clock);
326-
struct ptp_sys_offset_extended *extoff = NULL;
327364
struct ptp_clock_info *ops = ptp->info;
328365
struct ptp_sys_offset *sysoff = NULL;
329366
struct timestamp_event_queue *tsevq;
330-
struct ptp_system_timestamp sts;
331367
struct ptp_clock_time *pct;
332368
unsigned int i, pin_index;
333369
struct ptp_pin_desc pd;
@@ -370,39 +406,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
370406

371407
case PTP_SYS_OFFSET_EXTENDED:
372408
case PTP_SYS_OFFSET_EXTENDED2:
373-
if (!ptp->info->gettimex64) {
374-
err = -EOPNOTSUPP;
375-
break;
376-
}
377-
extoff = memdup_user((void __user *)arg, sizeof(*extoff));
378-
if (IS_ERR(extoff)) {
379-
err = PTR_ERR(extoff);
380-
extoff = NULL;
381-
break;
382-
}
383-
if (extoff->n_samples > PTP_MAX_SAMPLES ||
384-
extoff->rsv[0] || extoff->rsv[1] ||
385-
(extoff->clockid != CLOCK_REALTIME &&
386-
extoff->clockid != CLOCK_MONOTONIC &&
387-
extoff->clockid != CLOCK_MONOTONIC_RAW)) {
388-
err = -EINVAL;
389-
break;
390-
}
391-
sts.clockid = extoff->clockid;
392-
for (i = 0; i < extoff->n_samples; i++) {
393-
err = ptp->info->gettimex64(ptp->info, &ts, &sts);
394-
if (err)
395-
goto out;
396-
extoff->ts[i][0].sec = sts.pre_ts.tv_sec;
397-
extoff->ts[i][0].nsec = sts.pre_ts.tv_nsec;
398-
extoff->ts[i][1].sec = ts.tv_sec;
399-
extoff->ts[i][1].nsec = ts.tv_nsec;
400-
extoff->ts[i][2].sec = sts.post_ts.tv_sec;
401-
extoff->ts[i][2].nsec = sts.post_ts.tv_nsec;
402-
}
403-
if (copy_to_user((void __user *)arg, extoff, sizeof(*extoff)))
404-
err = -EFAULT;
405-
break;
409+
return ptp_sys_offset_extended(ptp, argptr);
406410

407411
case PTP_SYS_OFFSET:
408412
case PTP_SYS_OFFSET2:
@@ -527,7 +531,6 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
527531
}
528532

529533
out:
530-
kfree(extoff);
531534
kfree(sysoff);
532535
return err;
533536
}

0 commit comments

Comments
 (0)