[PATCH] riscv: sbi: fix errno mapping for SBI_ERR_ALREADY_* error codes
Paul Sherman <[email protected]>
| Newsgroups | org.infradead.lists.linux-riscv,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
SBI error codes SBI_ERR_ALREADY_AVAILABLE (-6), SBI_ERR_ALREADY_STARTED (-7), and SBI_ERR_ALREADY_STOPPED (-8) have no explicit case in sbi_err_map_linux_errno() and fall through to the default branch, returning -ENOTSUPP (-524). Map these three codes to -EALREADY, which correctly reflects their semantics: the requested operation was not performed because the target is already in the desired state. Also add a documentation comment enumerating all SBI error codes and their Linux errno mappings, making the translation table self-documenting and making any future omissions immediately visible. Tested-on: Milk-V Pioneer (SG2042, 64-hart RISC-V, OpenSBI v1.5) Cc: Himanshu Chauhan <[email protected]> Cc: Anup Patel <[email protected]> Signed-off-by: Paul Sherman <[email protected]> --- arch/riscv/include/asm/sbi.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 5725e0ca4dda3..b067eb08bcc34 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -651,6 +651,26 @@ static inline unsigned long sbi_mk_version(unsigned long major, | (minor & SBI_SPEC_VERSION_MINOR_MASK); } +/* + * SBI error code to Linux errno mapping. + * + * SBI error codes (from the SBI specification): + * 0 SUCCESS + * -1 FAILURE : -ENOTSUPP + * -2 NOT_SUPPORTED : -ENOTSUPP + * -3 INVALID_PARAM : -EINVAL + * -4 DENIED : -EPERM + * -5 INVALID_ADDRESS : -EFAULT + * -6 ALREADY_AVAILABLE : -EALREADY + * -7 ALREADY_STARTED : -EALREADY + * -8 ALREADY_STOPPED : -EALREADY + * -9 NO_SHMEM : -ENOMEM + * -10 INVALID_STATE : -EINVAL + * -11 BAD_RANGE : -ERANGE + * -12 TIMEOUT : -ETIMEDOUT + * -13 IO : -EIO + * -14 DENIED_LOCKED : -EPERM + */ static inline int sbi_err_map_linux_errno(int err) { switch (err) { @@ -672,6 +692,10 @@ static inline int sbi_err_map_linux_errno(int err) return -ETIMEDOUT; case SBI_ERR_IO: return -EIO; + case SBI_ERR_ALREADY_AVAILABLE: + case SBI_ERR_ALREADY_STARTED: + case SBI_ERR_ALREADY_STOPPED: + return -EALREADY; case SBI_ERR_NOT_SUPPORTED: case SBI_ERR_FAILURE: default: -- 2.53.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv