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

Björn Töpel bjorn at kernel.org
Wed Jan 18 03:08:56 PST 2023


Geert Uytterhoeven <geert at linux-m68k.org> 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



More information about the linux-riscv mailing list