diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-11-17 20:17:11 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-11-17 20:17:11 +0000 |
commit | b7040577ec9a71296c5e8bb548f9d3173fe4f679 (patch) | |
tree | 2c38104ef2d95ff02465374777cb4dc3e91d8f51 /sys/dev/usb/usb_subr.c | |
parent | 216030c0a0d8b3fe6279a516e9640c3cf356c9f3 (diff) |
free(9) size for USB subdevs array.
ok ratchov@, visa@
Diffstat (limited to 'sys/dev/usb/usb_subr.c')
-rw-r--r-- | sys/dev/usb/usb_subr.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index 8bfd5516c30..540833d0554 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_subr.c,v 1.141 2018/11/16 11:56:42 mpi Exp $ */ +/* $OpenBSD: usb_subr.c,v 1.142 2018/11/17 20:17:10 mpi Exp $ */ /* $NetBSD: usb_subr.c,v 1.103 2003/01/10 11:19:13 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -894,6 +894,7 @@ usbd_probe_and_attach(struct device *parent, struct usbd_device *dev, int port, err = USBD_NOMEM; goto fail; } + dev->nsubdev = 2; dev->subdevs[dev->ndevs++] = dv; dev->subdevs[dev->ndevs] = 0; err = USBD_NORMAL_COMPLETION; @@ -936,6 +937,7 @@ usbd_probe_and_attach(struct device *parent, struct usbd_device *dev, int port, /* add 1 for possible ugen and 1 for NULL terminator */ dev->subdevs = mallocarray(nifaces + 2, sizeof(dv), M_USB, M_NOWAIT | M_ZERO); + dev->nsubdev = nifaces + 2; if (dev->subdevs == NULL) { free(ifaces, M_USB, nifaces * sizeof(*ifaces)); err = USBD_NOMEM; @@ -967,8 +969,9 @@ usbd_probe_and_attach(struct device *parent, struct usbd_device *dev, int port, goto fail; } - free(dev->subdevs, M_USB, (nifaces + 2) * sizeof(dv)); + free(dev->subdevs, M_USB, dev->nsubdev * sizeof(*dev->subdevs)); dev->subdevs = NULL; + dev->nsubdev = 0; } /* No interfaces were attached in any of the configurations. */ @@ -993,6 +996,7 @@ generic: goto fail; } } + dev->nsubdev = 2; dev->subdevs[dev->ndevs++] = dv; dev->subdevs[dev->ndevs] = 0; err = USBD_NORMAL_COMPLETION; @@ -1410,8 +1414,7 @@ usb_free_device(struct usbd_device *dev) } if (dev->cdesc != NULL) free(dev->cdesc, M_USB, UGETW(dev->cdesc->wTotalLength)); - if (dev->subdevs != NULL) - free(dev->subdevs, M_USB, 0); + free(dev->subdevs, M_USB, dev->nsubdev * sizeof(*dev->subdevs)); dev->bus->devices[dev->address] = NULL; if (dev->vendor != NULL) |