svn commit: r330910 - stable/11/sys/dev/syscons

Eitan Adler eadler at FreeBSD.org
Wed Mar 14 07:08:47 UTC 2018


Author: eadler
Date: Wed Mar 14 07:08:46 2018
New Revision: 330910
URL: https://svnweb.freebsd.org/changeset/base/330910

Log:
  MFC r305059:
  
  Start adding locking to sc_cngetc().
  
  Restore an splx() lost in r228644.  We aren't nearly ready to remove
  spl's.  They give hints about missing locking.  This lost one was
  misplaced.  Dropping it early for convenience gave race windows for
  accesses to the fkey buffer.  Giant locking accidentally fixed this
  for non-console cases.
  
  Put the spl's around the whole function.  Since there are many returns
  that would need splx() just before them for a direct fix, split the
  function into a wrapper that does the spl's and a "locked" function
  that does the work.
  
  Return earlier when no keyboard is attached to match the ordering in a
  planned version.  This breaks the dubious feature of returning keys
  from the fkey buffer after the keyboard has gone away.  Losing the keys
  wouldn't matter, but we keep them too long now.

Modified:
  stable/11/sys/dev/syscons/syscons.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/syscons/syscons.c
==============================================================================
--- stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 07:08:02 2018	(r330909)
+++ stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 07:08:46 2018	(r330910)
@@ -1650,6 +1650,7 @@ sc_cnterm(struct consdev *cp)
 }
 
 static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp);
+static int sc_cngetc_locked(struct sc_cnstate *sp);
 static void sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags);
 static void sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp);
 static void sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp);
@@ -1826,15 +1827,28 @@ sc_cnputc(struct consdev *cd, int c)
 static int
 sc_cngetc(struct consdev *cd)
 {
+    int c, s;
+
+    /* assert(sc_console != NULL) */
+    s = spltty();	/* block sckbdevent and scrn_timer while we poll */
+    if (sc_console->sc->kbd == NULL) {
+	splx(s);
+	return -1;
+    }
+    c = sc_cngetc_locked(NULL);
+    splx(s);
+    return c;
+}
+
+static int
+sc_cngetc_locked(struct sc_cnstate *sp)
+{
     static struct fkeytab fkey;
     static int fkeycp;
     scr_stat *scp;
     const u_char *p;
-    int s = spltty();	/* block sckbdevent and scrn_timer while we poll */
     int c;
 
-    /* assert(sc_console != NULL) */
-
     /* 
      * Stop the screen saver and update the screen if necessary.
      * What if we have been running in the screen saver code... XXX
@@ -1843,15 +1857,8 @@ sc_cngetc(struct consdev *cd)
     scp = sc_console->sc->cur_scp;	/* XXX */
     sccnupdate(scp);
 
-    if (fkeycp < fkey.len) {
-	splx(s);
+    if (fkeycp < fkey.len)
 	return fkey.str[fkeycp++];
-    }
-
-    if (scp->sc->kbd == NULL) {
-	splx(s);
-	return -1;
-    }
 
     c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK, NULL);
 


More information about the svn-src-all mailing list