[PATCH 1/2] lib: sbi: Make console_puts/console_putc interchangeable

Guo Ren guoren at kernel.org
Tue Oct 24 23:53:48 PDT 2023


On Wed, Oct 25, 2023 at 12:32 PM Xiang W <wxjstz at 126.com> wrote:
>
> console_puts/console_putc should replace each other, but the previous
> sbi_putc can only use console_putc. This patch improves this problem.
>
> Signed-off-by: Xiang W <wxjstz at 126.com>
> ---
>  lib/sbi/sbi_console.c | 35 +++++++++++++++++------------------
>  1 file changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c
> index 2b3b0a3..ab09a5c 100644
> --- a/lib/sbi/sbi_console.c
> +++ b/lib/sbi/sbi_console.c
> @@ -37,28 +37,22 @@ int sbi_getc(void)
>         return -1;
>  }
>
> -void sbi_putc(char ch)
> -{
> -       if (console_dev && console_dev->console_putc) {
> -               if (ch == '\n')
> -                       console_dev->console_putc('\r');
> -               console_dev->console_putc(ch);
> -       }
> -}
> -
>  static unsigned long nputs(const char *str, unsigned long len)
>  {
> -       unsigned long i, ret;
> +       unsigned long i;
>
> -       if (console_dev && console_dev->console_puts) {
> -               ret = console_dev->console_puts(str, len);
> -       } else {
> -               for (i = 0; i < len; i++)
> -                       sbi_putc(str[i]);
> -               ret = len;
> +       if (console_dev) {
> +               if (console_dev->console_puts)
> +                       return console_dev->console_puts(str, len);
> +               else if (console_dev->console_putc) {
> +                       for (i = 0; i < len; i++) {
> +                               if (str[i] == '\n')
> +                                       console_dev->console_putc('\r');
> +                               console_dev->console_putc(str[i]);
> +                       }
> +               }
>         }
> -
> -       return ret;
> +       return len;
The return becomes meaningless, right?

>  }
>
>  static void nputs_all(const char *str, unsigned long len)
> @@ -69,6 +63,11 @@ static void nputs_all(const char *str, unsigned long len)
>                 p += nputs(&str[p], len - p);
>  }
>
> +void sbi_putc(char ch)
> +{
> +       nputs_all(&ch, 1);
> +}
> +
>  void sbi_puts(const char *str)
>  {
>         unsigned long len = sbi_strlen(str);
> --
> 2.42.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



-- 
Best Regards
 Guo Ren



More information about the opensbi mailing list