don't set dv_private. it's a bad pattern and only didn't

trip kmem_free() lossage because struct usbnet is at the
start of the softc.

for now, enforce this as part of the ABI.

catch up urndis with tx_prepare checking buffer length,
and also add an assert to usbnet_start_locked() to match.
This commit is contained in:
mrg 2019-08-11 23:55:43 +00:00
parent 662413259f
commit c9e9d49af6
5 changed files with 23 additions and 20 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_axe.c,v 1.112 2019/08/11 05:14:41 mrg Exp $ */
/* $NetBSD: if_axe.c,v 1.113 2019/08/11 23:55:43 mrg Exp $ */
/* $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
/*
@ -87,7 +87,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.112 2019/08/11 05:14:41 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.113 2019/08/11 23:55:43 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -873,8 +873,7 @@ axe_attach(device_t parent, device_t self, void *aux)
unsigned bufsz;
int i;
/* Switch to usbnet for device_private() */
self->dv_private = un;
KASSERT((void *)sc == un);
aprint_naive("\n");
aprint_normal("\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_smsc.c,v 1.55 2019/08/11 12:16:59 skrll Exp $ */
/* $NetBSD: if_smsc.c,v 1.56 2019/08/11 23:55:43 mrg Exp $ */
/* $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */
/* $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.55 2019/08/11 12:16:59 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.56 2019/08/11 23:55:43 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -823,8 +823,7 @@ smsc_attach(device_t parent, device_t self, void *aux)
int err, i;
uint32_t mac_h, mac_l;
/* Switch to usbnet for device_private() */
self->dv_private = un;
KASSERT((void *)sc == un);
aprint_naive("\n");
aprint_normal("\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ure.c,v 1.24 2019/08/11 08:57:36 skrll Exp $ */
/* $NetBSD: if_ure.c,v 1.25 2019/08/11 23:55:43 mrg Exp $ */
/* $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */
/*-
@ -30,7 +30,7 @@
/* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.24 2019/08/11 08:57:36 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.25 2019/08/11 23:55:43 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -842,9 +842,6 @@ ure_attach(device_t parent, device_t self, void *aux)
uint8_t eaddr[8]; /* 2byte padded */
char *devinfop;
/* Switch to usbnet for device_private() */
self->dv_private = un;
aprint_naive("\n");
aprint_normal("\n");
devinfop = usbd_devinfo_alloc(dev, 0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_urndis.c,v 1.28 2019/08/11 13:16:10 hannken Exp $ */
/* $NetBSD: if_urndis.c,v 1.29 2019/08/11 23:55:43 mrg Exp $ */
/* $OpenBSD: if_urndis.c,v 1.31 2011/07/03 15:47:17 matthew Exp $ */
/*
@ -21,7 +21,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.28 2019/08/11 13:16:10 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.29 2019/08/11 23:55:43 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -720,6 +720,11 @@ urndis_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
{
struct rndis_packet_msg *msg;
usbnet_isowned_tx(un);
if (m->m_pkthdr.len > un->un_tx_bufsz - sizeof(*msg))
return 0;
msg = (struct rndis_packet_msg *)c->unc_buf;
memset(msg, 0, sizeof(*msg));
@ -929,8 +934,7 @@ urndis_attach(device_t parent, device_t self, void *aux)
uint32_t filter;
char *devinfop;
/* Switch to usbnet for device_private() */
self->dv_private = un;
KASSERT((void *)sc == un);
aprint_naive("\n");
aprint_normal("\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbnet.c,v 1.12 2019/08/11 01:31:19 mrg Exp $ */
/* $NetBSD: usbnet.c,v 1.13 2019/08/11 23:55:43 mrg Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@ -29,11 +29,11 @@
*/
/*
* Common code shared between USB ethernet drivers.
* Common code shared between USB network drivers.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.12 2019/08/11 01:31:19 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.13 2019/08/11 23:55:43 mrg Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -438,6 +438,7 @@ usbnet_start_locked(struct ifnet *ifp)
IFQ_POLL(&ifp->if_snd, m);
if (m == NULL)
break;
KASSERT(m->m_pkthdr.len <= un->un_tx_bufsz);
struct usbnet_chain *c = &cd->uncd_tx_chain[idx];
@ -1274,6 +1275,9 @@ usbnet_attach(struct usbnet *un,
KASSERT(un->un_rx_list_cnt);
KASSERT(un->un_tx_list_cnt);
/* Unfortunate fact. */
KASSERT(un == device_private(un->un_dev));
un->un_pri = kmem_zalloc(sizeof(*un->un_pri), KM_SLEEP);
struct usbnet_private * const unp = un->un_pri;