[coreboot-gerrit] Patch set updated for coreboot: nb/i945, gm45, x4x/gma.c: fix unsigned arithmetics

Arthur Heymans (arthur@aheymans.xyz) gerrit at coreboot.org
Wed Oct 12 14:38:37 CEST 2016


Arthur Heymans (arthur at aheymans.xyz) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16992

-gerrit

commit e4d2782ca83fea5e8178b7691ada25b8c6ae34c2
Author: Arthur Heymans <arthur at aheymans.xyz>
Date:   Wed Oct 12 01:04:28 2016 +0200

    nb/i945,gm45,x4x/gma.c: fix unsigned arithmetics
    
    This issue was found by Coverity Scan, CID 1364118.
    
    Change-Id: Iba3c0f4f952729d9e0987d928b63ef8b8fe8841e
    Signed-off-by: Arthur Heymans <arthur at aheymans.xyz>
---
 src/northbridge/intel/gm45/gma.c | 6 ++++--
 src/northbridge/intel/i945/gma.c | 3 ++-
 src/northbridge/intel/x4x/gma.c  | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/northbridge/intel/gm45/gma.c b/src/northbridge/intel/gm45/gma.c
index c12b038..1e2ea07 100644
--- a/src/northbridge/intel/gm45/gma.c
+++ b/src/northbridge/intel/gm45/gma.c
@@ -171,7 +171,8 @@ static void gma_init_lvds(const struct northbridge_intel_gm45_config *info,
 					u32 p = candp1 * pixel_p2;
 					u32 vco = DIV_ROUND_CLOSEST(BASE_FREQUENCY * m, candn + 2);
 					u32 dot = DIV_ROUND_CLOSEST(vco, p);
-					u32 this_err = ABS(dot - target_frequency);
+					u32 this_err = MAX(dot, target_frequency) -
+						MIN(dot, target_frequency);
 					if (this_err < smallest_err) {
 						smallest_err = this_err;
 						pixel_n = candn;
@@ -477,7 +478,8 @@ static void gma_init_vga(const struct northbridge_intel_gm45_config *info,
 					u32 p = candp1 * pixel_p2;
 					u32 vco = DIV_ROUND_CLOSEST(BASE_FREQUENCY * m, candn + 2);
 					u32 dot = DIV_ROUND_CLOSEST(vco, p);
-					u32 this_err = ABS(dot - target_frequency);
+					u32 this_err = MAX(dot, target_frequency) -
+						MIN(dot, target_frequency);
 					if (this_err < smallest_err) {
 						smallest_err= this_err;
 						pixel_n = candn;
diff --git a/src/northbridge/intel/i945/gma.c b/src/northbridge/intel/i945/gma.c
index eeb377a..86eda67 100644
--- a/src/northbridge/intel/i945/gma.c
+++ b/src/northbridge/intel/i945/gma.c
@@ -177,7 +177,8 @@ static int intel_gma_init_lvds(struct northbridge_intel_i945_config *conf,
 					u32 p = candp1 * pixel_p2;
 					u32 vco = DIV_ROUND_CLOSEST(BASE_FREQUENCY * m, candn + 2);
 					u32 dot = DIV_ROUND_CLOSEST(vco, p);
-					u32 this_err = ABS(dot - target_frequency);
+					u32 this_err = MAX(dot, target_frequency) -
+						MIN(dot, target_frequency);
 					if ((m < 70) || (m > 120))
 						continue;
 					if (this_err < smallest_err) {
diff --git a/src/northbridge/intel/x4x/gma.c b/src/northbridge/intel/x4x/gma.c
index 8cf853f..728edc4 100644
--- a/src/northbridge/intel/x4x/gma.c
+++ b/src/northbridge/intel/x4x/gma.c
@@ -191,7 +191,8 @@ static void intel_gma_init(const struct northbridge_intel_x4x_config *info,
 					u32 vco = DIV_ROUND_CLOSEST(
 						BASE_FREQUENCY * m, candn + 2);
 					u32 dot = DIV_ROUND_CLOSEST(vco, p);
-					u32 this_err = ABS(dot - target_frequency);
+					u32 this_err = MAX(dot, target_frequency) -
+						MIN(dot, target_frequency);
 					if (this_err < err_most) {
 						err_most = this_err;
 						pixel_n = candn;



More information about the coreboot-gerrit mailing list