From 2d8a425be01526b346810a775893b950bb4ac399 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Fri, 8 Feb 2013 21:15:47 +0000 Subject: [PATCH] Fix regression issue after r244503: Correct init order to fix a NULL pointer access. MFC after: 1 week Reported by: Ian FREISLICH --- sys/dev/usb/wlan/if_uath.c | 26 +++++++++++++------------- sys/dev/usb/wlan/if_upgt.c | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/sys/dev/usb/wlan/if_uath.c b/sys/dev/usb/wlan/if_uath.c index 0ac57afd6a2d..37162c089313 100644 --- a/sys/dev/usb/wlan/if_uath.c +++ b/sys/dev/usb/wlan/if_uath.c @@ -358,22 +358,12 @@ uath_attach(device_t dev) callout_init(&sc->stat_ch, 0); callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); - /* - * Allocate xfers for firmware commands. - */ - error = uath_alloc_cmd_list(sc, sc->sc_cmd); - if (error != 0) { - device_printf(sc->sc_dev, - "could not allocate Tx command list\n"); - goto fail; - } - error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, uath_usbconfig, UATH_N_XFERS, sc, &sc->sc_mtx); if (error) { device_printf(dev, "could not allocate USB transfers, " "err=%s\n", usbd_errstr(error)); - goto fail1; + goto fail; } sc->sc_cmd_dma_buf = @@ -381,6 +371,16 @@ uath_attach(device_t dev) sc->sc_tx_dma_buf = usbd_xfer_get_frame_buffer(sc->sc_xfer[UATH_BULK_TX], 0); + /* + * Setup buffers for firmware commands. + */ + error = uath_alloc_cmd_list(sc, sc->sc_cmd); + if (error != 0) { + device_printf(sc->sc_dev, + "could not allocate Tx command list\n"); + goto fail1; + } + /* * We're now ready to send+receive firmware commands. */ @@ -492,8 +492,8 @@ uath_attach(device_t dev) fail4: if_free(ifp); fail3: UATH_UNLOCK(sc); -fail2: usbd_transfer_unsetup(sc->sc_xfer, UATH_N_XFERS); -fail1: uath_free_cmd_list(sc, sc->sc_cmd); +fail2: uath_free_cmd_list(sc, sc->sc_cmd); +fail1: usbd_transfer_unsetup(sc->sc_xfer, UATH_N_XFERS); fail: return (error); } diff --git a/sys/dev/usb/wlan/if_upgt.c b/sys/dev/usb/wlan/if_upgt.c index c625926795f6..6b49df1f836b 100644 --- a/sys/dev/usb/wlan/if_upgt.c +++ b/sys/dev/usb/wlan/if_upgt.c @@ -259,20 +259,12 @@ upgt_attach(device_t dev) callout_init(&sc->sc_led_ch, 0); callout_init(&sc->sc_watchdog_ch, 0); - /* Allocate TX and RX xfers. */ - error = upgt_alloc_tx(sc); - if (error) - goto fail1; - error = upgt_alloc_rx(sc); - if (error) - goto fail2; - error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, upgt_config, UPGT_N_XFERS, sc, &sc->sc_mtx); if (error) { device_printf(dev, "could not allocate USB transfers, " "err=%s\n", usbd_errstr(error)); - goto fail3; + goto fail1; } sc->sc_rx_dma_buf = usbd_xfer_get_frame_buffer( @@ -280,6 +272,14 @@ upgt_attach(device_t dev) sc->sc_tx_dma_buf = usbd_xfer_get_frame_buffer( sc->sc_xfer[UPGT_BULK_TX], 0); + /* Setup TX and RX buffers */ + error = upgt_alloc_tx(sc); + if (error) + goto fail2; + error = upgt_alloc_rx(sc); + if (error) + goto fail3; + ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); if (ifp == NULL) { device_printf(dev, "can not if_alloc()\n"); @@ -382,9 +382,9 @@ upgt_attach(device_t dev) return (0); fail5: if_free(ifp); -fail4: usbd_transfer_unsetup(sc->sc_xfer, UPGT_N_XFERS); -fail3: upgt_free_rx(sc); -fail2: upgt_free_tx(sc); +fail4: upgt_free_rx(sc); +fail3: upgt_free_tx(sc); +fail2: usbd_transfer_unsetup(sc->sc_xfer, UPGT_N_XFERS); fail1: mtx_destroy(&sc->sc_mtx); return (error);