[PATCH v3] riscv: entry: set a0 = -ENOSYS only when syscall != -1

David Laight David.Laight at ACULAB.COM
Wed Jul 19 06:13:33 PDT 2023


...
> > +               /*
> > +                * Convert negative numbers to very high and thus out of range
> > +                * numbers for comparisons.
> > +                */
> >                 ulong syscall = regs->a7;
> >
> >                 regs->epc += 4;
> > @@ -308,7 +312,7 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs)
> >
> >                 if (syscall < NR_syscalls)

If you leave 'syscall' signed and write:
	if (syscall >= 0 && syscall < NR_syscalls)
the compiler will use a single unsigned compare.
There is no need to 'optimise' it yourself.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


More information about the linux-riscv mailing list