diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-05-10 11:36:14 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-05-19 09:19:34 +0530 |
commit | 49841832b85bbcc8ae99dc2b808175a1a8650ff3 (patch) | |
tree | 8f3460e224933741c99f6a84ca94baf039a165f0 /lib/sbi/sbi_platform.c | |
parent | 28b40528499755ec19a6f8a06dc47e65619fb96c (diff) |
lib: sbi: Improve get_feature_str() implementation and usage
We do following improvements for get_feature_str():
1. We should return "none" from get_feature_str() no features
available instead of sbi_boot_prints() explicitly handling
failure.
2. We don't need to return failure (just like misa_xlen())
because we are returning "none" for no features and we are
truncating output when space is not available.
3. Based on 1 and 2, the sbi_boot_prints() can be further
simplified.
4. No need for two char[] in sbi_boot_prints()
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'lib/sbi/sbi_platform.c')
-rw-r--r-- | lib/sbi/sbi_platform.c | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/lib/sbi/sbi_platform.c b/lib/sbi/sbi_platform.c index 1912512..568d956 100644 --- a/lib/sbi/sbi_platform.c +++ b/lib/sbi/sbi_platform.c @@ -38,27 +38,20 @@ static inline char *sbi_platform_feature_id2string(unsigned long feature) return fstr; } -/** - * Get the platform features in string format - * - * @param plat pointer to struct sbi_platform - * @param features_str pointer to a char array where the features string will be - * updated - * @param nfstr length of the features_str. The feature string will be truncated - * if nfstr is not long enough. - * @return the features value currently set for the given platform - */ -int sbi_platform_get_features_str(const struct sbi_platform *plat, - char *features_str, int nfstr) +void sbi_platform_get_features_str(const struct sbi_platform *plat, + char *features_str, int nfstr) { unsigned long features, feat = 1UL; char *temp; int offset = 0; if (!plat || !features_str || !nfstr) - return SBI_EINVAL; + return; + sbi_memset(features_str, 0, nfstr); features = sbi_platform_get_features(plat); + if (!features) + goto done; do { if (features & feat) { @@ -72,21 +65,14 @@ int sbi_platform_get_features_str(const struct sbi_platform *plat, feat = feat << 1; } while (feat <= SBI_PLATFORM_HAS_LAST_FEATURE); - features_str[offset - 1] = '\0'; - - return 0; +done: + if (offset) + features_str[offset - 1] = '\0'; + else + sbi_strncpy(features_str, "none", nfstr); } -/** - * Get HART index for the given HART - * - * @param plat pointer to struct sbi_platform - * @param hartid HART ID - * - * @return 0 <= value < hart_count for valid HART otherwise -1U - */ -u32 sbi_platform_hart_index(const struct sbi_platform *plat, - u32 hartid) +u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid) { u32 i; |