Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb don't set dv_private. it's a bad pattern and on...
details: https://anonhg.NetBSD.org/src/rev/78dda1e6048f
branches: trunk
changeset: 453439:78dda1e6048f
user: mrg <mrg%NetBSD.org@localhost>
date: Sun Aug 11 23:55:43 2019 +0000
description:
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.
diffstat:
sys/dev/usb/if_axe.c | 7 +++----
sys/dev/usb/if_smsc.c | 7 +++----
sys/dev/usb/if_ure.c | 7 ++-----
sys/dev/usb/if_urndis.c | 12 ++++++++----
sys/dev/usb/usbnet.c | 10 +++++++---
5 files changed, 23 insertions(+), 20 deletions(-)
diffs (165 lines):
diff -r da343f5c50c4 -r 78dda1e6048f sys/dev/usb/if_axe.c
--- a/sys/dev/usb/if_axe.c Sun Aug 11 22:55:03 2019 +0000
+++ b/sys/dev/usb/if_axe.c Sun Aug 11 23:55:43 2019 +0000
@@ -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 @@
unsigned bufsz;
int i;
- /* Switch to usbnet for device_private() */
- self->dv_private = un;
+ KASSERT((void *)sc == un);
aprint_naive("\n");
aprint_normal("\n");
diff -r da343f5c50c4 -r 78dda1e6048f sys/dev/usb/if_smsc.c
--- a/sys/dev/usb/if_smsc.c Sun Aug 11 22:55:03 2019 +0000
+++ b/sys/dev/usb/if_smsc.c Sun Aug 11 23:55:43 2019 +0000
@@ -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 @@
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");
diff -r da343f5c50c4 -r 78dda1e6048f sys/dev/usb/if_ure.c
--- a/sys/dev/usb/if_ure.c Sun Aug 11 22:55:03 2019 +0000
+++ b/sys/dev/usb/if_ure.c Sun Aug 11 23:55:43 2019 +0000
@@ -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 @@
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);
diff -r da343f5c50c4 -r 78dda1e6048f sys/dev/usb/if_urndis.c
--- a/sys/dev/usb/if_urndis.c Sun Aug 11 22:55:03 2019 +0000
+++ b/sys/dev/usb/if_urndis.c Sun Aug 11 23:55:43 2019 +0000
@@ -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 @@
{
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 @@
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");
diff -r da343f5c50c4 -r 78dda1e6048f sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c Sun Aug 11 22:55:03 2019 +0000
+++ b/sys/dev/usb/usbnet.c Sun Aug 11 23:55:43 2019 +0000
@@ -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 @@
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 @@
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;
Home |
Main Index |
Thread Index |
Old Index