From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796031020; b=bkWSL4KBFIdxBxeDlHIThYVgV+T0UYvSPML3/GWrh32ue1Yz97UGZ2G3r+6Dpg7/beNG QODwB8WCGiW1k2CdavYoT+STdOhTtwG7mq4wL6ZdsyyCipvWUP15OAqKreAqaPY4sTynI +jZ5o2tWa1/n1lnURWWLqpiNOsh/cu1iZRRfKKk8nZk1Pp+DGByGvbvvfyFx6ok5jtTLu gFnp4RTcMTJyn1HnKkre9LPyx7k7qBYKIgfnXV42wGPGW0rlvds28wDumxlzoqKHKsXmr cDC/r4mkUmhFahpEgKOAFoRdVyyQD1ROlzBqP2/Gjzt8IJQ9AkLSlnEorjlZYl8YZhQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796031020; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/cJWRTdKKnnTxlsW6QjfQr1Y5gw1x6PU4U3+ahUBx1g=; b=HAaxcxfCXwRn1lNB4mb82vAOj5JTpcVWHgxxv92WCdT1iYdym78IdfhJu7DF8lMA0Tt3 wHdIUQrX+o0pPF6GjugvikqMP3N7vpHF86NLqM1iGpW7a6ntgqHKBmyAtCTOOIn8n8Iy5 klpGMjrP0XXvBraHP2E0HsYh5mGY+GetC8spZmhUyhLBrst1FpYTPhbQ0iqxid9QYkaNN aC/GWq6YMMUAz+lcoMyIeX3zqDBjbT9FRjVOTGjN9ySj9BJ6Su6NUreNNRNWOb8KT0m1p 5/OHC3FosT/eCTwcAEXsx1uFAamLSrlFtchVqo5pz3EFssOjQYdj17KyC7hmuwZZJ9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MbfkjbSQ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8E44606A6A6 for ; Mon, 30 Nov 2026 09:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MbfkjbSQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 840831F00897; Mon, 30 Nov 2026 09:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796031020; bh=/cJWRTdKKnnTxlsW6QjfQr1Y5gw1x6PU4U3+ahUBx1g=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=MbfkjbSQBCLmYZyh1Yr0WTHfh+sC6gnpRLnjwXibNvj46JiioxzzjfBhj16a+pHlO bypes9CDTCmpyE+Zdo5L1rIrhOmw05lBVV9FJ9WuS/uInCMjzXIXEhtr7MlY6CptNj Xgt7PvBQ/6+vFGNDrWp1/Jv6aYb2ZqwoA5SJRgLJ+km8ioLkJbTx48do8mlXI4jEr2 7xEOz6y5XN7BLhZ0i8HseyEQY5IKG2Kn7IRd5KeLC79SuOixf5BGwfwahBsOzQssK8 apC7+nBzw6aN6nE1eQvQYFtaWkrqi94P1zRwvLr1G60Vvv98xjOTvT1CQ8Tl0q7Cd0 lp7QyHEcTj6jQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next 2/3] net: usb: ax88179: Add PTP Implementation Reply-To: sashiko-reviews@lists.linux.dev To: "Birger Koblitz" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261129-ptp-v1-2-8148c402beaf@birger-koblitz.de> References: <20261129-ptp-v1-0-8148c402beaf@birger-koblitz.de> <20261129-ptp-v1-2-8148c402beaf@birger-koblitz.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 09:30:20 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 14 potential issues to consider: - [High] net: usb: ax88179: PTP_1588_CLOCK_OPTIONAL added to USB_NET_AX8817X in Kconfig - [High] net: usb: ax88179: uninitialized or dangling ptp_hdr in ax88279_process_tx_ts() - [High] net: usb: ax88179: ptp_info[0] read instead of ptp_info[i] in timestamp readers - [High] net: usb: ax88179: broken error handling and leaks in ax88179a_ptp_register() - [High] net: usb: ax88179: incomplete teardown and leaks in ax88179a_ptp_unregister() - [High] net: usb: ax88179: GFP_KERNEL and error resubmit in ax88279_read_ts_complete() - [High] net: usb: ax88179: ring drain and full-queue wraparound on ptp_info_buf - [High] net: usb: ax88179: unlocked __skb_unlink() on tx_skbs and ptp_info_buf race - [High] net: usb: ax88179: unlocked tx_skbs unlink in ax88279_process_tx_ts() - [Medium] net: usb: ax88179: speed enum mismatch in ax88179a_ptp_config() - [Medium] net: usb: ax88179: missing endian conversion in 32-bit PTP writes - [Medium] net: usb: ax88179: wrong transfer size in ax88179a_ptp_read_ts() - [Medium] net: usb: ax88179: off-by-one nanosecond carry in ax88179a_ptp_adjtime() - [Low] net: usb: ax88179: duplicate macro definitions in ax88179a_ptp.h -- commit fe13df4a07a9671fd74415abcea9a55992d30d82 Author: Birger Koblitz net: usb: ax88179: Add PTP Implementation This commit adds PTP hardware clock and TX/RX hardware timestamping support for the AX88179A and AX88279 USB Ethernet controllers. > diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig > index cc8f2e1503399..2a811116d34dc 100644 > --- a/drivers/net/usb/Kconfig > +++ b/drivers/net/usb/Kconfig > @@ -166,6 +166,7 @@ config USB_USBNET > config USB_NET_AX8817X > tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters" > depends on USB_USBNET > + depends on PTP_1588_CLOCK_OPTIONAL > select CRC32 > select PHYLINK > select AX88796B_PHY > diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile > index 4026f19ecb826..812adcf839dc4 100644 > --- a/drivers/net/usb/Makefile > +++ b/drivers/net/usb/Makefile > @@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX) +=3D lan78xx.o > obj-$(CONFIG_USB_NET_AX8817X) +=3D asix.o > asix-y :=3D asix_devices.o asix_common.o ax88172a.o > obj-$(CONFIG_USB_NET_AX88179) +=3D ax88179.o > -ax88179-y :=3D ax88179_178a.o ax88179a_devices.o ax88179_lib.o > +ax88179-y :=3D ax88179_178a.o ax88179a_devices.o ax88179_lib.o ax88179a_= ptp.o [Severity: High] Should the PTP_1588_CLOCK_OPTIONAL dependency be on USB_NET_AX88179 instead of USB_NET_AX8817X? ax88179a_ptp.o is linked into ax88179.o under CONFIG_USB_NET_AX88179, so building with CONFIG_USB_NET_AX88179=3Dy and CONFIG_PTP_1588_CLOCK=3Dm fails at link time with undefined references to ptp_clock_register(), ptp_clock_index() and ptp_clock_unregister(). > diff --git a/drivers/net/usb/ax88179a_ptp.c b/drivers/net/usb/ax88179a_pt= p.c > new file mode 100644 > index 0000000000000..9a04a93e50952 > --- /dev/null > +++ b/drivers/net/usb/ax88179a_ptp.c > @@ -0,0 +1,845 @@ [ ... ] > +static int ax88279_ptp_pbus_write(struct usbnet *dev, u16 offset, > + u16 len, void *data) > +{ > + int ret; > + > + ret =3D ax88179_write_cmd(dev, AX88279_PBUS_A32, offset, > + AX88279_PTP_REG_BASE_ADDR_HI, len, data); > + if (ret < 0) > + return ret; > + > + return 0; > +} > + > +static int ax88279_ptp_pbus_write_u32(struct usbnet *dev, u16 offset, u3= 2 data) > +{ > + u32 buf =3D data; > + > + return ax88279_ptp_pbus_write(dev, offset, 4, &buf); > +} [Severity: Medium] Does ax88279_ptp_pbus_write_u32() write byte-reversed 32-bit values on big-endian hosts? ax88179_write_cmd() only byte-swaps 2-byte buffers and passes 4-byte buffers through raw, unlike ax88179_write_u32() which calls cpu_to_le32s(). The same endianness mismatch affects the 4-byte ax88179_write_cmd() calls in ax88179a_ptp_pps_ctrl(), ax88279_ptp_pps_ctrl() (after ax88179_read_cmd() converts reg32 to CPU byte order) and ax88179a_ptp_config(), as well as the unguarded C bitfields in struct ptp_info_279 and struct ptp_info_179a. [ ... ] > +static int ax88179a_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) > +{ > + struct ax88179a_ptp *ax88179a_ptp =3D ptp_to_dev(ptp); > + u8 timestamp[AX_PTP_DATA_LEN] =3D {0}; > + struct ax88179_data *ax179_data; > + bool delta_is_neg =3D false; > + u64 sec, d, d_sec; > + u32 d_nsec; > + u32 nsec; > + int ret; > + > + ax179_data =3D ax88179a_ptp->ax179_data; > + if (ax179_data->chip_version =3D=3D AX_VERSION_AX88279) > + ret =3D ax88279_ptp_clk_read(ax88179a_ptp->dev, AX88179A_PTP_GET_80B_L= CK, > + AX_PTP_DATA_LEN, timestamp); > + else > + ret =3D ax88179_read_cmd(ax88179a_ptp->dev, AX_PTP_OP, AX_GET_LOCAL_CL= OCK, 0, > + AX_GET_LOCAL_CLOCK_SIZE, timestamp); > + > + if (ret < 0) > + return ret; > + > + nsec =3D get_unaligned_le32(timestamp); > + sec =3D get_unaligned_le64(×tamp[4]); > + if (delta < 0) > + delta_is_neg =3D true; > + d =3D abs(delta); > + > + d_sec =3D div_u64_rem(d, NSEC_PER_SEC, &d_nsec); > + if (delta_is_neg) { > + if (d_nsec > nsec) { > + nsec +=3D NSEC_PER_SEC; > + sec -=3D 1; > + } > + nsec -=3D d_nsec; > + sec -=3D d_sec; > + } else { > + nsec +=3D d_nsec; > + if (nsec > NSEC_PER_SEC) { > + sec +=3D 1; > + nsec -=3D NSEC_PER_SEC; > + } > + sec +=3D d_sec; > + } [Severity: Medium] Should the nanosecond carry check in ax88179a_ptp_adjtime() be "nsec >=3D NSEC_PER_SEC" instead of "nsec > NSEC_PER_SEC"? When nsec + d_nsec equals NSEC_PER_SEC, this writes 1000000000 into the nanosecond field without incrementing sec. In addition, on AX88279 both ax88179a_ptp_adjtime() and ax88179a_ptp_gettime64() read AX_PTP_DATA_LEN (12) bytes from the 80-bit clock register without masking the upper 16 bits of sec, and the read-modify-write sequence in ax88179a_ptp_adjtime() is not serialized against concurrent clock adjustments. [ ... ] > +static int match_ptp_ts(struct ax88179a_ptp *ptp, struct ptp_header *ptp= _hdr, > + struct sk_buff *skb, int type) > +{ > + u16 sequence_id; > + > + sequence_id =3D ntohs(ptp_hdr->sequence_id); > + if (ptp->ax179_data->chip_version =3D=3D AX_VERSION_AX88179A) > + sequence_id &=3D 0xff; > + > + while (ptp->ptp_info_buf_tail !=3D ptp->ptp_info_buf_head) { > + struct ptp_info *ptp_info =3D &ptp->ptp_info_buf[ptp->ptp_info_buf_tai= l]; > + > + if (ptp_info->sequence_id =3D=3D sequence_id && > + (ptp_hdr->tsmt & 0xf) =3D=3D ptp_info->msg_type) { > + struct skb_shared_hwtstamps shhwtstamps; > + u64 timestamp_h, timestamp_l; > + u8 msgtype; > + u64 time64; > + > + timestamp_l =3D ptp_info->nsec; > + timestamp_h =3D ptp_info->sec; > + time64 =3D timestamp_h * NSEC_PER_SEC; > + time64 +=3D timestamp_l & 0xFFFFFFFF; > + memset(&shhwtstamps, 0, sizeof(shhwtstamps)); > + shhwtstamps.hwtstamp =3D ns_to_ktime(time64); > + > + msgtype =3D ptp_get_msgtype(ptp_hdr, type); > + if (ptp_hdr->flag_field[0] & 0x2 || (msgtype !=3D 0 && msgtype !=3D 3= )) > + skb_tstamp_tx(skb, &shhwtstamps); > + } > + ptp->ptp_info_buf_tail++; > + ptp->ptp_info_buf_tail %=3D AX88179A_PTP_QUEUE_SIZE; > + } > + > + return 0; > +} [Severity: High] Doesn't match_ptp_ts() drain the entire ptp_info_buf ring on the first skb in ptp->tx_skbs? Because the loop never breaks after a match and advances ptp_info_buf_tail to ptp_info_buf_head unconditionally, all remaining queued timestamps are discarded and any subsequent skbs in ptp->tx_skbs see an empty ring. Furthermore, ptp_info_buf has AX88179A_PTP_QUEUE_SIZE (5) slots, so when all 5 slots are populated in a batch, advancing ptp_info_buf_head 5 times modulo 5 wraps it back to ptp_info_buf_tail and makes the full ring appear empty. > + > +static void ax88279_process_tx_ts(struct work_struct *work) > +{ > + struct ptp_header *ptp_hdr; > + struct sk_buff *skb, *tmp; > + struct ax88179a_ptp *ptp; > + int type; > + > + ptp =3D container_of(work, struct ax88179a_ptp, process_ptp_info_buf); > + > + skb_queue_walk_safe(&ptp->tx_skbs, skb, tmp) { > + type =3D ptp_classify_raw(skb); > + if (type !=3D PTP_CLASS_NONE) { > + ptp_hdr =3D ptp_parse_header(skb, type); > + if (!ptp_hdr) > + goto frame_err; > + } > + match_ptp_ts(ptp, ptp_hdr, skb, type); > +frame_err: > + __skb_unlink(skb, &ptp->tx_skbs); > + dev_kfree_skb_any(skb); > + } > +} [Severity: High] When ptp_classify_raw(skb) returns PTP_CLASS_NONE, doesn't ax88279_process_tx_ts() pass an uninitialized or dangling ptp_hdr to match_ptp_ts()? If a non-PTP packet is queued in ptp->tx_skbs (or CONFIG_NET_PTP_CLASSIFY is disabled), ptp_hdr is not set and execution still falls through to match_ptp_ts(), which dereferences ptp_hdr->sequence_id. On the first iteration ptp_hdr is uninitialized stack data; on later iterations it points into the skb freed by dev_kfree_skb_any() on a previous iteration. [Severity: High] Can walking ptp->tx_skbs and calling __skb_unlink() without holding ptp->tx_skbs.lock corrupt the queue? CPU0 (TX path) CPU1 (kworker) ax88179a_tx_fixup() ax88279_process_tx_ts() skb_queue_tail(&ptp->tx_skbs) skb_queue_walk_safe(&ptp->tx_skbs, ...) spin_lock_irqsave(&list->lock) __skb_queue_tail(...) __skb_unlink(skb, &ptp->tx_skbs) <-- unlocked list mutation __skb_unlink() is a non-atomic helper that requires ptp->tx_skbs.lock; using skb_dequeue(&ptp->tx_skbs) in a while loop avoids racing with skb_queue_tail() and skb_queue_purge(). Likewise, match_ptp_ts() reads ptp->ptp_info_buf and updates ptp_info_buf_tail without synchronization while ax88279_read_ts_complete() (in URB completion context) or ax88179a_ptp_read_ts() writes ptp_info_buf and updates ptp_info_buf_head. > + > +static void ax88279_read_ts_complete(struct urb *urb) > +{ > + struct ax88179_data *ax179_data; > + struct ptp_info_279 *ptp_info; > + struct ax88179a_ptp *ptp; > + struct usbnet *dev; > + int offset; > + > + dev =3D urb->context; > + ax179_data =3D dev->driver_priv; > + if (!ax179_data) > + return; > + > + ptp =3D ax179_data->ptp; > + if (!ptp) > + return; > + > + if (!netif_carrier_ok(dev->net)) > + return; > + > + if (urb->status < 0) { > + netdev_err(dev->net, "Timestamp URB status error: %d", urb->status); > + goto out; > + } > + > + usb_mark_last_busy(dev->udev); > + > + // There can only be 2 packets in this buffer > + offset =3D (ptp->ep4_buf[AX88279_PTP_EP4_SIZE - 1] & AX_TS_SEG_1) ? > + 0 : (sizeof(struct ptp_info_279) * AX88179A_PTP_QUEUE_SIZE); > + > + ptp_info =3D (struct ptp_info_279 *)&ptp->ep4_buf[offset]; > + for (int i =3D 0; i < AX88179A_PTP_QUEUE_SIZE; i++) { > + int j; > + > + j =3D ptp->ptp_info_buf_head; > + if (ptp_info[i].status) { > + ptp->ptp_info_buf[j].msg_type =3D ptp_info->msg_type; > + ptp->ptp_info_buf[j].sequence_id =3D le16_to_cpu(ptp_info->sequence_i= d); > + ptp->ptp_info_buf[j].nsec =3D le32_to_cpu(ptp_info->nsec); > + ptp->ptp_info_buf[j].sec =3D le16_to_cpu(ptp_info->sec_h); > + ptp->ptp_info_buf[j].sec <<=3D 32; > + ptp->ptp_info_buf[j].sec |=3D le32_to_cpu(ptp_info->sec_l); > + ptp->ptp_info_buf_head++; > + ptp->ptp_info_buf_head %=3D AX88179A_PTP_QUEUE_SIZE; > + } > + } > + schedule_work(&ptp->process_ptp_info_buf); > +out: > + ptp->ptp_read_ts(dev); > +} [Severity: High] Doesn't this loop copy from ptp_info (element 0) instead of ptp_info[i] when ptp_info[i].status is set? Any timestamp reported in slots 1..4 is overwritten with the contents of slot 0. The same bug is present in ax88179a_ptp_read_ts() below. > + > +void ax88179a_ptp_kill_urbs(struct usbnet *dev) > +{ > + struct ax88179_data *ax179_data =3D dev->driver_priv; > + > + if (ax179_data->chip_version =3D=3D AX_VERSION_AX88279 && ax179_data->p= tp && > + ax179_data->ptp->urb) { > + netdev_info(dev->net, "PTP: killing URBs\n"); > + usb_kill_urb(ax179_data->ptp->urb); > + } > +} > + > +static int ax88279_ptp_read_ts(struct usbnet *dev) > +{ > + struct ax88179_data *ax179_data =3D dev->driver_priv; > + struct ax88179a_ptp *ptp =3D ax179_data->ptp; > + struct urb *urb =3D ptp->urb; > + int ret; > + > + memset(ptp->ep4_buf, 0, AX88279_PTP_EP4_SIZE); > + usb_fill_bulk_urb(urb, dev->udev, > + usb_rcvbulkpipe(dev->udev, 4), > + (void *)ptp->ep4_buf, AX88279_PTP_EP4_SIZE, > + (usb_complete_t)ax88279_read_ts_complete, > + dev); > + > + ret =3D usb_submit_urb(urb, GFP_KERNEL); > + if (ret =3D=3D -ENODEV) { > + netdev_err(dev->net, "Error submitting PTP bulk message: status=3D%d",= ret); > + netif_device_detach(dev->net); > + } > + > + urb->actual_length =3D 0; > + > + return ret; > +} [Severity: High] ax88279_read_ts_complete() runs in atomic URB completion context and calls ptp->ptp_read_ts(dev) -> ax88279_ptp_read_ts(), which calls usb_submit_urb(urb, GFP_KERNEL). Doesn't that sleep in atomic context? In addition, when urb->status < 0 in ax88279_read_ts_complete(), jumping to "out:" resubmits the URB even on -ENOENT, -ECONNRESET or -ESHUTDOWN (such as when usb_kill_urb() is called while carrier is up). ax88279_ptp_read_ts() also writes urb->actual_length =3D 0 after usb_submit_urb() has already submitted the URB, and DMA-maps ptp->ep4_buf, which is embedded in struct ax88179a_ptp without cacheline alignment. > + > +static int ax88179a_ptp_read_ts(struct usbnet *dev) > +{ > + struct ax88179_data *ax179_data =3D dev->driver_priv; > + struct ax88179a_ptp *ptp =3D ax179_data->ptp; > + struct ptp_info_179a *ptp_info; > + int count =3D 0; > + int ret; > + > + ret =3D ax88179_read_cmd(dev, AX_PTP_TIMESTAMP_REQ, 0, 0, AX88279_PTP_E= P4_SIZE, ptp->ep4_buf); > + if (ret < 0) { > + netdev_err(dev->net, "Error submitting PTP control message: status=3D%= d", ret); > + netif_device_detach(dev->net); > + return ret; > + } [Severity: Medium] Should ax88179a_ptp_read_ts() request sizeof(struct ptp_info_179a) * AX88179A_PTP_QUEUE_SIZE (60 bytes) instead of AX88279_PTP_EP4_SIZE (131 bytes)? ax88179a_ptp_config() programs AX88179A_PTP_MEM_SEG_SIZE to sizeof(struct ptp_info_179a) * AX88179A_PTP_QUEUE_SIZE. Also, ptp->ep4_buf is not zeroed before the read and short reads are not checked, so a short transfer can leave stale status bits in ptp->ep4_buf, and calling netif_device_detach() on any negative return value detaches the netdev even on transient control transfer errors (unlike ax88279_ptp_read_ts(), which checks for -ENODEV). [ ... ] > +static int ax88179a_ptp_config(struct usbnet *dev, int speed) > +{ [ ... ] > + switch (speed) { > + case ETHER_LINK_10: > + ptp_tx_delay[0] =3D 0xB7; > + ptp_tx_delay[1] =3D 0x0F; > + ptp_tx_delay[4] =3D ptpset; > + ptp_rx_delay[0] =3D 0xAC; > + ptp_rx_delay[1] =3D 0x0A; > + ptp_rx_delay[4] =3D ptpset; > + break; > + case ETHER_LINK_100: > + ptp_tx_delay[0] =3D 0x64; > + ptp_tx_delay[4] =3D ptpset; > + ptp_rx_delay[0] =3D 0x22; > + ptp_rx_delay[1] =3D 0x01; > + ptp_rx_delay[4] =3D ptpset; > + break; > + case ETHER_LINK_1000: > + default: > + ptp_tx_delay[0] =3D 0x6E; > + ptp_tx_delay[4] =3D ptpset; > + ptp_rx_delay[0] =3D 0xE4; > + ptp_rx_delay[4] =3D ptpset; > + break; > + } [ ... ] > + ptp_data->tx_tstamp =3D true; > + ptp_data->rx_tstamp =3D true; > + > + return 0; > +} > + > +static int ax88279_ptp_config(struct usbnet *dev, int speed) > +{ [ ... ] > + ret =3D ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MAC_BFM_CTRL, 1, 1, &re= g8); > + if (ret < 0) > + goto out; > + reg8 |=3D AX_CS_TRAIL_UDPV4_EN | AX_CS_TRAIL_UDPV6_EN; > + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MAC_BFM_CTRL, 1, 1, ®8); > + > + switch (speed) { > + case SPEED_100: [ ... ] > +out: > + return ret; > +} [Severity: Medium] Why does ax88179a_ptp_config() switch on ETHER_LINK_10 / ETHER_LINK_100 / ETHER_LINK_1000 (1, 2, 3) while ax88279_ptp_config() switches on SPEED_100 / SPEED_1000 / SPEED_2500 for the same ptp_config() callback? When phylink passes SPEED_10 or SPEED_100 to ptp_config(), ax88179a_ptp_config() always falls through to the 1000 Mbps default case. Also, unlike ax88179a_ptp_config(), ax88279_ptp_config() never sets ptp_data->tx_tstamp and ptp_data->rx_tstamp to true and returns ret (1 on success from ax88179_read_cmd()) instead of 0. [ ... ] > +int ax88179a_ptp_register(struct usbnet *dev) > +{ > + struct ax88179a_ptp *ax88179a_ptp; > + struct ax88179_data *ax179_data; > + u8 ptp_ver; > + int ret =3D 0; > + > + ax179_data =3D dev->driver_priv; > + ax88179a_ptp =3D kzalloc_obj(*ax88179a_ptp); > + if (!ax88179a_ptp) > + return -ENOMEM; > + > + ax179_data->ptp =3D ax88179a_ptp; > + ax88179a_ptp->dev =3D dev; > + ax88179a_ptp->ax179_data =3D ax179_data; > + > + ax88179a_ptp->ptp_info_buf_head =3D 0; > + ax88179a_ptp->ptp_info_buf_tail =3D 0; > + INIT_WORK(&ax88179a_ptp->process_ptp_info_buf, ax88279_process_tx_ts); > + INIT_WORK(&ax88179a_ptp->req_tx_timestamp, ax88179a_ptp_read_ts_work); > + skb_queue_head_init(&ax88179a_ptp->tx_skbs); > + > + switch (ax179_data->chip_version) { > + case AX_VERSION_AX88279: > + ax88179a_ptp->urb =3D usb_alloc_urb(0, GFP_KERNEL); > + if (!ax88179a_ptp->urb) > + goto err; > + ax88179a_ptp->pps_ctrl =3D ax88279_ptp_pps_ctrl; > + ax88179a_ptp->ptp_config =3D ax88279_ptp_config; > + ax88179a_ptp->ptp_read_ts =3D ax88279_ptp_read_ts; > + netdev_info(dev->net, "PTP enabled on AX88279\n"); > + break; > + > + case AX_VERSION_AX88179A: > + ax88179a_ptp->urb =3D usb_alloc_urb(0, GFP_KERNEL); > + if (!ax88179a_ptp->urb) > + goto err; > + ax88179a_ptp->ctrlreq =3D kzalloc_obj(*ax179_data->ptp->ctrlreq); > + if (!ax88179a_ptp->ctrlreq) > + goto no_ctrlreq; > + if (ax88179_read_cmd(dev, AX88179A_ACCESS_BL, > + AX88179A_HW_EC_VERSION, 1, 1, &ptp_ver) < 0) > + return 0; > + > + if (ptp_ver < 3) { > + netdev_warn(dev->net, "PTP on AX88179A version %d < 3 unsupported\n", > + ptp_ver); > + return 0; > + } > + netdev_info(dev->net, "PTP on AX88179A version %d enabled\n", ptp_ver); > + > + ax88179a_ptp->pps_ctrl =3D ax88179a_ptp_pps_ctrl; > + ax88179a_ptp->ptp_config =3D ax88179a_ptp_config; > + ax88179a_ptp->ptp_read_ts =3D ax88179a_ptp_read_ts; > + > + // PTP excludes TSO and SG on AX88179A > + dev->net->features &=3D ~(NETIF_F_SG | NETIF_F_TSO); > + dev->net->hw_features &=3D ~(NETIF_F_SG | NETIF_F_TSO); > + dev->net->vlan_features &=3D ~(NETIF_F_SG | NETIF_F_TSO); > + break; > + > + default: > + netdev_warn(dev->net, "PTP not supported\n"); > + ret =3D -EOPNOTSUPP; > + goto no_ctrlreq; > + }; > + > + ax88179a_ptp->ptp_ci =3D ax88179a_ptp_clock; > + ax88179a_ptp->ptp_clock =3D ptp_clock_register(&ax88179a_ptp->ptp_ci, &= dev->udev->dev); > + > + if (IS_ERR(ax88179a_ptp->ptp_clock)) { > + dev_err(&dev->udev->dev, "ptp_clock_register failed\n"); > + ret =3D PTR_ERR(ax88179a_ptp->ptp_clock); > + goto err; > + } > + > + ax88179a_ptp->phc_index =3D ptp_clock_index(ax88179a_ptp->ptp_clock); > + > + ax88179a_ptp->ax179_data =3D ax179_data; > + > + return 0; > + > +no_ctrlreq: > + kfree(ax88179a_ptp->urb); > +err: > + kfree(ax88179a_ptp); > + return ret; > +} [Severity: High] What happens on the early returns and error paths in ax88179a_ptp_register()? If reading AX88179A_HW_EC_VERSION fails or ptp_ver < 3, returning 0 leaks urb, ctrlreq and ax88179a_ptp while leaving ax179_data->ptp non-NULL with NULL pps_ctrl, ptp_config and ptp_read_ts callbacks, causing a NULL function pointer dereference when callers check ax179_data->ptp and invoke those callbacks (for example in ax88179a_ptp_unregister()). On the goto error paths: - ax179_data->ptp is never reset to NULL when ax88179a_ptp is freed, leaving a dangling pointer; - ret is still 0 when usb_alloc_urb() or kzalloc_obj() fails; - no_ctrlreq frees ax88179a_ptp->urb with kfree() instead of usb_free_urb(); - ptp_clock_register() failure jumps to err, leaking urb and ctrlreq. > + > +void ax88179a_ptp_unregister(struct usbnet *dev) > +{ > + struct ax88179a_ptp *ax88179a_ptp; > + struct ax88179_data *ax179_data; > + > + ax179_data =3D dev->driver_priv; > + ax88179a_ptp =3D ax179_data->ptp; > + > + if (!ax179_data->ptp) > + return; > + > + ax88179a_ptp->pps_ctrl(dev, false); > + cancel_work_sync(&ax88179a_ptp->process_ptp_info_buf); > + > + if (ax179_data->chip_version =3D=3D AX_VERSION_AX88279) { > + ax88279_ptp_pbus_write_u32(dev, AX88279_PTP_LCK_CTRL0, 0); > + ax88279_ptp_pbus_write_u32(dev, AX88279_PTP_RX_CTRL0, 0); > + ax88279_ptp_pbus_write_u32(dev, AX88279_PTP_TX_CTRL0, 0); > + usb_free_urb(ax88179a_ptp->urb); > + } else { > + u8 reg8 =3D 0; > + > + ax88179_read_cmd(dev, AX_PTP_CMD, AX88179A_PTP_CTRL_1, 0, 1, ®8); > + reg8 &=3D ~(AX_PTP_CTRL_L3_EN | AX_PTP_CTRL_EN); > + ax88179_write_cmd(dev, AX_PTP_CMD, AX88179A_PTP_CTRL_1, 0, 1, ®8); > + kfree(ax88179a_ptp->ctrlreq); > + } > + skb_queue_purge(&ax88179a_ptp->tx_skbs); > + > + if (ax88179a_ptp && ax88179a_ptp->ptp_clock) > + ptp_clock_unregister(ax88179a_ptp->ptp_clock); > + > + kfree(ax179_data->ptp); > +} [Severity: High] Does ax88179a_ptp_unregister() leave req_tx_timestamp work and the URB active, and leak ax88179a_ptp->urb on AX88179A? req_tx_timestamp is never cancelled with cancel_work_sync(), and the URB is not killed before cancelling process_ptp_info_buf, so an in-flight req_tx_timestamp work item or URB completion can reschedule process_ptp_info_buf and access ax88179a_ptp after it is freed. Also, ax88179a_ptp->urb is allocated for AX_VERSION_AX88179A in ax88179a_ptp_register() but only freed in the AX_VERSION_AX88279 branch here, and ax179_data->ptp is not cleared to NULL after kfree(). > diff --git a/drivers/net/usb/ax88179a_ptp.h b/drivers/net/usb/ax88179a_pt= p.h > new file mode 100644 > index 0000000000000..534e73cdc951e > --- /dev/null > +++ b/drivers/net/usb/ax88179a_ptp.h > @@ -0,0 +1,249 @@ [ ... ] > +#define AX_PTP_CLK_EN 0x010000 > +#define AX_PTP_CLK_SELECT_DIVIDE 0x040000 > + > +#define AX88179A_PBUS_REG 0x10 > +#define AX_PTP_CLK 0x13 > + > +#define AX88279_PTP_LCK_CTRL0 0x1000 > +#define AX_PTP_LCK_CTRL0_EN 0x0001 > +#define AX_PTP_LCK_CTRL0_80B_NS_EN 0x0002 > +#define AX_PTP_LCK_CTRL0_80B_S_E 0x0004 > +#define AX_PTP_LCK_CTRL0_48B_EN 0x0008 > +#define AX_PTP_LCK_CTRL0_PPS_EN 0x0010 > +#define AX_PTP_LCK_CTRL0_TX_DEL_VEC 0x0040 > + > +#define AX88279_PTP_RX_CTRL0 0x2000 > +#define AX88279_PTP_TX_CTRL0 0x3000 > + > +#define AX88179A_PTP_CTRL_1 0x00 > +#define AX_PTP_CTRL_EN 0x01 > +#define AX_PTP_CTRL_L3_EN 0x02 > +#define AX_PTP_TX_FILTER_GENERAL_MSG 0x08 > +#define AX_PTP_RX_FILTER_GENERAL_MSG 0x10 > +#define AX_PTP_TX_PLUS_DELAY 0x20 > +#define AX88179A_PTP_MEM_SEG_SIZE 0x21 > + > +#define AX88179A_PTP_CTRL_2 0x01 > +#define AX_PTP_CTRL_SET_PERIOD 0x08 > + > +#define AX88179A_PTP_MEM_SEG_SIZE 0x21 [Severity: Low] This isn't a bug, but several macros in ax88179a_ptp.h are defined twice: AX88179A_PTP_MEM_SEG_SIZE here, AX_PTP_CLK_EN, and the AX_PTP_LCK_CTRL0_* group (including the unused typo AX_PTP_LCK_CTRL0_80B_S_E alongside AX_PTP_LCK_CTRL0_80B_S_EN further down). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129-ptp-v1-0-8= 148c402beaf@birger-koblitz.de?part=3D2