[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 05/14] xen/riscv: add early_printk_hnum() function


  • To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 23 Jan 2023 12:10:05 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TI0/4CHvullVluTKKM10tQVQxLa2eSvSGGZSIoHfyV0=; b=ATgzWRUJgsYF9fWtfz/zkRsLHBvs1jUbfrmB+4fmTwTFiu7ZIB5BZKMXWd9utVaR/O96JQCbyFkIoEXx7WK60u2yMc2x6HWPvRea36e3F9v8J2oxf0RSH0PH6Ag/e1LUswhs9W05em7akOpiyPVNCNiLnDnphMbcKENvFv+uJnNa2RcyWdL/kvAwwZBORQALAEMmF7jUIZnB+kJkVn95IWVMfjCGlMMctQ//k30HjLy2u4IESUmi2Jldc/4fZ9DPCHg2aLs5alIpSD62/ZC3mjy90URePasmziYQgCQ1POUg/YYMQTke+0D/BmnStAaUFLs5og6c+wSnjHKZo66lvA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l9hz/iO31AnNCDzJ52ohe2jheCWNwrLUB8+OWAsPqQbElbo8GA5JiEmD5CKtKZxcdrDoGxcjGblA9CIzwspst5Ykip31kbuB0NStwCwq4raXUGAIMu68Zsz/LzRSJtwUYC0zJWLBHzZMpF+HShE2tAbMoE/I0NXT4zy4MAT48OB47ceQNVMA5cWbS4ib83/izFAnxWK0GjKKE8u5odEBunazi2ZAU6BsG9UD8Sosd2b68FMQ3vmioqtBJLzICzYPH5NJWUxbpdE9ATvZjjI97tfpEatmqWEaaUL8Q5J3Awh2nQixp2MOiE2oo9rQWHWsF/UFsgyb3YdueCnANztOLw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Gianluca Guida <gianluca@xxxxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 23 Jan 2023 11:10:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 20.01.2023 15:59, Oleksii Kurochko wrote:
> Add ability to print hex number.
> It might be useful to print register value as debug information
> in BUG(), WARN(), etc...
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>

Orthogonal to Andrew's reply (following which I think would be best)
a couple of comments which may be applicable elsewhere as well:

> --- a/xen/arch/riscv/early_printk.c
> +++ b/xen/arch/riscv/early_printk.c
> @@ -43,3 +43,42 @@ void early_printk(const char *str)
>          str++;
>      }
>  }
> +
> +static void reverse(char *s, int length)

Please can you get things const-correct (const char *s) and signedness-
correct (unsigned int length) from the beginning. We're converting other
code as we touch it, but this is extremely slow going and hence would
better be avoided in the first place in new code.

> +{
> +    int c;
> +    char *begin, *end, temp;
> +
> +    begin  = s;
> +    end    = s + length - 1;
> +
> +    for ( c = 0; c < length/2; c++ )

Style: Blanks around binary operators.

> +    {
> +        temp   = *end;
> +        *end   = *begin;
> +        *begin = temp;
> +
> +        begin++;
> +        end--;
> +    }
> +}
> +
> +void early_printk_hnum(const register_t reg_val)

Likely this function wants to be __init? (All functions that can be
should also be made so.) With that, reverse() then would also want
to become __init.

As to the const here vs the remark further up: In cases like this one
we typically don't use const. You're free to keep it of course, but
I think it should at least be purged from the declaration (and maybe
also the stub).

> +{
> +    char hex[] = "0123456789ABCDEF";

static const char __initconst?

> +    char buf[17] = {0};
> +
> +    register_t num = reg_val;
> +    unsigned int count = 0;
> +
> +    for ( count = 0; num != 0; count++, num >>= 4 )
> +        buf[count] = hex[num & 0x0000000f];

Just 0xf?

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.