All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: sbi: fix errno mapping for SBI_ERR_ALREADY_* error codes
@ 2026-07-27 22:15 ` Paul Sherman
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Sherman @ 2026-07-27 22:15 UTC (permalink / raw)
  To: palmer, pjw, aou
  Cc: alex, hchauhan, apatel, linux-riscv, linux-kernel, Paul Sherman

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 <hchauhan@ventanamicro.com>
Cc: Anup Patel <apatel@ventanamicro.com>
Signed-off-by: Paul Sherman <shermanpauldylan@gmail.com>
---
 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
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-30  0:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-27 22:15 [PATCH] riscv: sbi: fix errno mapping for SBI_ERR_ALREADY_* error codes Paul Sherman
2026-07-27 22:15 ` Paul Sherman
2026-07-29 18:43 ` Paul Walmsley
2026-07-29 18:43   ` Paul Walmsley
2026-07-30  0:01   ` Paul Sherman
2026-07-30  0:01     ` Paul Sherman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.