Author: zbb
Date: Tue Jun 13 18:35:14 2017
New Revision: 319906
URL: https://svnweb.freebsd.org/changeset/base/319906

Log:
  Prevent multiple lock initialization in e6000sw probe
  
  r319886 ("Add the initial support for the Marvell 88E6141
  and 88E6341 switches.") unveiled a problem with possible
  multiple lock creation. Move its initialization
  to the driver attach and for obtaining the switch ID
  create a temprorary one, which is immediately destroyed
  after the check.
  
  Submitted by: Zbigniew Bodek <z...@semihalf.com>
              Marcin Wojtas <m...@semihalf.com>
  Obtained from: Semihalf

Modified:
  head/sys/dev/etherswitch/e6000sw/e6000sw.c

Modified: head/sys/dev/etherswitch/e6000sw/e6000sw.c
==============================================================================
--- head/sys/dev/etherswitch/e6000sw/e6000sw.c  Tue Jun 13 17:49:49 2017        
(r319905)
+++ head/sys/dev/etherswitch/e6000sw/e6000sw.c  Tue Jun 13 18:35:14 2017        
(r319906)
@@ -217,11 +217,15 @@ e6000sw_probe(device_t dev)
        if (sc->sw_addr != 0 && (sc->sw_addr % 2) == 0)
                sc->multi_chip = true;
 
-       /* Lock is necessary due to assertions. */
-       sx_init(&sc->sx, "e6000sw");
+       /*
+        * Create temporary lock, just to satisfy assertions,
+        * when obtaining the switch ID. Destroy immediately afterwards.
+        */
+       sx_init(&sc->sx, "e6000sw_tmp");
        E6000SW_LOCK(sc);
        id = e6000sw_readreg(sc, REG_PORT(0), SWITCH_ID);
        E6000SW_UNLOCK(sc);
+       sx_destroy(&sc->sx);
 
        switch (id & 0xfff0) {
        case 0x3400:
@@ -247,7 +251,6 @@ e6000sw_probe(device_t dev)
                sc->num_ports = 7;
                break;
        default:
-               sx_destroy(&sc->sx);
                device_printf(dev, "Unrecognized device, id 0x%x.\n", id);
                return (ENXIO);
        }
@@ -354,6 +357,8 @@ e6000sw_attach(device_t dev)
                device_printf(dev, "multi-chip addressing mode\n");
        else
                device_printf(dev, "single-chip addressing mode\n");
+
+       sx_init(&sc->sx, "e6000sw");
 
        E6000SW_LOCK(sc);
        e6000sw_setup(dev, sc);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to