[PATCH 1/1] dtc: fix asm_emit_data()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



((d.len - off) >= sizeof(uint32_t)) will possibly be true if off > d.len:

sizeof(uint32_t)) is an unsigned type. The C language will convert
(d.len - off) to an unsigned type before executing the comparison.

Correct the inequality.
Change the equality for byte output to match the one for uint32_t.

Fixes: 53359016caf6 ("dtc: Use stdint.h types throughout dtc")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@xxxxxxxxxxxxx>
---
 flattree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flattree.c b/flattree.c
index 1bcd808..9f67104 100644
--- a/flattree.c
+++ b/flattree.c
@@ -156,12 +156,12 @@ static void asm_emit_data(void *e, struct data d)
 	for_each_marker_of_type(m, LABEL)
 		emit_offset_label(f, m->ref, m->offset);
 
-	while ((d.len - off) >= sizeof(uint32_t)) {
+	while (d.len + sizeof(uint32_t) >= off) {
 		asm_emit_cell(e, dtb_ld32(d.val + off));
 		off += sizeof(uint32_t);
 	}
 
-	while ((d.len - off) >= 1) {
+	while (d.len + 1 >= off) {
 		fprintf(f, "\t.byte\t0x%hhx\n", d.val[off]);
 		off += 1;
 	}
-- 
2.40.1




[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux