Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Aug 2016 10:57:20 +0000 (UTC)
From:      Bruce Evans <bde@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r305059 - head/sys/dev/syscons
Message-ID:  <201608301057.u7UAvKGK025465@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bde
Date: Tue Aug 30 10:57:19 2016
New Revision: 305059
URL: https://svnweb.freebsd.org/changeset/base/305059

Log:
  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:
  head/sys/dev/syscons/syscons.c

Modified: head/sys/dev/syscons/syscons.c
==============================================================================
--- head/sys/dev/syscons/syscons.c	Tue Aug 30 10:21:32 2016	(r305058)
+++ head/sys/dev/syscons/syscons.c	Tue Aug 30 10:57:19 2016	(r305059)
@@ -1648,6 +1648,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);
@@ -1824,15 +1825,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
@@ -1841,15 +1855,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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608301057.u7UAvKGK025465>