Skip to contentSkip to conversation

lib: sbi: Optimize probe of srst/susp

PATCH New Xiang W 1 participant 1 message May 2, 2023

lore
Share & tools
lore

Xiang W

author
#0 lore raw

PATCH v3 1/1 lib: sbi: Optimize probe of srst/susp

No need to do a fully comprehensive count, just find a supported reset or suspend type

---
V3:
Fixing missing {}
Fixing tags of Andrew

V2:
Add a similar optimization to susp as suggested by Andrew

lib/sbi/sbi_ecall_srst.c | 10 ++++++----

 lib/sbi/sbi_ecall_susp.c | 10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)
lib/sbi/sbi_ecall_srst.c +6 -4
index 93b012c..36f24e5 100644
@@ -50,7 +50,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one standard reset types should be supported by
@@ -59,11 +59,13 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 
 	for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
 		if (sbi_system_reset_supported(type,
-					SBI_SRST_RESET_REASON_NONE))
-			count++;
+					SBI_SRST_RESET_REASON_NONE)) {
+			*out_val = 1;
+			return 0;
+		}
 	}
 
-	*out_val = (count) ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
lib/sbi/sbi_ecall_susp.c +6 -4
index f20126c..c8b8f64 100644
@@ -25,18 +25,20 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one suspend type should be supported by the
 	 * platform for the SBI SUSP extension to be usable.
 	 */
 	for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
-		if (sbi_system_suspend_supported(type))
-			count++;
+		if (sbi_system_suspend_supported(type)) {
+			*out_val = 1;
+			return 0;
+		}
 	}
 
-	*out_val = count ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
Signature · 1 line
2.39.2