David Hendricks has uploaded this change for review. ( https://review.coreboot.org/20937
Change subject: ich_descriptors: Fix off-by-one error ......................................................................
ich_descriptors: Fix off-by-one error
The "number of masters" (NM) reflects the value that begins at 1. This value is compared with the constant MAX_NUM_MASTERS, which also begins with 1. So we really do want the raw value of NM to be used in the comparison. This fixes problems that arise when the actual NM value and MAX_NUM_MASTERS are equal.
Also, the return value then gets used as an upper limit for for loops with counters beginning at 0. So adding 1 to the return value makes it even more wrong than it was before.
Change-Id: I92627332265cf79720b98241d73bc36b1f6a7167 Signed-off-by: David Hendricks dhendricks@fb.com --- M ich_descriptors.c 1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/37/20937/1
diff --git a/ich_descriptors.c b/ich_descriptors.c index a2f8edf..542e1ec 100644 --- a/ich_descriptors.c +++ b/ich_descriptors.c @@ -66,8 +66,8 @@
ssize_t ich_number_of_masters(const enum ich_chipset cs, const struct ich_desc_content *const cont) { - if (cont->NM < MAX_NUM_MASTERS) - return cont->NM + 1; + if (cont->NM <= MAX_NUM_MASTERS) + return cont->NM; else return -1; }