Re: [patch 13/13] ptp: Convert ptp_open/read() to __free()
From: Paolo Abeni
Date: Tue Jun 24 2025 - 05:49:03 EST
On 6/20/25 3:24 PM, Thomas Gleixner wrote:
> scoped_guard(spinlock_irq, &queue->lock) {
> - size_t qcnt = queue_cnt(queue);
> -
> - if (cnt > qcnt)
> - cnt = qcnt;
> + size_t qcnt = min((size_t)queue_cnt(queue), cnt / sizeof(*event));
>
> - for (size_t i = 0; i < cnt; i++) {
> + for (size_t i = 0; i < qcnt; i++) {
> event[i] = queue->buf[queue->head];
> /* Paired with READ_ONCE() in queue_cnt() */
> WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS);
> }
> }
>
> - cnt = cnt * sizeof(struct ptp_extts_event);
> -
> - result = cnt;
> - if (copy_to_user(buf, event, cnt)) {
> - result = -EFAULT;
> - goto free_event;
> - }
> -
> -free_event:
> - kfree(event);
> -exit:
> - return result;
> + return copy_to_user(buf, event, cnt) ? -EFAULT : cnt;
> }
I'm likely low on coffee, but it looks like the above code is now
returning the original amount of provided events, while the existing
code returns the value bounded to the number of queue events.
Cheers,
Paolo