From 7c6ed19d8f98b96fd2b09e7cf2ef8c3eaab417b4 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Parimi Date: Tue, 27 Aug 2013 17:29:44 +0530 Subject: [PATCH] msm: msm_fb: validating backlight level and scale value Validating the value of backlight to be not more than the max value and also ensuring that the backlight scale value is not more than 1024, thereby ensuring that backlight scaling factor is not more than 1 Change-Id: I6a6f4f0f0a8c272edcac5078276fb406ddee3e90 Signed-off-by: Krishna Chaitanya Parimi [zhaoweiliew: Add bl_lvl argument for msm_fb_scale_bl in bl_workqueue_handler] Signed-off-by: Zhao Wei Liew --- drivers/video/msm/msm_fb.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/video/msm/msm_fb.c b/drivers/video/msm/msm_fb.c index ddcab26166c1..6eb7374402ab 100644 --- a/drivers/video/msm/msm_fb.c +++ b/drivers/video/msm/msm_fb.c @@ -123,7 +123,7 @@ static int msm_fb_ioctl(struct fb_info *info, unsigned int cmd, static int msm_fb_mmap(struct fb_info *info, struct vm_area_struct * vma); static int mdp_bl_scale_config(struct msm_fb_data_type *mfd, struct mdp_bl_scale_data *data); -static void msm_fb_scale_bl(__u32 *bl_lvl); +static void msm_fb_scale_bl(__u32 bl_max, __u32 *bl_lvl); static int msm_fb_commit_thread(void *data); static int msm_fb_pan_idle(struct msm_fb_data_type *mfd); @@ -1041,13 +1041,23 @@ static int mdp_bl_scale_config(struct msm_fb_data_type *mfd, return ret; } -static void msm_fb_scale_bl(__u32 *bl_lvl) +static void msm_fb_scale_bl(__u32 bl_max, __u32 *bl_lvl) { __u32 temp = *bl_lvl; pr_debug("%s: input = %d, scale = %d", __func__, temp, bl_scale); if (temp >= bl_min_lvl) { + /* checking if temp is below bl_max else capping */ + if (temp > bl_max) { + pr_warn("%s: invalid bl level\n", __func__); + temp = bl_max; + } + /* checking if bl_scale is below 1024 else capping */ + if (bl_scale > 1024) { + pr_warn("%s: invalid bl scale\n", __func__); + bl_scale = 1024; + } /* bl_scale is the numerator of scaling fraction (x/1024)*/ - temp = ((*bl_lvl) * bl_scale) / 1024; + temp = (temp * bl_scale) / 1024; /*if less than minimum level, use min level*/ if (temp < bl_min_lvl) @@ -1072,7 +1082,7 @@ void msm_fb_set_backlight(struct msm_fb_data_type *mfd, __u32 bkl_lvl) pdata = (struct msm_fb_panel_data *)mfd->pdev->dev.platform_data; if ((pdata) && (pdata->set_backlight)) { - msm_fb_scale_bl(&temp); + msm_fb_scale_bl(mfd->panel_info.bl_max, &temp); if (bl_level_old == temp) { return; } @@ -2115,7 +2125,7 @@ static void bl_workqueue_handler(struct work_struct *work) down(&mfd->sem); if ((pdata) && (pdata->set_backlight) && (!bl_updated) && (mfd->panel_power_on)) { - msm_fb_scale_bl(&temp); + msm_fb_scale_bl(mfd->panel_info.bl_max, &temp); mfd->bl_level = temp; pdata->set_backlight(mfd); bl_level_old = unset_bl_level;