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

From: Celeste Liu
Date: Thu Jul 20 2023 - 15:24:36 EST


On July 20, 2023 5:08:37 PM GMT+08:00, "Björn Töpel" <bjorn@xxxxxxxxxx> wrote:
>Celeste Liu <coelacanthushex@xxxxxxxxx> writes:
>
>> On July 20, 2023 12:28:47 AM GMT+08:00, "Björn Töpel" <bjorn@xxxxxxxxxx> wrote:
>>>Andreas Schwab <schwab@xxxxxxx> writes:
>>>
>>>> On Jul 19 2023, Celeste Liu wrote:
>>>>
>>>>> @@ -308,7 +312,7 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs)
>>>>>
>>>>> if (syscall < NR_syscalls)
>>>>> syscall_handler(regs, syscall);
>>>>> - else
>>>>> + else if ((long)syscall != -1L)
>>>>
>>>> You can also use syscall != -1UL or even syscall != -1.
>>>
>>>The former is indeed better for the eyes! :-) The latter will get a
>>>-Wsign-compare warning, no?
>>>
>>>
>>>Björn
>>
>> Well, that's true. And I just found out that by C standards, converting
>> ulong to long is implementation-defined behavior, unlike long to ulong
>> which is well-defined. So it is really better than (long)syscall != -1L.
>
>If you're respinning, I suggest you use David's suggestion:
> * Remove the comment I suggest you to add
> * Use (signed) long
> * Add syscall >= 0 &&
> * else if (syscall != -1)
>
>Which is the least amount of surprises IMO.

v4 has sent