Author: tsoome
Date: Wed Mar 18 22:21:42 2020
New Revision: 359099
URL: https://svnweb.freebsd.org/changeset/base/359099

Log:
  loader.efi: handle efi_cons_init() failure cases better
  
  if we fail to allocate buffer, set up the TERM_EMU and continue.
  On output, use TERM_EMU in case we did fail to allocate buffer.

Modified:
  head/stand/efi/libefi/efi_console.c

Modified: head/stand/efi/libefi/efi_console.c
==============================================================================
--- head/stand/efi/libefi/efi_console.c Wed Mar 18 22:17:01 2020        
(r359098)
+++ head/stand/efi/libefi/efi_console.c Wed Mar 18 22:21:42 2020        
(r359099)
@@ -855,27 +855,28 @@ efi_cons_update_mode(void)
                tp.tp_row = rows;
                tp.tp_col = cols;
                buffer = malloc(rows * cols * sizeof(*buffer));
-               if (buffer == NULL)
-                       return (false);
+               if (buffer != NULL) {
+                       teken_set_winsize(&teken, &tp);
+                       a = teken_get_defattr(&teken);
 
-               teken_set_winsize(&teken, &tp);
-               a = teken_get_defattr(&teken);
+                       snprintf(env, sizeof(env), "%d", a->ta_fgcolor);
+                       env_setenv("teken.fg_color", EV_VOLATILE, env,
+                           efi_set_colors, env_nounset);
+                       snprintf(env, sizeof(env), "%d", a->ta_bgcolor);
+                       env_setenv("teken.bg_color", EV_VOLATILE, env,
+                           efi_set_colors, env_nounset);
 
-               snprintf(env, sizeof(env), "%d", a->ta_fgcolor);
-               env_setenv("teken.fg_color", EV_VOLATILE, env, efi_set_colors,
-                   env_nounset);
-               snprintf(env, sizeof(env), "%d", a->ta_bgcolor);
-               env_setenv("teken.bg_color", EV_VOLATILE, env, efi_set_colors,
-                   env_nounset);
-
-               for (int row = 0; row < rows; row++) {
-                       for (int col = 0; col < cols; col++) {
-                               buffer[col + row * tp.tp_col].c = ' ';
-                               buffer[col + row * tp.tp_col].a = *a;
+                       for (int row = 0; row < rows; row++) {
+                               for (int col = 0; col < cols; col++) {
+                                       buffer[col + row * tp.tp_col].c = ' ';
+                                       buffer[col + row * tp.tp_col].a = *a;
+                               }
                        }
                }
-       } else {
+       }
+
 #ifdef TERM_EMU
+       if (buffer == NULL) {
                conout->SetAttribute(conout, EFI_TEXT_ATTR(DEFAULT_FGCOLOR,
                    DEFAULT_BGCOLOR));
                end_term();
@@ -883,8 +884,8 @@ efi_cons_update_mode(void)
                curs_move(&curx, &cury, curx, cury);
                fg_c = DEFAULT_FGCOLOR;
                bg_c = DEFAULT_BGCOLOR;
-#endif
        }
+#endif
 
        snprintf(env, sizeof (env), "%u", (unsigned)rows);
        setenv("LINES", env, 1);
@@ -1011,15 +1012,12 @@ efi_cons_putchar(int c)
         * Don't use Teken when we're doing pure serial, or a multiple console
         * with video "primary" because that's also serial.
         */
-       if ((mode & (RB_SERIAL | RB_MULTIPLE)) != 0) {
+       if ((mode & (RB_SERIAL | RB_MULTIPLE)) != 0 || buffer == NULL) {
                input_byte(ch);
                return;
        }
 
-       if (buffer != NULL)
-               teken_input(&teken, &ch, sizeof (ch));
-       else
-               efi_cons_efiputchar(c);
+       teken_input(&teken, &ch, sizeof (ch));
 }
 
 static int
_______________________________________________
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