Author: mav
Date: Wed Mar 15 11:16:26 2017
New Revision: 315303
URL: https://svnweb.freebsd.org/changeset/base/315303

Log:
  Fix panic when SIM dereferenced before allocation.
  
  MFC after:    2 weeks

Modified:
  head/sys/dev/isp/isp_freebsd.c

Modified: head/sys/dev/isp/isp_freebsd.c
==============================================================================
--- head/sys/dev/isp/isp_freebsd.c      Wed Mar 15 10:53:40 2017        
(r315302)
+++ head/sys/dev/isp/isp_freebsd.c      Wed Mar 15 11:16:26 2017        
(r315303)
@@ -362,39 +362,40 @@ isp_detach(ispsoftc_t *isp)
 static void
 isp_freeze_loopdown(ispsoftc_t *isp, int chan)
 {
-       if (IS_FC(isp)) {
-               struct isp_fc *fc = ISP_FC_PC(isp, chan);
-               if (fc->simqfrozen == 0) {
-                       isp_prt(isp, ISP_LOGDEBUG0,
-                           "Chan %d Freeze simq (loopdown)", chan);
-                       fc->simqfrozen = SIMQFRZ_LOOPDOWN;
-                       xpt_hold_boot();
-                       xpt_freeze_simq(fc->sim, 1);
-               } else {
-                       isp_prt(isp, ISP_LOGDEBUG0,
-                           "Chan %d Mark simq frozen (loopdown)", chan);
-                       fc->simqfrozen |= SIMQFRZ_LOOPDOWN;
-               }
+       struct isp_fc *fc = ISP_FC_PC(isp, chan);
+
+       if (fc->sim == NULL)
+               return;
+       if (fc->simqfrozen == 0) {
+               isp_prt(isp, ISP_LOGDEBUG0,
+                   "Chan %d Freeze simq (loopdown)", chan);
+               fc->simqfrozen = SIMQFRZ_LOOPDOWN;
+               xpt_hold_boot();
+               xpt_freeze_simq(fc->sim, 1);
+       } else {
+               isp_prt(isp, ISP_LOGDEBUG0,
+                   "Chan %d Mark simq frozen (loopdown)", chan);
+               fc->simqfrozen |= SIMQFRZ_LOOPDOWN;
        }
 }
 
 static void
 isp_unfreeze_loopdown(ispsoftc_t *isp, int chan)
 {
-       if (IS_FC(isp)) {
-               struct isp_fc *fc = ISP_FC_PC(isp, chan);
-               int wasfrozen = fc->simqfrozen & SIMQFRZ_LOOPDOWN;
-               fc->simqfrozen &= ~SIMQFRZ_LOOPDOWN;
-               if (wasfrozen && fc->simqfrozen == 0) {
-                       isp_prt(isp, ISP_LOGDEBUG0,
-                           "Chan %d Release simq", chan);
-                       xpt_release_simq(fc->sim, 1);
-                       xpt_release_boot();
-               }
+       struct isp_fc *fc = ISP_FC_PC(isp, chan);
+
+       if (fc->sim == NULL)
+               return;
+       int wasfrozen = fc->simqfrozen & SIMQFRZ_LOOPDOWN;
+       fc->simqfrozen &= ~SIMQFRZ_LOOPDOWN;
+       if (wasfrozen && fc->simqfrozen == 0) {
+               isp_prt(isp, ISP_LOGDEBUG0,
+                   "Chan %d Release simq", chan);
+               xpt_release_simq(fc->sim, 1);
+               xpt_release_boot();
        }
 }
 
-
 static int
 ispioctl(struct cdev *dev, u_long c, caddr_t addr, int flags, struct thread 
*td)
 {
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to