efi/earlycon: Replace open coded strnchrnul()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 8 Dec 2022 22:12:16 +0000 (00:12 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 10 Jan 2023 14:16:12 +0000 (15:16 +0100)
strnchrnul() can be called in the early stages. Replace
open coded variant in the EFI early console driver.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/earlycon.c

index 4d6c532..be7c83b 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/serial_core.h>
 #include <linux/screen_info.h>
+#include <linux/string.h>
 
 #include <asm/early_ioremap.h>
 
@@ -143,16 +144,10 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
        len = si->lfb_linelength;
 
        while (num) {
-               unsigned int linemax;
-               unsigned int h, count = 0;
+               unsigned int linemax = (si->lfb_width - efi_x) / font->width;
+               unsigned int h, count;
 
-               for (s = str; *s && *s != '\n'; s++) {
-                       if (count == num)
-                               break;
-                       count++;
-               }
-
-               linemax = (si->lfb_width - efi_x) / font->width;
+               count = strnchrnul(str, num, '\n') - str;
                if (count > linemax)
                        count = linemax;