Module Name:    src
Committed By:   andvar
Date:           Tue Aug 22 07:13:33 UTC 2023

Modified Files:
        src/sys/arch/newsmips/apbus: if_sn.c

Log Message:
newsmips: fix build with SNDEBUG option enabled.

It was broken since rev 1.21 24 years ago, and got more broken code later on:
remove leftover device_xname(sc->sc_dev) param from aprint_debug_dev in one 
block.
fix wrong method name devoce_xname to device_xname in second block.
rename et to eh for consistency, and define it (definition was removed in the 
past).
while here, improve the code with riastradh help to make it safer.

pullup to at least netbsd-10 is needed.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/newsmips/apbus/if_sn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/newsmips/apbus/if_sn.c
diff -u src/sys/arch/newsmips/apbus/if_sn.c:1.52 src/sys/arch/newsmips/apbus/if_sn.c:1.53
--- src/sys/arch/newsmips/apbus/if_sn.c:1.52	Sun Sep 18 12:49:34 2022
+++ src/sys/arch/newsmips/apbus/if_sn.c	Tue Aug 22 07:13:33 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sn.c,v 1.52 2022/09/18 12:49:34 thorpej Exp $	*/
+/*	$NetBSD: if_sn.c,v 1.53 2023/08/22 07:13:33 andvar Exp $	*/
 
 /*
  * National Semiconductor  DP8393X SONIC Driver
@@ -16,7 +16,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.52 2022/09/18 12:49:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.53 2023/08/22 07:13:33 andvar Exp $");
 
 #include "opt_inet.h"
 
@@ -202,7 +202,7 @@ snsetup(struct sn_softc	*sc, uint8_t *ll
 
 #ifdef SNDEBUG
 	aprint_debug_dev(sc->sc_dev, "buffers: rra=%p cda=%p rda=%p tda=%p\n",
-	    device_xname(sc->sc_dev), sc->p_rra[0], sc->p_cda,
+	    sc->p_rra[0], sc->p_cda,
 	    sc->p_rda, sc->mtda[0].mtd_txp);
 #endif
 
@@ -1033,15 +1033,6 @@ sonic_read(struct sn_softc *sc, void *pk
 	struct ifnet *ifp = &sc->sc_if;
 	struct mbuf *m;
 
-#ifdef SNDEBUG
-	{
-		printf("%s: rcvd %p len=%d type=0x%x from %s",
-		    devoce_xname(sc->sc_dev), et, len, htons(et->ether_type),
-		    ether_sprintf(et->ether_shost));
-		printf(" (to %s)\n", ether_sprintf(et->ether_dhost));
-	}
-#endif /* SNDEBUG */
-
 	if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN) ||
 	    len > (ETHER_MAX_LEN - ETHER_CRC_LEN)) {
 		printf("%s: invalid packet length %d bytes\n",
@@ -1049,6 +1040,18 @@ sonic_read(struct sn_softc *sc, void *pk
 		return 0;
 	}
 
+#ifdef SNDEBUG
+	{       
+		struct ether_header eh_s, *eh = &eh_s;
+		memcpy(eh, pkt, sizeof(*eh));
+		CTASSERT(sizeof(*eh) <= ETHER_MIN_LEN);
+		printf("%s: rcvd %p len=%d type=0x%x from %s",
+		    device_xname(sc->sc_dev), eh, len, htons(eh->ether_type),
+		    ether_sprintf(eh->ether_shost));
+		printf(" (to %s)\n", ether_sprintf(eh->ether_dhost));
+	}       
+#endif /* SNDEBUG */
+
 	m = sonic_get(sc, pkt, len);
 	if (m == NULL)
 		return 0;

Reply via email to