diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-11-10 15:29:23 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-11-10 15:29:23 +0000 |
commit | f436bcaa89e46f73146f84edb80e157c6f73b1af (patch) | |
tree | 5319995ba2e5f703b6efc4b545d6655a6f723d4f /sys/dev/usb | |
parent | 5da860ade2e693bc6837216a9710d6a54da0bce7 (diff) |
Pass free(9) sizes for port arrays.
ok tedu@, visa@
Diffstat (limited to 'sys/dev/usb')
-rw-r--r-- | sys/dev/usb/uhub.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c index afab99e7936..c4ee5c0f12a 100644 --- a/sys/dev/usb/uhub.c +++ b/sys/dev/usb/uhub.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhub.c,v 1.90 2017/04/08 02:57:25 deraadt Exp $ */ +/* $OpenBSD: uhub.c,v 1.91 2018/11/10 15:29:22 mpi Exp $ */ /* $NetBSD: uhub.c,v 1.64 2003/02/08 03:32:51 ichiro Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */ @@ -292,7 +292,7 @@ uhub_attach(struct device *parent, struct device *self, void *aux) if (UHUB_IS_HIGH_SPEED(sc)) { tts = mallocarray((UHUB_IS_SINGLE_TT(sc) ? 1 : nports), - sizeof (struct usbd_tt), M_USBDEV, M_NOWAIT); + sizeof(struct usbd_tt), M_USBDEV, M_NOWAIT); if (!tts) goto bad; } @@ -339,12 +339,10 @@ uhub_attach(struct device *parent, struct device *self, void *aux) return; bad: - if (sc->sc_statusbuf) - free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen); + free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen); if (hub) { - if (hub->ports) - free(hub->ports, M_USBDEV, 0); - free(hub, M_USBDEV, sizeof *hub); + free(hub->ports, M_USBDEV, hub->nports * sizeof(*hub->ports)); + free(hub, M_USBDEV, sizeof(*hub)); } dev->hub = NULL; } @@ -474,13 +472,11 @@ uhub_detach(struct device *self, int flags) } } - if (hub->ports[0].tt) - free(hub->ports[0].tt, M_USBDEV, 0); - if (sc->sc_statusbuf) - free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen); - if (hub->ports) - free(hub->ports, M_USBDEV, 0); - free(hub, M_USBDEV, sizeof *hub); + free(hub->ports[0].tt, M_USBDEV, + (UHUB_IS_SINGLE_TT(sc) ? 1 : hub->nports) * sizeof(struct usbd_tt)); + free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen); + free(hub->ports, M_USBDEV, hub->nports * sizeof(*hub->ports)); + free(hub, M_USBDEV, sizeof(*hub)); sc->sc_hub->hub = NULL; return (0); |