Thread (23 messages) 23 messages, 4 authors, 2026-07-29

Re: [PATCH v5 net-next 1/7] ptp: Add ioctls for PHC timestamps with quality attributes

flat view

From: Andrew Lunn <andrew@lunn.ch>
Date: 2026-07-27 13:15:28
Also in: linux-doc, linux-kselftest

quoted
+static long ptp_sys_offset_extended_attrs(struct ptp_clock *ptp, void __user *arg)
+{
+	struct ptp_sys_offset_attrs *data __free(kfree) = NULL;
+	struct ptp_attrs_request request;
+	struct ptp_system_timestamp sts;
+	unsigned int n_samples;
+	int err;
+
+	if (copy_from_user(&request, arg, sizeof(request)))
+		return -EFAULT;
+
+	if (request.valid ||
+	    request.num_samples > PTP_MAX_SAMPLES ||
+	    request.num_samples == 0)
+		return -EINVAL;
+
+	err = ptp_validate_sys_offset_clockid(request.clock_id);
+	if (err)
+		return err;
+
+	n_samples = request.num_samples;
+	sts.clockid = request.clock_id;
+
+	data = kzalloc(struct_size(data, timestamps, n_samples), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->request.num_samples = n_samples;
+
+	for (unsigned int i = 0; i < n_samples; i++) {
+		struct ptp_clock_attrs att = {};
+		struct timespec64 ts;
+
+		if (ptp->info->gettimexattrs64)
+			err = ptp->info->gettimexattrs64(ptp->info, &ts,
+							 &sts, &att);
+		else if (ptp->info->gettimex64)
+			err = ptp->info->gettimex64(ptp->info, &ts, &sts);
+		else
+			return -EOPNOTSUPP;
+
+		if (err)
+			return err;
+
+		/* Filter out disabled or unavailable clocks */
+		if (!sts.pre_sts.valid || !sts.post_sts.valid)
+			return -EINVAL;
+
+		data->timestamps[i].pre_systime.sys_time =
+			ktime_to_ns(sts.pre_sts.systime);
+		data->timestamps[i].pre_systime.sys_rawtime =
+			ktime_to_ns(sts.pre_sts.monoraw);
+		data->timestamps[i].pre_systime.sys_counter =
+			sts.pre_sts.cycles;
I hate all this line wrapping, btw. I'll defer to the net coding style
if they insist, but my preference would just be just to have longer
lines. Especially when it's a block of assignments like this, the
wrapped form is *much* harder to read.
This is a long function, probably longer than the coding style
suggests. So one option is to move the code within the for loop into a
helper. That might then allow unwrapped lines?

That is kind of the point of the line length limit, to make you break
code up into lots of small functions which do one thing.

     Andrew
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help