systemlib: Fix param access for used params

This commit is contained in:
Lorenz Meier 2015-06-25 09:28:04 +02:00
parent c2127f9501
commit 3bad91dd3b
1 changed files with 7 additions and 6 deletions

View File

@ -326,7 +326,8 @@ param_for_used_index(unsigned index)
int count = get_param_info_count();
if (count && index < count) {
/* walk all params and count */
/* walk all params and count used params */
unsigned used_count = 0;
for (unsigned i = 0; i < (unsigned)size_param_changed_storage_bytes; i++) {
for (unsigned j = 0; j < bits_per_allocation_unit; j++) {
@ -335,11 +336,11 @@ param_for_used_index(unsigned index)
/* we found the right used count,
* return the param value
*/
if (index == count) {
if (index == used_count) {
return (param_t)(i * bits_per_allocation_unit + j);
}
count++;
used_count++;
}
}
}
@ -367,17 +368,17 @@ param_get_used_index(param_t param)
}
/* walk all params and count, now knowing that it has a valid index */
int count = 0;
int used_count = 0;
for (unsigned i = 0; i < (unsigned)size_param_changed_storage_bytes; i++) {
for (unsigned j = 0; j < bits_per_allocation_unit; j++) {
if (param_changed_storage[i] & (1 << j)) {
if ((unsigned)param == i * bits_per_allocation_unit + j) {
return count;
return used_count;
}
count++;
used_count++;
}
}
}