diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-09-01 16:02:07 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-09-01 16:02:07 +0000 |
commit | 8c21b12d97572662476182c394c95357d834b9f6 (patch) | |
tree | e55fe429431752301a0bd3d797c36f7c0708bb43 /sys/dev/usb/if_urtw.c | |
parent | 48e679f5a5de1ec9a7e98a7575dc0bc072af99c6 (diff) |
Set the configuration number and get the interface handle in attach(),
like urtwn(4) does, to prevent a null dereference of the configuration
descriptor.
Issue reported and fix tested by Ludovic Coues on misc@
Diffstat (limited to 'sys/dev/usb/if_urtw.c')
-rw-r--r-- | sys/dev/usb/if_urtw.c | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/sys/dev/usb/if_urtw.c b/sys/dev/usb/if_urtw.c index 8ab6f4a6b44..7407a790b3a 100644 --- a/sys/dev/usb/if_urtw.c +++ b/sys/dev/usb/if_urtw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urtw.c,v 1.47 2014/07/13 15:52:49 mpi Exp $ */ +/* $OpenBSD: if_urtw.c,v 1.48 2014/09/01 16:02:06 mpi Exp $ */ /*- * Copyright (c) 2009 Martynas Venckus <martynas@openbsd.org> @@ -608,6 +608,19 @@ urtw_attach(struct device *parent, struct device *self, void *aux) sc->sc_udev = uaa->device; sc->sc_hwrev = urtw_lookup(uaa->vendor, uaa->product)->rev; + if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) { + printf("%s: could not set configuration no\n", + sc->sc_dev.dv_xname); + return; + } + + /* Get the first interface handle. */ + if (usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface) != 0) { + printf("%s: could not get interface handle\n", + sc->sc_dev.dv_xname); + return; + } + printf("%s: ", sc->sc_dev.dv_xname); if (sc->sc_hwrev & URTW_HWREV_8187) { @@ -2297,20 +2310,6 @@ urtw_init(struct ifnet *ifp) sc->sc_txtimer = 0; if (!(sc->sc_flags & URTW_INIT_ONCE)) { - error = usbd_set_config_no(sc->sc_udev, URTW_CONFIG_NO, 0); - if (error != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - goto fail; - } - /* get the first interface handle */ - error = usbd_device2interface_handle(sc->sc_udev, - URTW_IFACE_INDEX, &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - goto fail; - } error = urtw_open_pipes(sc); if (error != 0) goto fail; @@ -3730,20 +3729,6 @@ urtw_8187b_init(struct ifnet *ifp) sc->sc_txtimer = 0; if (!(sc->sc_flags & URTW_INIT_ONCE)) { - error = usbd_set_config_no(sc->sc_udev, URTW_CONFIG_NO, 0); - if (error != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - goto fail; - } - /* Get the first interface handle. */ - error = usbd_device2interface_handle(sc->sc_udev, - URTW_IFACE_INDEX, &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - goto fail; - } error = urtw_open_pipes(sc); if (error != 0) goto fail; |