Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb move the deallocation of the protocol-specific s...
details: https://anonhg.NetBSD.org/src/rev/4bd52d91c1b4
branches: trunk
changeset: 448836:4bd52d91c1b4
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Sun Feb 10 19:23:55 2019 +0000
description:
move the deallocation of the protocol-specific softc into its own detach hook,
so that calls to kmem_alloc() and kmem_free() would agree on the size
fixes panic on umass detach reported by Tom Ivar Helbekkmo on current-users@
diffstat:
sys/dev/usb/umass.c | 26 ++++++++++++++++++++++----
sys/dev/usb/umass_isdata.c | 7 +++++--
sys/dev/usb/umass_scsipi.c | 22 ++++++++++++++++++++--
sys/dev/usb/umass_scsipi.h | 5 ++++-
4 files changed, 51 insertions(+), 9 deletions(-)
diffs (149 lines):
diff -r af93be80b7a8 -r 4bd52d91c1b4 sys/dev/usb/umass.c
--- a/sys/dev/usb/umass.c Sun Feb 10 19:21:52 2019 +0000
+++ b/sys/dev/usb/umass.c Sun Feb 10 19:23:55 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: umass.c,v 1.173 2019/02/07 13:48:27 skrll Exp $ */
+/* $NetBSD: umass.c,v 1.174 2019/02/10 19:23:55 jdolecek Exp $ */
/*
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -124,7 +124,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.173 2019/02/07 13:48:27 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.174 2019/02/10 19:23:55 jdolecek Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -828,6 +828,24 @@
rv = config_detach(scbus->sc_child, flags);
switch (sc->sc_cmd) {
+ case UMASS_CPROTO_RBC:
+ case UMASS_CPROTO_SCSI:
+#if NSCSIBUS > 0
+ umass_scsi_detach(sc);
+#else
+ aprint_error_dev(self, "scsibus not configured\n");
+#endif
+ break;
+
+ case UMASS_CPROTO_UFI:
+ case UMASS_CPROTO_ATAPI:
+#if NATAPIBUS > 0
+ umass_atapi_detach(sc);
+#else
+ aprint_error_dev(self, "atapibus not configured\n");
+#endif
+ break;
+
case UMASS_CPROTO_ISD_ATA:
#if NWD > 0
umass_isdata_detach(sc);
@@ -841,8 +859,8 @@
break;
}
- kmem_free(scbus, sizeof(*scbus));
- sc->bus = NULL;
+ /* protocol detach is expected to free sc->bus */
+ KASSERT(sc->bus == NULL);
}
if (rv != 0)
diff -r af93be80b7a8 -r 4bd52d91c1b4 sys/dev/usb/umass_isdata.c
--- a/sys/dev/usb/umass_isdata.c Sun Feb 10 19:21:52 2019 +0000
+++ b/sys/dev/usb/umass_isdata.c Sun Feb 10 19:23:55 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: umass_isdata.c,v 1.41 2019/02/07 13:48:27 skrll Exp $ */
+/* $NetBSD: umass_isdata.c,v 1.42 2019/02/10 19:23:55 jdolecek Exp $ */
/*
* TODO:
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass_isdata.c,v 1.41 2019/02/07 13:48:27 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_isdata.c,v 1.42 2019/02/10 19:23:55 jdolecek Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -244,6 +244,9 @@
struct uisdata_softc *scbus = (struct uisdata_softc *)sc->bus;
ata_channel_destroy(&scbus->sc_channel);
+
+ kmem_free(scbus, sizeof(*scbus));
+ sc->bus = NULL;
}
void
diff -r af93be80b7a8 -r 4bd52d91c1b4 sys/dev/usb/umass_scsipi.c
--- a/sys/dev/usb/umass_scsipi.c Sun Feb 10 19:21:52 2019 +0000
+++ b/sys/dev/usb/umass_scsipi.c Sun Feb 10 19:23:55 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: umass_scsipi.c,v 1.59 2019/02/07 13:48:27 skrll Exp $ */
+/* $NetBSD: umass_scsipi.c,v 1.60 2019/02/10 19:23:55 jdolecek Exp $ */
/*
* Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.59 2019/02/07 13:48:27 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.60 2019/02/10 19:23:55 jdolecek Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -151,6 +151,15 @@
return 0;
}
+
+void
+umass_scsi_detach(struct umass_softc *sc)
+{
+ struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus;
+
+ kmem_free(scbus, sizeof(*scbus));
+ sc->bus = NULL;
+}
#endif
#if NATAPIBUS > 0
@@ -183,6 +192,15 @@
return 0;
}
+
+void
+umass_atapi_detach(struct umass_softc *sc)
+{
+ struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus;
+
+ kmem_free(scbus, sizeof(*scbus));
+ sc->bus = NULL;
+}
#endif
Static struct umass_scsipi_softc *
diff -r af93be80b7a8 -r 4bd52d91c1b4 sys/dev/usb/umass_scsipi.h
--- a/sys/dev/usb/umass_scsipi.h Sun Feb 10 19:21:52 2019 +0000
+++ b/sys/dev/usb/umass_scsipi.h Sun Feb 10 19:23:55 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: umass_scsipi.h,v 1.3 2016/04/23 10:15:32 skrll Exp $ */
+/* $NetBSD: umass_scsipi.h,v 1.4 2019/02/10 19:23:55 jdolecek Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -31,4 +31,7 @@
*/
int umass_scsi_attach(struct umass_softc *);
+void umass_scsi_detach(struct umass_softc *);
+
int umass_atapi_attach(struct umass_softc *);
+void umass_atapi_detach(struct umass_softc *);
Home |
Main Index |
Thread Index |
Old Index