git: 690c3fbbe1ed - main - mbuf: remove remnants of caddr_t

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Fri, 16 Oct 2026 21:17:26 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=690c3fbbe1ed31d551a81e665e3f6dbdaadb045e

commit 690c3fbbe1ed31d551a81e665e3f6dbdaadb045e
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-10-16 21:09:19 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-10-16 21:09:19 +0000

    mbuf: remove remnants of caddr_t
    
    caddr_t is a typedef for a character pointer (char *) that originated in
    Version 7 Unix, released by AT&T in 1979.  It became obsolete in 1989,
    when ANSI C introduced void *.
    
    There is a lot of code that uses m->m_data for arithmetics, thus we can't
    switch it to void * easily.  Let's at least stop proliferation of caddr_t.
    We have developers that are twice younger than obsoletion of this type.
    
    Reviewed by:            zlei, tuexen, adrian
    Differential Revision:  https://reviews.freebsd.org/D60736
---
 sys/kern/uipc_mbuf.c | 27 +++++++++++++++------------
 sys/sys/mbuf.h       | 10 +++++-----
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 726d3ccb5536..5e9c13c55881 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -648,7 +648,7 @@ nospace:
 }
 
 static void
-m_copyfromunmapped(const struct mbuf *m, int off, int len, caddr_t cp)
+m_copyfromunmapped(const struct mbuf *m, int off, int len, void *data)
 {
 	struct iovec iov;
 	struct uio uio;
@@ -658,7 +658,7 @@ m_copyfromunmapped(const struct mbuf *m, int off, int len, caddr_t cp)
 	KASSERT(len >= 0, ("m_copyfromunmapped: negative len %d", len));
 	KASSERT(off < m->m_len,
 	    ("m_copyfromunmapped: len exceeds mbuf length"));
-	iov.iov_base = cp;
+	iov.iov_base = data;
 	iov.iov_len = len;
 	uio.uio_resid = len;
 	uio.uio_iov = &iov;
@@ -676,8 +676,9 @@ m_copyfromunmapped(const struct mbuf *m, int off, int len, caddr_t cp)
  * continuing for "len" bytes, into the indicated buffer.
  */
 void
-m_copydata(const struct mbuf *m, int off, int len, caddr_t cp)
+m_copydata(const struct mbuf *m, int off, int len, void *data)
 {
+	char *cp = data;
 	u_int count;
 
 	KASSERT(off >= 0, ("m_copydata, negative off %d", off));
@@ -695,7 +696,7 @@ m_copydata(const struct mbuf *m, int off, int len, caddr_t cp)
 		if ((m->m_flags & M_EXTPG) != 0)
 			m_copyfromunmapped(m, off, count, cp);
 		else
-			bcopy(mtod(m, caddr_t) + off, cp, count);
+			bcopy(mtod(m, char *) + off, cp, count);
 		len -= count;
 		cp += count;
 		off = 0;
@@ -1248,7 +1249,7 @@ m_devget(char *buf, int totlen, int off, struct ifnet *ifp,
 }
 
 static void
-m_copytounmapped(const struct mbuf *m, int off, int len, c_caddr_t cp)
+m_copytounmapped(const struct mbuf *m, int off, int len, const void *data)
 {
 	struct iovec iov;
 	struct uio uio;
@@ -1257,7 +1258,7 @@ m_copytounmapped(const struct mbuf *m, int off, int len, c_caddr_t cp)
 	KASSERT(off >= 0, ("m_copytounmapped: negative off %d", off));
 	KASSERT(len >= 0, ("m_copytounmapped: negative len %d", len));
 	KASSERT(off < m->m_len, ("m_copytounmapped: len exceeds mbuf length"));
-	iov.iov_base = __DECONST(caddr_t, cp);
+	iov.iov_base = __DECONST(void *, data);
 	iov.iov_len = len;
 	uio.uio_resid = len;
 	uio.uio_iov = &iov;
@@ -1276,8 +1277,9 @@ m_copytounmapped(const struct mbuf *m, int off, int len, c_caddr_t cp)
  * chain if necessary.
  */
 void
-m_copyback(struct mbuf *m0, int off, int len, c_caddr_t cp)
+m_copyback(struct mbuf *m0, int off, int len, const void *data)
 {
+	const char *cp = data;
 	int mlen;
 	struct mbuf *m = m0, *n;
 	int totlen = 0;
@@ -1291,7 +1293,7 @@ m_copyback(struct mbuf *m0, int off, int len, c_caddr_t cp)
 			n = m_get(M_NOWAIT, m->m_type);
 			if (n == NULL)
 				goto out;
-			bzero(mtod(n, caddr_t), MLEN);
+			bzero(mtod(n, void *), MLEN);
 			n->m_len = min(MLEN, len + off);
 			m->m_next = n;
 		}
@@ -1306,7 +1308,7 @@ m_copyback(struct mbuf *m0, int off, int len, c_caddr_t cp)
 		if ((m->m_flags & M_EXTPG) != 0)
 			m_copytounmapped(m, off, mlen, cp);
 		else
-			bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen);
+			bcopy(cp, mtod(m, char *) + off, (u_int)mlen);
 		cp += mlen;
 		len -= mlen;
 		mlen += off;
@@ -1335,8 +1337,9 @@ out:	if (((m = m0)->m_flags & M_PKTHDR) && (m->m_pkthdr.len < totlen))
  * Return 1 if able to complete the job; otherwise 0.
  */
 int
-m_append(struct mbuf *m0, int len, c_caddr_t cp)
+m_append(struct mbuf *m0, int len, const void *data)
 {
+	const char *cp = data;
 	struct mbuf *m, *n;
 	int remainder, space;
 
@@ -1350,7 +1353,7 @@ m_append(struct mbuf *m0, int len, c_caddr_t cp)
 		 */
 		if (space > remainder)
 			space = remainder;
-		bcopy(cp, mtod(m, caddr_t) + m->m_len, space);
+		bcopy(cp, mtod(m, char *) + m->m_len, space);
 		m->m_len += space;
 		cp += space, remainder -= space;
 	}
@@ -1363,7 +1366,7 @@ m_append(struct mbuf *m0, int len, c_caddr_t cp)
 		if (n == NULL)
 			break;
 		n->m_len = min(MLEN, remainder);
-		bcopy(cp, mtod(n, caddr_t), n->m_len);
+		bcopy(cp, mtod(n, void *), n->m_len);
 		cp += n->m_len, remainder -= n->m_len;
 		m->m_next = n;
 		m = n;
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 86b7f3770bf6..7651562f1392 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -344,7 +344,7 @@ struct mbuf {
 		SLIST_ENTRY(mbuf)	m_slistpkt;
 		STAILQ_ENTRY(mbuf)	m_stailqpkt;
 	};
-	caddr_t		 m_data;	/* location of data */
+	char		*m_data;	/* location of data */
 	int32_t		 m_len;		/* amount of data in this mbuf */
 	uint32_t	 m_type:8,	/* type of data in this mbuf */
 			 m_flags:24;	/* flags; see below */
@@ -823,14 +823,14 @@ void		 m_adj(struct mbuf *, int);
 void		 m_adj_decap(struct mbuf *, int);
 int		 m_apply(struct mbuf *, int, int,
 		    int (*)(void *, void *, u_int), void *);
-int		 m_append(struct mbuf *, int, c_caddr_t);
+int		 m_append(struct mbuf *, int, const void *);
 void		 m_cat(struct mbuf *, struct mbuf *);
 void		 m_catpkt(struct mbuf *, struct mbuf *);
 int		 m_clget(struct mbuf *m, int how);
 void 		*m_cljget(struct mbuf *m, int how, int size);
 struct mbuf	*m_collapse(struct mbuf *, int, int);
-void		 m_copyback(struct mbuf *, int, int, c_caddr_t);
-void		 m_copydata(const struct mbuf *, int, int, caddr_t);
+void		 m_copyback(struct mbuf *, int, int, const void *);
+void		 m_copydata(const struct mbuf *, int, int, void *);
 struct mbuf	*m_copym(struct mbuf *, int, int, int);
 struct mbuf	*m_copypacket(struct mbuf *, int);
 void		 m_copy_pkthdr(struct mbuf *, struct mbuf *);
@@ -839,7 +839,7 @@ struct mbuf	*m_defrag(struct mbuf *, int);
 void		 m_demote_pkthdr(struct mbuf *);
 void		 m_demote(struct mbuf *, int, int);
 struct mbuf	*m_devget(char *, int, int, struct ifnet *,
-		    void (*)(char *, caddr_t, u_int));
+		    void (*)(char *, char *, u_int));
 void		 m_dispose_extcontrolm(struct mbuf *m);
 struct mbuf	*m_dup(const struct mbuf *, int);
 int		 m_dup_pkthdr(struct mbuf *, const struct mbuf *, int);