Author: mav
Date: Sat Jan 21 08:31:49 2017
New Revision: 312573
URL: https://svnweb.freebsd.org/changeset/base/312573

Log:
  MFC r310555: Some random code cleaning.
  
   - Reduce indentation.
   - Remove extra braces.
   - Add few missing savety checks.

Modified:
  stable/10/sys/cam/ctl/ctl.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cam/ctl/ctl.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl.c Sat Jan 21 08:31:20 2017        (r312572)
+++ stable/10/sys/cam/ctl/ctl.c Sat Jan 21 08:31:49 2017        (r312573)
@@ -426,7 +426,7 @@ static int ctl_init(void);
 void ctl_shutdown(void);
 static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td);
 static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td);
-static int ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio);
+static void ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio);
 static void ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,
                              struct ctl_ooa *ooa_hdr,
                              struct ctl_ooa_entry *kern_entries);
@@ -1026,27 +1026,27 @@ ctl_isc_ua(struct ctl_softc *softc, unio
        uint32_t iid = ctl_get_initindex(&msg->hdr.nexus);
 
        mtx_lock(&softc->ctl_lock);
-       if (msg->hdr.nexus.targ_lun < CTL_MAX_LUNS &&
-           (lun = softc->ctl_luns[msg->hdr.nexus.targ_mapped_lun]) != NULL) {
-               mtx_lock(&lun->lun_lock);
-               mtx_unlock(&softc->ctl_lock);
-               if (msg->ua.ua_type == CTL_UA_THIN_PROV_THRES &&
-                   msg->ua.ua_set)
-                       memcpy(lun->ua_tpt_info, msg->ua.ua_info, 8);
-               if (msg->ua.ua_all) {
-                       if (msg->ua.ua_set)
-                               ctl_est_ua_all(lun, iid, msg->ua.ua_type);
-                       else
-                               ctl_clr_ua_all(lun, iid, msg->ua.ua_type);
-               } else {
-                       if (msg->ua.ua_set)
-                               ctl_est_ua(lun, iid, msg->ua.ua_type);
-                       else
-                               ctl_clr_ua(lun, iid, msg->ua.ua_type);
-               }
-               mtx_unlock(&lun->lun_lock);
-       } else
+       if (msg->hdr.nexus.targ_lun >= CTL_MAX_LUNS ||
+           (lun = softc->ctl_luns[msg->hdr.nexus.targ_mapped_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
+               return;
+       }
+       mtx_lock(&lun->lun_lock);
+       mtx_unlock(&softc->ctl_lock);
+       if (msg->ua.ua_type == CTL_UA_THIN_PROV_THRES && msg->ua.ua_set)
+               memcpy(lun->ua_tpt_info, msg->ua.ua_info, 8);
+       if (msg->ua.ua_all) {
+               if (msg->ua.ua_set)
+                       ctl_est_ua_all(lun, iid, msg->ua.ua_type);
+               else
+                       ctl_clr_ua_all(lun, iid, msg->ua.ua_type);
+       } else {
+               if (msg->ua.ua_set)
+                       ctl_est_ua(lun, iid, msg->ua.ua_type);
+               else
+                       ctl_clr_ua(lun, iid, msg->ua.ua_type);
+       }
+       mtx_unlock(&lun->lun_lock);
 }
 
 static void
@@ -1060,8 +1060,8 @@ ctl_isc_lun_sync(struct ctl_softc *softc
 
        targ_lun = msg->hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
-           ((lun = softc->ctl_luns[targ_lun]) == NULL)) {
+       if (targ_lun >= CTL_MAX_LUNS ||
+           (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                return;
        }
@@ -1291,8 +1291,8 @@ ctl_isc_mode_sync(struct ctl_softc *soft
 
        targ_lun = msg->hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
-           ((lun = softc->ctl_luns[targ_lun]) == NULL)) {
+       if (targ_lun >= CTL_MAX_LUNS ||
+           (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                return;
        }
@@ -2197,7 +2197,7 @@ ctl_create_iid(struct ctl_port *port, in
  * command on this side (XFER mode) or tell the other side to execute it
  * (SER_ONLY mode).
  */
-static int
+static void
 ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio)
 {
        struct ctl_softc *softc = control_softc;
@@ -2205,7 +2205,6 @@ ctl_serialize_other_sc_cmd(struct ctl_sc
        struct ctl_port *port;
        struct ctl_lun *lun;
        const struct ctl_cmd_entry *entry;
-       int retval = 0;
        uint32_t targ_lun;
 
        targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
@@ -2220,24 +2219,10 @@ ctl_serialize_other_sc_cmd(struct ctl_sc
        }
 
        /* Make sure that we know about this LUN. */
-       if ((targ_lun < CTL_MAX_LUNS) &&
-           ((lun = softc->ctl_luns[targ_lun]) != NULL)) {
-               mtx_lock(&lun->lun_lock);
-               mtx_unlock(&softc->ctl_lock);
-               /*
-                * If the LUN is invalid, pretend that it doesn't exist.
-                * It will go away as soon as all pending I/O has been
-                * completed.
-                */
-               if (lun->flags & CTL_LUN_DISABLED) {
-                       mtx_unlock(&lun->lun_lock);
-                       lun = NULL;
-               }
-       } else {
+       if (targ_lun >= CTL_MAX_LUNS ||
+           (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
-               lun = NULL;
-       }
-       if (lun == NULL) {
+
                /*
                 * The other node would not send this request to us unless
                 * received announce that we are primary node for this LUN.
@@ -2247,6 +2232,18 @@ ctl_serialize_other_sc_cmd(struct ctl_sc
                ctl_set_busy(ctsio);
                goto badjuju;
        }
+       mtx_lock(&lun->lun_lock);
+       mtx_unlock(&softc->ctl_lock);
+
+       /*
+        * If the LUN is invalid, pretend that it doesn't exist.
+        * It will go away as soon as all pending I/Os completed.
+        */
+       if (lun->flags & CTL_LUN_DISABLED) {
+               mtx_unlock(&lun->lun_lock);
+               ctl_set_busy(ctsio);
+               goto badjuju;
+       }
 
        entry = ctl_get_cmd_entry(ctsio, NULL);
        if (ctl_scsiio_lun_check(lun, entry, ctsio) != 0) {
@@ -2318,10 +2315,9 @@ badjuju:
                msg_info.hdr.msg_type = CTL_MSG_BAD_JUJU;
                ctl_ha_msg_send(CTL_HA_CHAN_CTL, &msg_info,
                    sizeof(msg_info.scsi), M_WAITOK);
-               retval = 1;
+               ctl_free_io((union ctl_io *)ctsio);
                break;
        }
-       return (retval);
 }
 
 /*
@@ -2676,9 +2672,9 @@ ctl_ioctl(struct cdev *dev, u_long cmd, 
                }
 
                mtx_lock(&softc->ctl_lock);
-               if (((ooa_hdr->flags & CTL_OOA_FLAG_ALL_LUNS) == 0)
-                && ((ooa_hdr->lun_num >= CTL_MAX_LUNS)
-                 || (softc->ctl_luns[ooa_hdr->lun_num] == NULL))) {
+               if ((ooa_hdr->flags & CTL_OOA_FLAG_ALL_LUNS) == 0 &&
+                   (ooa_hdr->lun_num >= CTL_MAX_LUNS ||
+                    softc->ctl_luns[ooa_hdr->lun_num] == NULL)) {
                        mtx_unlock(&softc->ctl_lock);
                        free(entries, M_CTL);
                        printf("%s: CTL_GET_OOA: invalid LUN %ju\n",
@@ -2730,49 +2726,37 @@ ctl_ioctl(struct cdev *dev, u_long cmd, 
 
 #ifdef CTL_IO_DELAY
                mtx_lock(&softc->ctl_lock);
-
-               if ((delay_info->lun_id >= CTL_MAX_LUNS)
-                || (softc->ctl_luns[delay_info->lun_id] == NULL)) {
+               if (delay_info->lun_id >= CTL_MAX_LUNS ||
+                   (lun = softc->ctl_luns[delay_info->lun_id]) == NULL) {
+                       mtx_unlock(&softc->ctl_lock);
                        delay_info->status = CTL_DELAY_STATUS_INVALID_LUN;
-               } else {
-                       lun = softc->ctl_luns[delay_info->lun_id];
-                       mtx_lock(&lun->lun_lock);
-
-                       delay_info->status = CTL_DELAY_STATUS_OK;
-
-                       switch (delay_info->delay_type) {
-                       case CTL_DELAY_TYPE_CONT:
-                               break;
-                       case CTL_DELAY_TYPE_ONESHOT:
-                               break;
-                       default:
-                               delay_info->status =
-                                       CTL_DELAY_STATUS_INVALID_TYPE;
-                               break;
-                       }
-
-                       switch (delay_info->delay_loc) {
-                       case CTL_DELAY_LOC_DATAMOVE:
-                               lun->delay_info.datamove_type =
-                                       delay_info->delay_type;
-                               lun->delay_info.datamove_delay =
-                                       delay_info->delay_secs;
-                               break;
-                       case CTL_DELAY_LOC_DONE:
-                               lun->delay_info.done_type =
-                                       delay_info->delay_type;
-                               lun->delay_info.done_delay =
-                                       delay_info->delay_secs;
-                               break;
-                       default:
-                               delay_info->status =
-                                       CTL_DELAY_STATUS_INVALID_LOC;
-                               break;
-                       }
-                       mtx_unlock(&lun->lun_lock);
+                       break;
                }
-
+               mtx_lock(&lun->lun_lock);
                mtx_unlock(&softc->ctl_lock);
+               delay_info->status = CTL_DELAY_STATUS_OK;
+               switch (delay_info->delay_type) {
+               case CTL_DELAY_TYPE_CONT:
+               case CTL_DELAY_TYPE_ONESHOT:
+                       break;
+               default:
+                       delay_info->status = CTL_DELAY_STATUS_INVALID_TYPE;
+                       break;
+               }
+               switch (delay_info->delay_loc) {
+               case CTL_DELAY_LOC_DATAMOVE:
+                       lun->delay_info.datamove_type = delay_info->delay_type;
+                       lun->delay_info.datamove_delay = delay_info->delay_secs;
+                       break;
+               case CTL_DELAY_LOC_DONE:
+                       lun->delay_info.done_type = delay_info->delay_type;
+                       lun->delay_info.done_delay = delay_info->delay_secs;
+                       break;
+               default:
+                       delay_info->status = CTL_DELAY_STATUS_INVALID_LOC;
+                       break;
+               }
+               mtx_unlock(&lun->lun_lock);
 #else
                delay_info->status = CTL_DELAY_STATUS_NOT_IMPLEMENTED;
 #endif /* CTL_IO_DELAY */
@@ -2823,8 +2807,8 @@ ctl_ioctl(struct cdev *dev, u_long cmd, 
                bcopy(err_desc, new_err_desc, sizeof(*new_err_desc));
 
                mtx_lock(&softc->ctl_lock);
-               lun = softc->ctl_luns[err_desc->lun_id];
-               if (lun == NULL) {
+               if (err_desc->lun_id >= CTL_MAX_LUNS ||
+                   (lun = softc->ctl_luns[err_desc->lun_id]) == NULL) {
                        mtx_unlock(&softc->ctl_lock);
                        free(new_err_desc, M_CTL);
                        printf("%s: CTL_ERROR_INJECT: invalid LUN %ju\n",
@@ -2867,8 +2851,8 @@ ctl_ioctl(struct cdev *dev, u_long cmd, 
                delete_done = 0;
 
                mtx_lock(&softc->ctl_lock);
-               lun = softc->ctl_luns[delete_desc->lun_id];
-               if (lun == NULL) {
+               if (delete_desc->lun_id >= CTL_MAX_LUNS ||
+                   (lun = softc->ctl_luns[delete_desc->lun_id]) == NULL) {
                        mtx_unlock(&softc->ctl_lock);
                        printf("%s: CTL_ERROR_INJECT_DELETE: invalid LUN %ju\n",
                               __func__, (uintmax_t)delete_desc->lun_id);
@@ -8531,8 +8515,8 @@ ctl_hndl_per_res_out_on_other_sc(union c
 
        targ_lun = msg->hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
-           ((lun = softc->ctl_luns[targ_lun]) == NULL)) {
+       if (targ_lun >= CTL_MAX_LUNS ||
+           (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                return;
        }
@@ -11427,18 +11411,17 @@ ctl_failover_lun(union ctl_io *rio)
 
        /* Find and lock the LUN. */
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun < CTL_MAX_LUNS) &&
-           ((lun = softc->ctl_luns[targ_lun]) != NULL)) {
-               mtx_lock(&lun->lun_lock);
-               mtx_unlock(&softc->ctl_lock);
-               if (lun->flags & CTL_LUN_DISABLED) {
-                       mtx_unlock(&lun->lun_lock);
-                       return;
-               }
-       } else {
+       if (targ_lun > CTL_MAX_LUNS ||
+           (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                return;
        }
+       mtx_lock(&lun->lun_lock);
+       mtx_unlock(&softc->ctl_lock);
+       if (lun->flags & CTL_LUN_DISABLED) {
+               mtx_unlock(&lun->lun_lock);
+               return;
+       }
 
        if (softc->ha_mode == CTL_HA_MODE_XFER) {
                TAILQ_FOREACH_SAFE(io, &lun->ooa_queue, ooa_links, next_io) {
@@ -11506,15 +11489,13 @@ ctl_scsiio_precheck(struct ctl_softc *so
        struct ctl_lun *lun;
        const struct ctl_cmd_entry *entry;
        uint32_t initidx, targ_lun;
-       int retval;
-
-       retval = 0;
+       int retval = 0;
 
        lun = NULL;
-
        targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
-       if ((targ_lun < CTL_MAX_LUNS)
-        && ((lun = softc->ctl_luns[targ_lun]) != NULL)) {
+       if (targ_lun < CTL_MAX_LUNS)
+               lun = softc->ctl_luns[targ_lun];
+       if (lun) {
                /*
                 * If the LUN is invalid, pretend that it doesn't exist.
                 * It will go away as soon as all pending I/O has been
@@ -11524,29 +11505,22 @@ ctl_scsiio_precheck(struct ctl_softc *so
                if (lun->flags & CTL_LUN_DISABLED) {
                        mtx_unlock(&lun->lun_lock);
                        lun = NULL;
-                       ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr = NULL;
-                       ctsio->io_hdr.ctl_private[CTL_PRIV_BACKEND_LUN].ptr = 
NULL;
-               } else {
-                       ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr = lun;
-                       ctsio->io_hdr.ctl_private[CTL_PRIV_BACKEND_LUN].ptr =
-                               lun->be_lun;
+               }
+       }
+       ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr = lun;
+       if (lun) {
+               ctsio->io_hdr.ctl_private[CTL_PRIV_BACKEND_LUN].ptr =
+                   lun->be_lun;
 
-                       /*
-                        * Every I/O goes into the OOA queue for a
-                        * particular LUN, and stays there until completion.
-                        */
+               /*
+                * Every I/O goes into the OOA queue for a particular LUN,
+                * and stays there until completion.
+                */
 #ifdef CTL_TIME_IO
-                       if (TAILQ_EMPTY(&lun->ooa_queue)) {
-                               lun->idle_time += getsbinuptime() -
-                                   lun->last_busy;
-                       }
+               if (TAILQ_EMPTY(&lun->ooa_queue))
+                       lun->idle_time += getsbinuptime() - lun->last_busy;
 #endif
-                       TAILQ_INSERT_TAIL(&lun->ooa_queue, &ctsio->io_hdr,
-                           ooa_links);
-               }
-       } else {
-               ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr = NULL;
-               ctsio->io_hdr.ctl_private[CTL_PRIV_BACKEND_LUN].ptr = NULL;
+               TAILQ_INSERT_TAIL(&lun->ooa_queue, &ctsio->io_hdr, ooa_links);
        }
 
        /* Get command entry and return error if it is unsuppotyed. */
@@ -11963,7 +11937,7 @@ ctl_lun_reset(struct ctl_softc *softc, u
 
        targ_lun = io->io_hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
+       if (targ_lun >= CTL_MAX_LUNS ||
            (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                io->taskio.task_status = CTL_TASK_LUN_DOES_NOT_EXIST;
@@ -12042,7 +12016,7 @@ ctl_abort_task_set(union ctl_io *io)
         */
        targ_lun = io->io_hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
+       if (targ_lun >= CTL_MAX_LUNS ||
            (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                io->taskio.task_status = CTL_TASK_LUN_DOES_NOT_EXIST;
@@ -12127,7 +12101,7 @@ ctl_abort_task(union ctl_io *io)
         */
        targ_lun = io->io_hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
+       if (targ_lun >= CTL_MAX_LUNS ||
            (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                io->taskio.task_status = CTL_TASK_LUN_DOES_NOT_EXIST;
@@ -12252,7 +12226,7 @@ ctl_query_task(union ctl_io *io, int tas
        softc = control_softc;
        targ_lun = io->io_hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
+       if (targ_lun >= CTL_MAX_LUNS ||
            (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                io->taskio.task_status = CTL_TASK_LUN_DOES_NOT_EXIST;
@@ -12292,7 +12266,7 @@ ctl_query_async_event(union ctl_io *io)
        softc = control_softc;
        targ_lun = io->io_hdr.nexus.targ_mapped_lun;
        mtx_lock(&softc->ctl_lock);
-       if ((targ_lun >= CTL_MAX_LUNS) ||
+       if (targ_lun >= CTL_MAX_LUNS ||
            (lun = softc->ctl_luns[targ_lun]) == NULL) {
                mtx_unlock(&softc->ctl_lock);
                io->taskio.task_status = CTL_TASK_LUN_DOES_NOT_EXIST;
@@ -12375,29 +12349,25 @@ ctl_run_task(union ctl_io *io)
 static void
 ctl_handle_isc(union ctl_io *io)
 {
-       int free_io;
-       struct ctl_lun *lun;
        struct ctl_softc *softc = control_softc;
+       struct ctl_lun *lun;
+       const struct ctl_cmd_entry *entry;
        uint32_t targ_lun;
 
        targ_lun = io->io_hdr.nexus.targ_mapped_lun;
-       lun = softc->ctl_luns[targ_lun];
-
        switch (io->io_hdr.msg_type) {
        case CTL_MSG_SERIALIZE:
-               free_io = ctl_serialize_other_sc_cmd(&io->scsiio);
+               ctl_serialize_other_sc_cmd(&io->scsiio);
                break;
-       case CTL_MSG_R2R: {
-               const struct ctl_cmd_entry *entry;
-
-               /*
-                * This is only used in SER_ONLY mode.
-                */
-               free_io = 0;
+       case CTL_MSG_R2R:               /* Only used in SER_ONLY mode. */
                entry = ctl_get_cmd_entry(&io->scsiio, NULL);
+               if (targ_lun >= CTL_MAX_LUNS ||
+                   (lun = softc->ctl_luns[targ_lun]) == NULL) {
+                       ctl_done(io);
+                       break;
+               }
                mtx_lock(&lun->lun_lock);
-               if (ctl_scsiio_lun_check(lun,
-                   entry, (struct ctl_scsiio *)io) != 0) {
+               if (ctl_scsiio_lun_check(lun, entry, &io->scsiio) != 0) {
                        mtx_unlock(&lun->lun_lock);
                        ctl_done(io);
                        break;
@@ -12406,51 +12376,46 @@ ctl_handle_isc(union ctl_io *io)
                mtx_unlock(&lun->lun_lock);
                ctl_enqueue_rtr(io);
                break;
-       }
        case CTL_MSG_FINISH_IO:
                if (softc->ha_mode == CTL_HA_MODE_XFER) {
-                       free_io = 0;
                        ctl_done(io);
-               } else {
-                       free_io = 1;
-                       mtx_lock(&lun->lun_lock);
-                       TAILQ_REMOVE(&lun->ooa_queue, &io->io_hdr,
-                                    ooa_links);
-                       ctl_check_blocked(lun);
-                       mtx_unlock(&lun->lun_lock);
+                       break;
                }
+               if (targ_lun >= CTL_MAX_LUNS ||
+                   (lun = softc->ctl_luns[targ_lun]) == NULL) {
+                       ctl_free_io(io);
+                       break;
+               }
+               mtx_lock(&lun->lun_lock);
+               TAILQ_REMOVE(&lun->ooa_queue, &io->io_hdr, ooa_links);
+               ctl_check_blocked(lun);
+               mtx_unlock(&lun->lun_lock);
+               ctl_free_io(io);
                break;
        case CTL_MSG_PERS_ACTION:
                ctl_hndl_per_res_out_on_other_sc(
                        (union ctl_ha_msg *)&io->presio.pr_msg);
-               free_io = 1;
+               ctl_free_io(io);
                break;
        case CTL_MSG_BAD_JUJU:
-               free_io = 0;
                ctl_done(io);
                break;
-       case CTL_MSG_DATAMOVE:
-               /* Only used in XFER mode */
-               free_io = 0;
+       case CTL_MSG_DATAMOVE:          /* Only used in XFER mode */
                ctl_datamove_remote(io);
                break;
-       case CTL_MSG_DATAMOVE_DONE:
-               /* Only used in XFER mode */
-               free_io = 0;
+       case CTL_MSG_DATAMOVE_DONE:     /* Only used in XFER mode */
                io->scsiio.be_move_done(io);
                break;
        case CTL_MSG_FAILOVER:
                ctl_failover_lun(io);
-               free_io = 1;
+               ctl_free_io(io);
                break;
        default:
-               free_io = 1;
                printf("%s: Invalid message type %d\n",
                       __func__, io->io_hdr.msg_type);
+               ctl_free_io(io);
                break;
        }
-       if (free_io)
-               ctl_free_io(io);
 
 }
 
@@ -13351,37 +13316,33 @@ ctl_queue_sense(union ctl_io *io)
        struct ctl_softc *softc;
        uint32_t initidx, targ_lun;
 
-       softc = control_softc;
-
        CTL_DEBUG_PRINT(("ctl_queue_sense\n"));
 
+       softc = control_softc;
+       port = ctl_io_port(&ctsio->io_hdr);
+       targ_lun = ctl_lun_map_from_port(port, io->io_hdr.nexus.targ_lun);
+
        /*
         * LUN lookup will likely move to the ctl_work_thread() once we
         * have our new queueing infrastructure (that doesn't put things on
         * a per-LUN queue initially).  That is so that we can handle
         * things like an INQUIRY to a LUN that we don't have enabled.  We
         * can't deal with that right now.
+        * If we don't have a LUN for this, just toss the sense information.
         */
        mtx_lock(&softc->ctl_lock);
-
-       /*
-        * If we don't have a LUN for this, just toss the sense
-        * information.
-        */
-       port = ctl_io_port(&ctsio->io_hdr);
-       targ_lun = ctl_lun_map_from_port(port, io->io_hdr.nexus.targ_lun);
-       if ((targ_lun < CTL_MAX_LUNS)
-        && (softc->ctl_luns[targ_lun] != NULL))
-               lun = softc->ctl_luns[targ_lun];
-       else
+       if (targ_lun >= CTL_MAX_LUNS ||
+           (lun = softc->ctl_luns[targ_lun]) == NULL) {
+               mtx_unlock(&softc->ctl_lock);
                goto bailout;
-
-       initidx = ctl_get_initindex(&io->io_hdr.nexus);
-
+       }
        mtx_lock(&lun->lun_lock);
+       mtx_unlock(&softc->ctl_lock);
+
        /*
         * Already have CA set for this LUN...toss the sense information.
         */
+       initidx = ctl_get_initindex(&io->io_hdr.nexus);
        if (ctl_is_set(lun->have_ca, initidx)) {
                mtx_unlock(&lun->lun_lock);
                goto bailout;
@@ -13394,10 +13355,7 @@ ctl_queue_sense(union ctl_io *io)
        mtx_unlock(&lun->lun_lock);
 
 bailout:
-       mtx_unlock(&softc->ctl_lock);
-
        ctl_free_io(io);
-
        return (CTL_RETVAL_COMPLETE);
 }
 #endif
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to