Merge pull request #13699 from boraozgen/bugfix/sfdp-find-addr-region

Fix sfdp_find_addr_region algorithm
pull/13904/head
Martin Kojtal 2020-11-12 08:43:02 +00:00 committed by GitHub
commit f333c3ead1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -129,7 +129,7 @@ int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfd
* *
* @return Region number * @return Region number
*/ */
int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info); int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info);
/** Finds the largest Erase Type of the Region to which the offset belongs to /** Finds the largest Erase Type of the Region to which the offset belongs to
* *

View File

@ -373,9 +373,9 @@ int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfd
return 0; return 0;
} }
int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info) int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info)
{ {
if ((offset > sfdp_info.bptbl.device_size_bytes) || (sfdp_info.smptbl.region_cnt == 0)) { if ((offset >= sfdp_info.bptbl.device_size_bytes) || (sfdp_info.smptbl.region_cnt == 0)) {
return -1; return -1;
} }
@ -383,10 +383,10 @@ int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info)
return 0; return 0;
} }
for (int idx = sfdp_info.smptbl.region_cnt - 2; idx >= 0; idx--) { for (int idx = 0; idx < sfdp_info.smptbl.region_cnt; idx++) {
if (offset > sfdp_info.smptbl.region_high_boundary[idx]) { if (offset <= sfdp_info.smptbl.region_high_boundary[idx]) {
return (idx + 1); return idx;
} }
} }
return -1; return -1;