Skip to contentSkip to conversation

lib: sbi: sbi_ecall: Check the range of SBI error

PATCH Superseded Yu Chien Peter Lin 3 participants 4 messages Feb 22, 2023 – Feb 27, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib: sbi: sbi_ecall: Check the range of SBI error

We should also check if the return error code is greater than 0 (SBI_SUCCESS), as this is an invalid error.

---
Changes v1 -> v2:
- Include Xiang's Reviewed-by
- Drop the 'ret -> out_err' rename

---
 lib/sbi/sbi_ecall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_ecall.c +1 -1
index 27ce5d49..d0f01665 100644
@@ -120,7 +120,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
 		trap.epc = regs->mepc;
 		sbi_trap_redirect(regs, &trap);
 	} else {
-		if (ret < SBI_LAST_ERR) {
+		if (ret < SBI_LAST_ERR || SBI_SUCCESS < ret) {
 			sbi_printf("%s: Invalid error %d for ext=0x%lx "
 				   "func=0x%lx\n", __func__, ret,
 				   extension_id, func_id);
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 lib: sbi: sbi_ecall: Check the range of SBI error

Quoted 9 lines · Yu Chien Peter Lin

We should also check if the return error code is greater than 0 (SBI_SUCCESS), as this is an invalid error.

---
Changes v1 -> v2:
- Include Xiang's Reviewed-by
- Drop the 'ret -> out_err' rename

The SBI_ENOTSUPP -> SBI_ERR_NOT_SUPPORTED rename was also dropped, but as Anup suggests, we should probably do a full rework of that in another series later.

Thanks,
drew

Quoted 20 lines
---
 lib/sbi/sbi_ecall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_ecall.c +1 -1
index 27ce5d49..d0f01665 100644
@@ -120,7 +120,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
 		trap.epc = regs->mepc;
 		sbi_trap_redirect(regs, &trap);
 	} else {
-		if (ret < SBI_LAST_ERR) {
+		if (ret < SBI_LAST_ERR || SBI_SUCCESS < ret) {
 			sbi_printf("%s: Invalid error %d for ext=0x%lx "
 				   "func=0x%lx\n", __func__, ret,
 				   extension_id, func_id);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 1/1 lib: sbi: sbi_ecall: Check the range of SBI error

Hi Andrew,

Quoted 11 lines · Andrew Jones
Quoted 9 lines · Yu Chien Peter Lin

We should also check if the return error code is greater than 0 (SBI_SUCCESS), as this is an invalid error.

---
Changes v1 -> v2:
- Include Xiang's Reviewed-by
- Drop the 'ret -> out_err' rename

Quoted 8 lines

The SBI_ENOTSUPP -> SBI_ERR_NOT_SUPPORTED rename was also dropped, but as Anup suggests, we should probably do a full rework of that in another series later.

Thanks,
drew

Agreed, thanks for the review.

Best regards,
Peter Lin

Quoted 21 lines
Quoted 21 lines
---
 lib/sbi/sbi_ecall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_ecall.c +1 -1
index 27ce5d49..d0f01665 100644
@@ -120,7 +120,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
 		trap.epc = regs->mepc;
 		sbi_trap_redirect(regs, &trap);
 	} else {
-		if (ret < SBI_LAST_ERR) {
+		if (ret < SBI_LAST_ERR || SBI_SUCCESS < ret) {
 			sbi_printf("%s: Invalid error %d for ext=0x%lx "
 				   "func=0x%lx\n", __func__, ret,
 				   extension_id, func_id);
Signature · 1 line
2.34.1
Applied
#3 lore raw

PATCH v2 1/1 lib: sbi: sbi_ecall: Check the range of SBI error

In reply to Yu Chien Peter Lin
Quoted 6 lines · Yu Chien Peter Lin

We should also check if the return error code is greater than 0 (SBI_SUCCESS), as this is an invalid error.

Looks good to me.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 29 lines

---
Changes v1 -> v2:
- Include Xiang's Reviewed-by
- Drop the 'ret -> out_err' rename

---
 lib/sbi/sbi_ecall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_ecall.c +1 -2
index 27ce5d49..d0f01665 100644
@@ -120,7 +120,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
                trap.epc = regs->mepc;
                sbi_trap_redirect(regs, &trap);
        } else {
-               if (ret < SBI_LAST_ERR) {
+               if (ret < SBI_LAST_ERR || SBI_SUCCESS < ret) {
                        sbi_printf("%s: Invalid error %d for ext=0x%lx "
                                   "func=0x%lx\n", __func__, ret,
                                   extension_id, func_id);
--

2.34.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi