Skip to content

Commit f333c3e

Browse files
authored
Merge pull request #13699 from boraozgen/bugfix/sfdp-find-addr-region
Fix sfdp_find_addr_region algorithm
2 parents 9c40d1f + 7f0716a commit f333c3e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

drivers/include/drivers/internal/SFDP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfd
129129
*
130130
* @return Region number
131131
*/
132-
int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info);
132+
int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info);
133133

134134
/** Finds the largest Erase Type of the Region to which the offset belongs to
135135
*

drivers/source/SFDP.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,20 +373,20 @@ int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfd
373373
return 0;
374374
}
375375

376-
int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info)
376+
int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info)
377377
{
378-
if ((offset > sfdp_info.bptbl.device_size_bytes) || (sfdp_info.smptbl.region_cnt == 0)) {
378+
if ((offset >= sfdp_info.bptbl.device_size_bytes) || (sfdp_info.smptbl.region_cnt == 0)) {
379379
return -1;
380380
}
381381

382382
if (sfdp_info.smptbl.region_cnt == 1) {
383383
return 0;
384384
}
385385

386-
for (int idx = sfdp_info.smptbl.region_cnt - 2; idx >= 0; idx--) {
386+
for (int idx = 0; idx < sfdp_info.smptbl.region_cnt; idx++) {
387387

388-
if (offset > sfdp_info.smptbl.region_high_boundary[idx]) {
389-
return (idx + 1);
388+
if (offset <= sfdp_info.smptbl.region_high_boundary[idx]) {
389+
return idx;
390390
}
391391
}
392392
return -1;

0 commit comments

Comments
 (0)