lib: utils/serial: Simplify semihosting_getc() function
PATCH 1/1 lib: utils/serial: Simplify semihosting_getc() function
Simply pass the character returned by semihosting_trap(SYSREADC, NULL) on success, or -1 on failure. This also fixes issue [1] of comparison of constant -1 with char type.
[1] https://github.com/riscv-software-src/opensbi/issues/269
--- lib/utils/serial/semihosting.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
lib/utils/serial/semihosting.c +4 -8
@@ -151,15 +151,11 @@ static void semihosting_putc(char ch)static int semihosting_getc (void ) {char ch =0 ; -int ret; -if (semihosting_infd <0 ) { - ch =semihosting_trap (SYSREADC ,NULL ); - ret = ch >-1 ? ch :-1 ; - }else - ret =semihosting_read (semihosting_infd, &ch,1 ) >0 ? ch :-1 ; - -return ret; +if (semihosting_infd <0 ) +return semihosting_trap (SYSREADC ,NULL ); +else +return semihosting_read (semihosting_infd, &ch,1 ) >0 ? ch :-1 ; }static struct sbi_console_device semihosting_console = {
Signature · 1 line
2.34.1
PATCH 1/1 lib: utils/serial: Simplify semihosting_getc() function
Quoted 17 lines · Yu Chien Peter Lin
Simply pass the character returned by
semihosting_trap(SYSREADC, NULL)on success, or -1 on failure. This also fixes issue [1] of comparison of constant -1 with char type.[1] https://github.com/riscv-software-src/opensbi/issues/269
Signed-off-by Yu Chien Peter Lin <[email protected]>--- lib/utils/serial/semihosting.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)lib/utils/serial/semihosting.c +0
-0
lib/utils/serial/semihosting.c static void semihosting_putc(char ch) · line 158
Quoted 8 lines
lib/utils/serial/semihosting.c +0
-4@@ -151,15 +151,11 @@ static void semihosting_putc(char ch)static int semihosting_getc (void ) {char ch =0 ; -int ret; -if (semihosting_infd <0 ) { - ch =semihosting_trap (SYSREADC ,NULL ); - ret = ch >-1 ? ch :-1 ;
We have to return -1 upon any failure or no character. This is as-per expectation of SBI v0.1 console_getchar()
Regards,
Anup
Quoted 19 lines
lib/utils/serial/semihosting.c +4
-5- } else - ret =semihosting_read (semihosting_infd, &ch,1 ) >0 ? ch :-1 ; - -return ret; +if (semihosting_infd <0 ) +return semihosting_trap (SYSREADC ,NULL ); +else +return semihosting_read (semihosting_infd, &ch,1 ) >0 ? ch :-1 ; }static struct sbi_console_device semihosting_console = { --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi