Commit c3484c27 authored by Richard Cochran's avatar Richard Cochran Committed by David S. Miller

ptp: reduce stack usage when measuring the system time offset

This patch removes the large buffer from the stack of the system
offset ioctl and replaces it with a kmalloced buffer.
Signed-off-by: default avatarRichard Cochran <richardcochran@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c7ec0bad
...@@ -34,7 +34,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) ...@@ -34,7 +34,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
{ {
struct ptp_clock_caps caps; struct ptp_clock_caps caps;
struct ptp_clock_request req; struct ptp_clock_request req;
struct ptp_sys_offset sysoff; struct ptp_sys_offset *sysoff = NULL;
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
struct ptp_clock_info *ops = ptp->info; struct ptp_clock_info *ops = ptp->info;
struct ptp_clock_time *pct; struct ptp_clock_time *pct;
...@@ -94,17 +94,22 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) ...@@ -94,17 +94,22 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
break; break;
case PTP_SYS_OFFSET: case PTP_SYS_OFFSET:
if (copy_from_user(&sysoff, (void __user *)arg, sysoff = kmalloc(sizeof(*sysoff), GFP_KERNEL);
sizeof(sysoff))) { if (!sysoff) {
err = -ENOMEM;
break;
}
if (copy_from_user(sysoff, (void __user *)arg,
sizeof(*sysoff))) {
err = -EFAULT; err = -EFAULT;
break; break;
} }
if (sysoff.n_samples > PTP_MAX_SAMPLES) { if (sysoff->n_samples > PTP_MAX_SAMPLES) {
err = -EINVAL; err = -EINVAL;
break; break;
} }
pct = &sysoff.ts[0]; pct = &sysoff->ts[0];
for (i = 0; i < sysoff.n_samples; i++) { for (i = 0; i < sysoff->n_samples; i++) {
getnstimeofday(&ts); getnstimeofday(&ts);
pct->sec = ts.tv_sec; pct->sec = ts.tv_sec;
pct->nsec = ts.tv_nsec; pct->nsec = ts.tv_nsec;
...@@ -117,7 +122,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) ...@@ -117,7 +122,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
getnstimeofday(&ts); getnstimeofday(&ts);
pct->sec = ts.tv_sec; pct->sec = ts.tv_sec;
pct->nsec = ts.tv_nsec; pct->nsec = ts.tv_nsec;
if (copy_to_user((void __user *)arg, &sysoff, sizeof(sysoff))) if (copy_to_user((void __user *)arg, sysoff, sizeof(*sysoff)))
err = -EFAULT; err = -EFAULT;
break; break;
...@@ -125,6 +130,8 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) ...@@ -125,6 +130,8 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
err = -ENOTTY; err = -ENOTTY;
break; break;
} }
kfree(sysoff);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment