[PATCH] tty: xtensa/iss: use strnlen to improve iss_console_write

Thorsten Blum posted 1 patch 1 month, 2 weeks ago
arch/xtensa/platforms/iss/console.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] tty: xtensa/iss: use strnlen to improve iss_console_write
Posted by Thorsten Blum 1 month, 2 weeks ago
Use strnlen() to limit scanning 's' to 'count' bytes. Use the length of
's' to decide if simc_write() should be called instead of dereferencing
it first and then calling strlen().

With strnlen(), iss_console_write() is further hardened against callers
where 's' is not NUL-terminated.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/xtensa/platforms/iss/console.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index 8b95221375a8..8e54625cb2ba 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -166,8 +166,9 @@ late_initcall(rs_init);
 
 static void iss_console_write(struct console *co, const char *s, unsigned count)
 {
-	if (s && *s != 0)
-		simc_write(1, s, min(count, strlen(s)));
+	count = s ? strnlen(s, count) : 0;
+	if (count)
+		simc_write(1, s, count);
 }
 
 static struct tty_driver* iss_console_device(struct console *c, int *index)
Re: [PATCH] tty: xtensa/iss: use strnlen to improve iss_console_write
Posted by Max Filippov 1 month, 2 weeks ago
On Thu, Apr 30, 2026 at 2:04 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> Use strnlen() to limit scanning 's' to 'count' bytes. Use the length of
> 's' to decide if simc_write() should be called instead of dereferencing
> it first and then calling strlen().
>
> With strnlen(), iss_console_write() is further hardened against callers
> where 's' is not NUL-terminated.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/xtensa/platforms/iss/console.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Thanks. Applied to my xtensa tree.

-- Max