From b731ccd999dbc4ac22d2bf40c07347b8479ff80b Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Tue, 9 Mar 2021 07:40:48 +0800 Subject: [PATCH] hwmon: qti_amoled_ecm: return avg_current as 0 upon error exceptions Avg_current is an unsigned 16-bit data and assigning it a negative value would make it being shown as a very big positive value which doesn't make sense for ECM current measurement. Instead, assign it to 0 upon error exceptions and print out corresponding messages. Change-Id: I438667e40d63e4142860b7de4e7cf7495d3c424e Signed-off-by: Fenglin Wu --- drivers/hwmon/qti_amoled_ecm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/qti_amoled_ecm.c b/drivers/hwmon/qti_amoled_ecm.c index 9954598ae8d3..1fc019987694 100644 --- a/drivers/hwmon/qti_amoled_ecm.c +++ b/drivers/hwmon/qti_amoled_ecm.c @@ -337,9 +337,9 @@ static void ecm_average_work(struct work_struct *work) mutex_lock(&ecm->sdam_lock); if (!data->num_m_samples || !data->m_cumulative) { - pr_warn("Invalid data, num_m_samples=%u m_cumulative:%u\n", + pr_warn_ratelimited("Invalid data, num_m_samples=%u m_cumulative:%u\n", data->num_m_samples, data->m_cumulative); - data->avg_current = -EINVAL; + data->avg_current = 0; } else { data->avg_current = data->m_cumulative / data->num_m_samples; pr_debug("avg_current=%u mA\n", data->avg_current); @@ -510,11 +510,14 @@ static int handle_ecm_abort(struct amoled_ecm *ecm) switch (mode) { case ECM_MODE_MULTI_FRAMES: - data->avg_current = -EIO; + pr_warn_ratelimited("Multiple frames mode is not supported\n"); + data->avg_current = 0; break; case ECM_MODE_CONTINUOUS: if (data->num_m_samples < ECM_MIN_M_SAMPLES) { - data->avg_current = -EIO; + pr_warn_ratelimited("Too few samples %u for continuous mode\n", + data->num_m_samples); + data->avg_current = 0; break; } @@ -522,7 +525,8 @@ static int handle_ecm_abort(struct amoled_ecm *ecm) schedule_delayed_work(&ecm->average_work, 0); break; default: - data->avg_current = -EINVAL; + pr_err_ratelimited("Invalid ECM operation mode: %u\n", mode); + data->avg_current = 0; return -EINVAL; }