[OpenBIOS] [PATCH 3/3] OFMEM: fix off-by-one calculation in available property tail calculation

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Sun May 10 10:51:41 CEST 2015


Make sure that the final address of the range is passed into
ofmem_update_memory_available() for physical ranges, rather than the
physical memory size. This enables us to fix an off-by-one calculation
in the tail entry for the available property.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 openbios-devel/libopenbios/ofmem_common.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/openbios-devel/libopenbios/ofmem_common.c b/openbios-devel/libopenbios/ofmem_common.c
index ef91119..052aa2f 100644
--- a/openbios-devel/libopenbios/ofmem_common.c
+++ b/openbios-devel/libopenbios/ofmem_common.c
@@ -334,8 +334,8 @@ static void ofmem_update_memory_available( phandle_t ph, range_t *range,
 	}
 
 	/* tail */
-	if (start < top_address) {
-		ofmem_arch_create_available_entry(ph, &prop[ncells], start, top_address - start);
+	if ((start - 1) < top_address) {
+		ofmem_arch_create_available_entry(ph, &prop[ncells], start, top_address - start + 1);
 		ncells += ofmem_arch_get_available_entry_size(ph);
 	}
 
@@ -348,7 +348,7 @@ static void ofmem_update_translations( void )
 	ofmem_t *ofmem = ofmem_arch_get_private();
 
 	ofmem_update_memory_available(s_phandle_memory, ofmem->phys_range, 
-			&phys_range_prop, &phys_range_prop_size, &phys_range_prop_used, get_ram_size());
+			&phys_range_prop, &phys_range_prop_size, &phys_range_prop_used, get_ram_size() - 1);
 	ofmem_update_memory_available(s_phandle_mmu, ofmem->virt_range, 
 			&virt_range_prop, &virt_range_prop_size, &virt_range_prop_used, (ucell)-1);
 	ofmem_update_mmu_translations();
-- 
1.7.10.4




More information about the OpenBIOS mailing list