From 421a7047e5223630e7cb3b4a13e08aa572f50a39 Mon Sep 17 00:00:00 2001 From: Eric Ackermann Date: Fri, 11 Apr 2025 18:44:06 +0200 Subject: [PATCH] net: gPTP: Fix pointer type in gptp_add_port The number of ports in gptp_domain.default_ds.nb_ports is a uint8_t. A pointer to it is passed to gptp_add_port. However, in this method, the pointer is cast to an int pointer. The C compiler generates an int-size store for this. In addition to potentially overwriting adjacent attributes, on platforms such as RISC-V that do not support unaligned accesses, this causes an exception on access. This commit casts nb_ports to the correct type, uint8_t. Signed-off-by: Eric Ackermann --- subsys/net/l2/ethernet/gptp/gptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/ethernet/gptp/gptp.c b/subsys/net/l2/ethernet/gptp/gptp.c index 67eb3296fbd..e22b10c515d 100644 --- a/subsys/net/l2/ethernet/gptp/gptp.c +++ b/subsys/net/l2/ethernet/gptp/gptp.c @@ -586,7 +586,7 @@ static void gptp_thread(void *p1, void *p2, void *p3) static void gptp_add_port(struct net_if *iface, void *user_data) { - int *num_ports = user_data; + uint8_t *num_ports = user_data; const struct device *clk; if (*num_ports >= CONFIG_NET_GPTP_NUM_PORTS) {