summaryrefslogtreecommitdiff
path: root/drivers/staging/xgifb
diff options
context:
space:
mode:
authorPratik Jain <pratik.jain0509@gmail.com>2018-03-21 15:20:43 +0530
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-03-22 18:29:50 +0100
commit65197a7d361f01878ac23a2cc007c19095e5d8a6 (patch)
treec74fd9205ded62f33306816dc85e3359cf9afe58 /drivers/staging/xgifb
parentf81746470b47d9815ecc7de5724242960a87bd2a (diff)
Staging: xgifb: XGI_main_26.c: Refactored the function
Refactored the function `XGIfb_search_refresh_rate` by removing a level of `if...else` block nesting. Removed unnecessary parantheses. Removed potential bug of array underflow. Signed-off-by: Pratik Jain <pratik.jain0509@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/xgifb')
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index 10107de0119a..eca0b50f0df6 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -544,41 +544,42 @@ static u8 XGIfb_search_refresh_rate(struct xgifb_video_info *xgifb_info,
yres = XGIbios_mode[xgifb_info->mode_idx].yres;
xgifb_info->rate_idx = 0;
- while ((XGIfb_vrate[i].idx != 0) && (XGIfb_vrate[i].xres <= xres)) {
- if ((XGIfb_vrate[i].xres == xres) &&
- (XGIfb_vrate[i].yres == yres)) {
- if (XGIfb_vrate[i].refresh == rate) {
+
+ while (XGIfb_vrate[i].idx != 0 && XGIfb_vrate[i].xres <= xres) {
+ /* Skip values with xres or yres less than specified */
+ if ((XGIfb_vrate[i].yres != yres) ||
+ (XGIfb_vrate[i].xres != xres)) {
+ i++;
+ continue;
+ }
+ if (XGIfb_vrate[i].refresh == rate) {
+ xgifb_info->rate_idx = XGIfb_vrate[i].idx;
+ break;
+ } else if (XGIfb_vrate[i].refresh > rate) {
+ if (XGIfb_vrate[i].refresh - rate <= 3) {
+ pr_debug("Adjusting rate from %d up to %d\n",
+ rate, XGIfb_vrate[i].refresh);
xgifb_info->rate_idx = XGIfb_vrate[i].idx;
- break;
- } else if (XGIfb_vrate[i].refresh > rate) {
- if ((XGIfb_vrate[i].refresh - rate) <= 3) {
- pr_debug("Adjusting rate from %d up to %d\n",
- rate, XGIfb_vrate[i].refresh);
- xgifb_info->rate_idx =
- XGIfb_vrate[i].idx;
- xgifb_info->refresh_rate =
- XGIfb_vrate[i].refresh;
- } else if (((rate - XGIfb_vrate[i - 1].refresh)
- <= 2) && (XGIfb_vrate[i].idx
- != 1)) {
- pr_debug("Adjusting rate from %d down to %d\n",
- rate,
- XGIfb_vrate[i - 1].refresh);
- xgifb_info->rate_idx =
- XGIfb_vrate[i - 1].idx;
- xgifb_info->refresh_rate =
- XGIfb_vrate[i - 1].refresh;
- }
- break;
- } else if ((rate - XGIfb_vrate[i].refresh) <= 2) {
+ xgifb_info->refresh_rate =
+ XGIfb_vrate[i].refresh;
+ } else if ((XGIfb_vrate[i].idx != 1) &&
+ (rate - XGIfb_vrate[i - 1].refresh <= 2)) {
pr_debug("Adjusting rate from %d down to %d\n",
- rate, XGIfb_vrate[i].refresh);
- xgifb_info->rate_idx = XGIfb_vrate[i].idx;
- break;
+ rate, XGIfb_vrate[i - 1].refresh);
+ xgifb_info->rate_idx = XGIfb_vrate[i - 1].idx;
+ xgifb_info->refresh_rate =
+ XGIfb_vrate[i - 1].refresh;
}
+ break;
+ } else if (rate - XGIfb_vrate[i].refresh <= 2) {
+ pr_debug("Adjusting rate from %d down to %d\n",
+ rate, XGIfb_vrate[i].refresh);
+ xgifb_info->rate_idx = XGIfb_vrate[i].idx;
+ break;
}
i++;
}
+
if (xgifb_info->rate_idx > 0)
return xgifb_info->rate_idx;
pr_info("Unsupported rate %d for %dx%d\n",