Skip to content

Commit bf4b999

Browse files
committed
Extract helper for configuration index calculation
Refactors the computation of configuration register index and bit offset into a reusable helper to reduce code duplication and improve maintainability. Updates existing code to use the new helper.
1 parent ffeea75 commit bf4b999

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

arch/riscv/pmp.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ static const mempool_t kernel_mempools[] = {
190190
/* Global PMP configuration (shadow of hardware state) */
191191
static pmp_config_t pmp_global_config;
192192

193+
/* Helper to compute pmpcfg register index and bit offset for a given region */
194+
static inline void pmp_get_cfg_indices(uint8_t region_idx,
195+
uint8_t *cfg_idx,
196+
uint8_t *cfg_offset)
197+
{
198+
*cfg_idx = region_idx / 4;
199+
*cfg_offset = (region_idx % 4) * 8;
200+
}
201+
193202
pmp_config_t *pmp_get_config(void)
194203
{
195204
return &pmp_global_config;
@@ -283,8 +292,8 @@ int32_t pmp_set_region(pmp_config_t *config, const pmp_region_t *region)
283292
return ERR_PMP_LOCKED;
284293

285294
uint8_t region_idx = region->region_id;
286-
uint8_t pmpcfg_idx = region_idx / 4;
287-
uint8_t pmpcfg_offset = (region_idx % 4) * 8;
295+
uint8_t pmpcfg_idx, pmpcfg_offset;
296+
pmp_get_cfg_indices(region_idx, &pmpcfg_idx, &pmpcfg_offset);
288297

289298
/* Build configuration byte with TOR mode and permissions */
290299
uint8_t pmpcfg_perm =

0 commit comments

Comments
 (0)