xen/console: introduce is_console_printable()

Add is_console_printable() to implement a common check for printable characters
in the UART emulation and guest logging code.

Signed-off-by: Denis Mukhin <dmukhin@ford.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
This commit is contained in:
Denis Mukhin authored and Jan Beulich committed 2025-02-25 08:42:37 +01:00
1 parent 01bdc6d2d2
commit 8743258747
4 files changed
+11 -8

No files matched your search

+2 -3
View File
@@ -24,7 +24,7 @@
#include <xen/lib.h>
#include <xen/sched.h>
#include <xen/errno.h>
#include <xen/ctype.h>
#include <xen/console.h>
#include <xen/serial.h>
#include <asm/mmio.h>
#include <xen/perfc.h>
@@ -79,8 +79,7 @@ static void vuart_print_char(struct vcpu *v, char c)
struct domain *d = v->domain;
struct vuart *uart = &d->arch.vuart;
/* Accept only printable characters, newline, and horizontal tab. */
if ( !isprint(c) && (c != '\n') && (c != '\t') )
if ( !is_console_printable(c) )
return ;
spin_lock(&uart->lock);
+2 -3
View File
@@ -7,7 +7,6 @@
* Copyright (c) 2008, Citrix Systems, Inc.
*/
#include <xen/ctype.h>
#include <xen/init.h>
#include <xen/ioreq.h>
#include <xen/lib.h>
@@ -30,6 +29,7 @@
#include <xen/vpci.h>
#include <xen/nospec.h>
#include <xen/vm_event.h>
#include <xen/console.h>
#include <asm/shadow.h>
#include <asm/hap.h>
#include <asm/current.h>
@@ -561,8 +561,7 @@ static int cf_check hvm_print_line(
if ( dir != IOREQ_WRITE )
return X86EMUL_UNHANDLEABLE;
/* Accept only printable characters, newline, and horizontal tab. */
if ( !isprint(c) && (c != '\n') && (c != '\t') )
if ( !is_console_printable(c) )
return X86EMUL_OKAY;
spin_lock(&cd->pbuf_lock);
+1 -2
View File
@@ -24,7 +24,6 @@
#include <xen/shutdown.h>
#include <xen/video.h>
#include <xen/kexec.h>
#include <xen/ctype.h>
#include <xen/warning.h>
#include <asm/div64.h>
#include <xen/hypercall.h> /* for do_console_io */
@@ -674,7 +673,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,
c = *kin++;
if ( c == '\n' )
break;
if ( isprint(c) || c == '\t' )
if ( is_console_printable(c) )
*kout++ = c;
} while ( --kcount > 0 );
+6
View File
@@ -8,6 +8,7 @@
#define __CONSOLE_H__
#include <xen/inttypes.h>
#include <xen/ctype.h>
#include <public/xen.h>
struct xen_sysctl_readconsole;
@@ -50,4 +51,9 @@ void console_serial_puts(const char *s, size_t nr);
extern int8_t opt_console_xen;
static inline bool is_console_printable(unsigned char c)
{
return isprint(c) || c == '\n' || c == '\t';
}
#endif /* __CONSOLE_H__ */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.