Re: [PATCH v2 1/2] riscv: Add instruction dump to RISC-V splats

From: Björn Töpel
Date: Wed Jan 18 2023 - 06:49:16 EST


Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> writes:

>> +static void dump_kernel_instr(const char *loglvl, struct pt_regs *regs)
>> +{
>> + char str[sizeof("0000 ") * 12 + 2 + 1], *p = str;
>> + unsigned long addr = regs->epc;
>
> Given you never use this as an unsigned long, what about
>
> const u16 *insns = (u16 *)instruction_pointer(regs);
>
> so you no longer need casts below?

Indeed! Good suggestion, thank you! I'll do this change in v3.

>> + long bad;
>> + u16 val;
>> + int i;
>> +
>> + for (i = -10; i < 2; i++) {
>> + bad = get_kernel_nofault(val, &((u16 *)addr)[i]);
>> + if (!bad) {
>> + p += sprintf(p, i == 0 ? "(%04hx) " : "%04hx ", val);
>> + } else {
>> + printk("%sCode: Unable to access instruction at 0x%lx.\n",
>
> %px, so you can drop the cast to long below.

Much cleaner. Thanks!


Björn