Author: avos
Date: Mon Jan  4 21:11:27 2016
New Revision: 293179
URL: https://svnweb.freebsd.org/changeset/base/293179

Log:
  iwn: reduce code duplication in iwn_read_firmware()
  
  - Separate 'firmware_put(sc->fw_fp, FIRMWARE_UNLOAD); sc->fw_fp = NULL;'
  into iwn_unload_firmware().
  - Move error handling to the end of iwn_read_firmware().
  
  No functional changes.
  
  Approved by:  adrian (mentor)
  Differential Revision:        https://reviews.freebsd.org/D4768

Modified:
  head/sys/dev/iwn/if_iwn.c

Modified: head/sys/dev/iwn/if_iwn.c
==============================================================================
--- head/sys/dev/iwn/if_iwn.c   Mon Jan  4 21:07:08 2016        (r293178)
+++ head/sys/dev/iwn/if_iwn.c   Mon Jan  4 21:11:27 2016        (r293179)
@@ -318,6 +318,7 @@ static int  iwn_read_firmware_leg(struct 
 static int     iwn_read_firmware_tlv(struct iwn_softc *,
                    struct iwn_fw_info *, uint16_t);
 static int     iwn_read_firmware(struct iwn_softc *);
+static void    iwn_unload_firmware(struct iwn_softc *);
 static int     iwn_clock_wait(struct iwn_softc *);
 static int     iwn_apm_init(struct iwn_softc *);
 static void    iwn_apm_stop_master(struct iwn_softc *);
@@ -8200,9 +8201,8 @@ iwn_read_firmware(struct iwn_softc *sc)
        if (fw->size < sizeof (uint32_t)) {
                device_printf(sc->sc_dev, "%s: firmware too short: %zu bytes\n",
                    __func__, fw->size);
-               firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
-               sc->fw_fp = NULL;
-               return EINVAL;
+               error = EINVAL;
+               goto fail;
        }
 
        /* Retrieve text and data sections. */
@@ -8214,9 +8214,7 @@ iwn_read_firmware(struct iwn_softc *sc)
                device_printf(sc->sc_dev,
                    "%s: could not read firmware sections, error %d\n",
                    __func__, error);
-               firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
-               sc->fw_fp = NULL;
-               return error;
+               goto fail;
        }
 
        device_printf(sc->sc_dev, "%s: ucode rev=0x%08x\n", __func__, 
sc->ucode_rev);
@@ -8230,13 +8228,22 @@ iwn_read_firmware(struct iwn_softc *sc)
            (fw->boot.textsz & 3) != 0) {
                device_printf(sc->sc_dev, "%s: firmware sections too large\n",
                    __func__);
-               firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
-               sc->fw_fp = NULL;
-               return EINVAL;
+               error = EINVAL;
+               goto fail;
        }
 
        /* We can proceed with loading the firmware. */
        return 0;
+
+fail:  iwn_unload_firmware(sc);
+       return error;
+}
+
+static void
+iwn_unload_firmware(struct iwn_softc *sc)
+{
+       firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
+       sc->fw_fp = NULL;
 }
 
 static int
@@ -8724,8 +8731,7 @@ iwn_init_locked(struct iwn_softc *sc)
 
        /* Initialize hardware and upload firmware. */
        error = iwn_hw_init(sc);
-       firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
-       sc->fw_fp = NULL;
+       iwn_unload_firmware(sc);
        if (error != 0) {
                device_printf(sc->sc_dev,
                    "%s: could not initialize hardware, error %d\n", __func__,
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to