From: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: edubezval@gmail.com, rui.zhang@intel.com, philip.li@intel.com,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
Kukjin Kim <kgene@kernel.org>,
Krzysztof Kozlowski <krzk@kernel.org>,
"open list:SAMSUNG THERMAL DRIVER"
<linux-samsung-soc@vger.kernel.org>,
"moderated list:ARM/SAMSUNG EXYNOS ARM ARCHITECTURES"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] thermal/drivers/exynos_tmu: Fix warnings in temp_to_code / code_to_temp
Date: Fri, 13 Apr 2018 13:08:35 +0200 [thread overview]
Message-ID: <11044079.DdDvlFD91s@amdc3058> (raw)
In-Reply-To: <1523617209-1730-1-git-send-email-daniel.lezcano@linaro.org>
On Friday, April 13, 2018 01:00:09 PM Daniel Lezcano wrote:
> The latest driver cleanup introduced a compilation warning
>
> drivers/thermal/samsung/exynos_tmu.c: In function ‘exynos_get_temp’:
> drivers/thermal/samsung/exynos_tmu.c:931:37: warning: ‘temp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> *temp = code_to_temp(data, value) * MCELSIUS;
> ^
>
> drivers/thermal/samsung/exynos_tmu.c: In function ‘temp_to_code’
> drivers/thermal/samsung/exynos_tmu.c:304:9: warning: ‘temp_code’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> return temp_code;
> ^~~~~~~~~
>
> The compiler gives a warning because semantically speaking the
> function has no default value. However the code path, were the
> variable is never initialized is a dead branch because the switch
> statement always choose one of the two cases as the data->cal_type is
> initialized in the init function to one of both values.
>
> This is unclear as it adds a dependency on the initialization function
> and it is prone to error. Make things clearer by converting the
> functions with if ... return statements, thus showing we are expecting
> the values to be correctly filled before calling this function.
>
> This change fixes the couple of function warnings.
>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Thanks Daniel, this is much better fix.
Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
> ---
> drivers/thermal/samsung/exynos_tmu.c | 46 ++++++++++--------------------------
> 1 file changed, 12 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
> index 2ec8548..197f267 100644
> --- a/drivers/thermal/samsung/exynos_tmu.c
> +++ b/drivers/thermal/samsung/exynos_tmu.c
> @@ -284,24 +284,13 @@ static void exynos_report_trigger(struct exynos_tmu_data *p)
> */
> static int temp_to_code(struct exynos_tmu_data *data, u8 temp)
> {
> - int temp_code;
> -
> - switch (data->cal_type) {
> - case TYPE_TWO_POINT_TRIMMING:
> - temp_code = (temp - EXYNOS_FIRST_POINT_TRIM) *
> - (data->temp_error2 - data->temp_error1) /
> - (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) +
> - data->temp_error1;
> - break;
> - case TYPE_ONE_POINT_TRIMMING:
> - temp_code = temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM;
> - break;
> - default:
> - WARN_ON(1);
> - break;
> - }
> + if (data->cal_type == TYPE_ONE_POINT_TRIMMING)
> + return temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM;
>
> - return temp_code;
> + return (temp - EXYNOS_FIRST_POINT_TRIM) *
> + (data->temp_error2 - data->temp_error1) /
> + (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) +
> + data->temp_error1;
> }
>
> /*
> @@ -310,24 +299,13 @@ static int temp_to_code(struct exynos_tmu_data *data, u8 temp)
> */
> static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code)
> {
> - int temp;
> -
> - switch (data->cal_type) {
> - case TYPE_TWO_POINT_TRIMMING:
> - temp = (temp_code - data->temp_error1) *
> - (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) /
> - (data->temp_error2 - data->temp_error1) +
> - EXYNOS_FIRST_POINT_TRIM;
> - break;
> - case TYPE_ONE_POINT_TRIMMING:
> - temp = temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM;
> - break;
> - default:
> - WARN_ON(1);
> - break;
> - }
> + if (data->cal_type == TYPE_ONE_POINT_TRIMMING)
> + return temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM;
>
> - return temp;
> + return (temp_code - data->temp_error1) *
> + (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) /
> + (data->temp_error2 - data->temp_error1) +
> + EXYNOS_FIRST_POINT_TRIM;
> }
>
> static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info)
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
WARNING: multiple messages have this Message-ID (diff)
From: b.zolnierkie@samsung.com (Bartlomiej Zolnierkiewicz)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] thermal/drivers/exynos_tmu: Fix warnings in temp_to_code / code_to_temp
Date: Fri, 13 Apr 2018 13:08:35 +0200 [thread overview]
Message-ID: <11044079.DdDvlFD91s@amdc3058> (raw)
In-Reply-To: <1523617209-1730-1-git-send-email-daniel.lezcano@linaro.org>
On Friday, April 13, 2018 01:00:09 PM Daniel Lezcano wrote:
> The latest driver cleanup introduced a compilation warning
>
> drivers/thermal/samsung/exynos_tmu.c: In function ?exynos_get_temp?:
> drivers/thermal/samsung/exynos_tmu.c:931:37: warning: ?temp? may be used uninitialized in this function [-Wmaybe-uninitialized]
> *temp = code_to_temp(data, value) * MCELSIUS;
> ^
>
> drivers/thermal/samsung/exynos_tmu.c: In function ?temp_to_code?
> drivers/thermal/samsung/exynos_tmu.c:304:9: warning: ?temp_code? may be used uninitialized in this function [-Wmaybe-uninitialized]
> return temp_code;
> ^~~~~~~~~
>
> The compiler gives a warning because semantically speaking the
> function has no default value. However the code path, were the
> variable is never initialized is a dead branch because the switch
> statement always choose one of the two cases as the data->cal_type is
> initialized in the init function to one of both values.
>
> This is unclear as it adds a dependency on the initialization function
> and it is prone to error. Make things clearer by converting the
> functions with if ... return statements, thus showing we are expecting
> the values to be correctly filled before calling this function.
>
> This change fixes the couple of function warnings.
>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Thanks Daniel, this is much better fix.
Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
> ---
> drivers/thermal/samsung/exynos_tmu.c | 46 ++++++++++--------------------------
> 1 file changed, 12 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
> index 2ec8548..197f267 100644
> --- a/drivers/thermal/samsung/exynos_tmu.c
> +++ b/drivers/thermal/samsung/exynos_tmu.c
> @@ -284,24 +284,13 @@ static void exynos_report_trigger(struct exynos_tmu_data *p)
> */
> static int temp_to_code(struct exynos_tmu_data *data, u8 temp)
> {
> - int temp_code;
> -
> - switch (data->cal_type) {
> - case TYPE_TWO_POINT_TRIMMING:
> - temp_code = (temp - EXYNOS_FIRST_POINT_TRIM) *
> - (data->temp_error2 - data->temp_error1) /
> - (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) +
> - data->temp_error1;
> - break;
> - case TYPE_ONE_POINT_TRIMMING:
> - temp_code = temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM;
> - break;
> - default:
> - WARN_ON(1);
> - break;
> - }
> + if (data->cal_type == TYPE_ONE_POINT_TRIMMING)
> + return temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM;
>
> - return temp_code;
> + return (temp - EXYNOS_FIRST_POINT_TRIM) *
> + (data->temp_error2 - data->temp_error1) /
> + (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) +
> + data->temp_error1;
> }
>
> /*
> @@ -310,24 +299,13 @@ static int temp_to_code(struct exynos_tmu_data *data, u8 temp)
> */
> static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code)
> {
> - int temp;
> -
> - switch (data->cal_type) {
> - case TYPE_TWO_POINT_TRIMMING:
> - temp = (temp_code - data->temp_error1) *
> - (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) /
> - (data->temp_error2 - data->temp_error1) +
> - EXYNOS_FIRST_POINT_TRIM;
> - break;
> - case TYPE_ONE_POINT_TRIMMING:
> - temp = temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM;
> - break;
> - default:
> - WARN_ON(1);
> - break;
> - }
> + if (data->cal_type == TYPE_ONE_POINT_TRIMMING)
> + return temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM;
>
> - return temp;
> + return (temp_code - data->temp_error1) *
> + (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) /
> + (data->temp_error2 - data->temp_error1) +
> + EXYNOS_FIRST_POINT_TRIM;
> }
>
> static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info)
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
next prev parent reply other threads:[~2018-04-13 11:08 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-11 8:41 [GIT PULL] Thermal management updates for v4.17-rc1 Zhang Rui
2018-04-12 0:01 ` Linus Torvalds
2018-04-12 5:08 ` Zhang Rui
2018-04-12 16:55 ` Linus Torvalds
2018-04-12 17:42 ` Daniel Lezcano
2018-04-13 4:08 ` Eduardo Valentin
2018-04-13 5:29 ` Zhang Rui
2018-04-13 5:39 ` Zhang Rui
2018-04-13 8:55 ` Bartlomiej Zolnierkiewicz
2018-04-13 9:00 ` Daniel Lezcano
2018-04-13 9:08 ` Bartlomiej Zolnierkiewicz
2018-04-13 9:19 ` Daniel Lezcano
2018-04-13 9:28 ` Bartlomiej Zolnierkiewicz
2018-04-13 10:30 ` Daniel Lezcano
2018-04-13 10:41 ` Bartlomiej Zolnierkiewicz
2018-04-13 11:00 ` [PATCH] thermal/drivers/exynos_tmu: Fix warnings in temp_to_code / code_to_temp Daniel Lezcano
2018-04-13 11:00 ` Daniel Lezcano
2018-04-13 11:00 ` Daniel Lezcano
2018-04-13 11:08 ` Bartlomiej Zolnierkiewicz [this message]
2018-04-13 11:08 ` Bartlomiej Zolnierkiewicz
2018-04-13 11:10 ` [GIT PULL] Thermal management updates for v4.17-rc1 Daniel Lezcano
2018-04-13 11:12 ` Bartlomiej Zolnierkiewicz
2018-04-13 11:21 ` Bartlomiej Zolnierkiewicz
2018-04-13 10:08 ` Eduardo Valentin
2018-04-13 10:25 ` Eduardo Valentin
2018-04-13 10:27 ` Bartlomiej Zolnierkiewicz
2018-04-15 8:51 ` Eduardo Valentin
2018-04-13 8:50 ` Bartlomiej Zolnierkiewicz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11044079.DdDvlFD91s@amdc3058 \
--to=b.zolnierkie@samsung.com \
--cc=daniel.lezcano@linaro.org \
--cc=edubezval@gmail.com \
--cc=kgene@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=philip.li@intel.com \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.