Re: [PATCH net-next v3 6/8] net: phy: mscc: timestamping and PHC support
From: Richard Cochran
Date: Sat Jun 20 2020 - 11:00:52 EST
On Fri, Jun 19, 2020 at 02:22:58PM +0200, Antoine Tenart wrote:
> +static void vsc85xx_dequeue_skb(struct vsc85xx_ptp *ptp)
> +{
> + struct skb_shared_hwtstamps shhwtstamps;
> + struct vsc85xx_ts_fifo fifo;
> + struct sk_buff *skb;
> + u8 skb_sig[16], *p;
> + int i, len;
> + u32 reg;
> +
> + memset(&fifo, 0, sizeof(fifo));
> + p = (u8 *)&fifo;
> +
> + reg = vsc85xx_ts_read_csr(ptp->phydev, PROCESSOR,
> + MSCC_PHY_PTP_EGR_TS_FIFO(0));
> + if (reg & PTP_EGR_TS_FIFO_EMPTY)
> + return;
> +
> + *p++ = reg & 0xff;
> + *p++ = (reg >> 8) & 0xff;
> +
> + /* Read the current FIFO item. Reading FIFO6 pops the next one. */
> + for (i = 1; i < 7; i++) {
> + reg = vsc85xx_ts_read_csr(ptp->phydev, PROCESSOR,
> + MSCC_PHY_PTP_EGR_TS_FIFO(i));
> + *p++ = reg & 0xff;
> + *p++ = (reg >> 8) & 0xff;
> + *p++ = (reg >> 16) & 0xff;
> + *p++ = (reg >> 24) & 0xff;
> + }
> +
> + len = skb_queue_len(&ptp->tx_queue);
> + if (len < 1)
> + return;
> +
> + while (len--) {
> + skb = __skb_dequeue(&ptp->tx_queue);
> + if (!skb)
> + return;
> +
> + /* Can't get the signature of the packet, won't ever
> + * be able to have one so let's dequeue the packet.
> + */
> + if (get_sig(skb, skb_sig) < 0)
> + continue;
This leaks the skb.
> + /* Check if we found the signature we were looking for. */
> + if (!memcmp(skb_sig, fifo.sig, sizeof(fifo.sig))) {
> + memset(&shhwtstamps, 0, sizeof(shhwtstamps));
> + shhwtstamps.hwtstamp = ktime_set(fifo.secs, fifo.ns);
> + skb_complete_tx_timestamp(skb, &shhwtstamps);
> +
> + return;
> + }
> +
> + /* Valid signature but does not match the one of the
> + * packet in the FIFO right now, reschedule it for later
> + * packets.
> + */
> + __skb_queue_tail(&ptp->tx_queue, skb);
> + }
> +}
Thanks,
Richard