summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXiang W <[email protected]>2023-10-31 00:39:40 +0800
committerAnup Patel <[email protected]>2023-11-17 13:23:49 +0530
commit6602e11de375b761d778808cc38645fce314c4fa (patch)
tree534c8de289a207d5a58fa5ee6d1bd6abf4990d5b /lib
parent6e5b0cfb4520d0c2d36ae1005770f2537970e90a (diff)
lib: sbi: change sbi_hart_features.extensions as an array
In the future there may be a lot of ISA extensions, a 'long' may not be able to accommodate, changed to an array for the future. Addresses-Coverity-ID: 1568357 Out-of-bounds access Fixes: 6259b2ec2d09 ("lib: utils/fdt: Fix fdt_parse_isa_extensions() implementation") Signed-off-by: Xiang W <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_hart.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index b47f00b2..77eef49c 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -620,9 +620,9 @@ static inline void __sbi_hart_update_extension(
bool enable)
{
if (enable)
- hfeatures->extensions |= BIT(ext);
+ __set_bit(ext, hfeatures->extensions);
else
- hfeatures->extensions &= ~BIT(ext);
+ __clear_bit(ext, hfeatures->extensions);
}
/**
@@ -655,7 +655,7 @@ bool sbi_hart_has_extension(struct sbi_scratch *scratch,
struct sbi_hart_features *hfeatures =
sbi_scratch_offset_ptr(scratch, hart_features_offset);
- if (hfeatures->extensions & BIT(ext))
+ if (__test_bit(ext, hfeatures->extensions))
return true;
else
return false;
@@ -721,24 +721,16 @@ void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
return;
sbi_memset(extensions_str, 0, nestr);
- if (!hfeatures->extensions)
- goto done;
-
- do {
- if (hfeatures->extensions & BIT(ext)) {
- temp = sbi_hart_extension_id2string(ext);
- if (temp) {
- sbi_snprintf(extensions_str + offset,
- nestr - offset,
- "%s,", temp);
- offset = offset + sbi_strlen(temp) + 1;
- }
+ for_each_set_bit(ext, hfeatures->extensions, SBI_HART_EXT_MAX) {
+ temp = sbi_hart_extension_id2string(ext);
+ if (temp) {
+ sbi_snprintf(extensions_str + offset,
+ nestr - offset,
+ "%s,", temp);
+ offset = offset + sbi_strlen(temp) + 1;
}
+ }
- ext++;
- } while (ext < SBI_HART_EXT_MAX);
-
-done:
if (offset)
extensions_str[offset - 1] = '\0';
else
@@ -808,7 +800,7 @@ static int hart_detect_features(struct sbi_scratch *scratch)
return 0;
/* Clear hart features */
- hfeatures->extensions = 0;
+ sbi_memset(hfeatures->extensions, 0, sizeof(hfeatures->extensions));
hfeatures->pmp_count = 0;
hfeatures->mhpm_mask = 0;