* [PATCH] thermal: int340x: delete bogus length check
@ 2021-09-30 12:28 Dan Carpenter
2021-10-05 14:47 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-09-30 12:28 UTC (permalink / raw)
To: Zhang Rui, Takashi Iwai
Cc: Daniel Lezcano, Amit Kucheria, Srinivas Pandruvada,
Sumeet Pawnikar, linux-pm, kernel-janitors
This check has a signedness bug and does not work. If "length" is
larger than "PAGE_SIZE" then "PAGE_SIZE - length" is not negative
but instead it is a large unsigned value. Fortunately, Takashi Iwai
changed this code to use scnprint() instead of snprintf() so now
"length" is never larger than "PAGE_SIZE - 1" and the check can be
removed.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index 19926beeb3b7..8502b7d8df89 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -129,11 +129,10 @@ static ssize_t available_uuids_show(struct device *dev,
for (i = 0; i < INT3400_THERMAL_MAXIMUM_UUID; i++) {
if (priv->uuid_bitmap & (1 << i))
- if (PAGE_SIZE - length > 0)
- length += scnprintf(&buf[length],
- PAGE_SIZE - length,
- "%s\n",
- int3400_thermal_uuids[i]);
+ length += scnprintf(&buf[length],
+ PAGE_SIZE - length,
+ "%s\n",
+ int3400_thermal_uuids[i]);
}
return length;
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] thermal: int340x: delete bogus length check
2021-09-30 12:28 [PATCH] thermal: int340x: delete bogus length check Dan Carpenter
@ 2021-10-05 14:47 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2021-10-05 14:47 UTC (permalink / raw)
To: Dan Carpenter
Cc: Zhang Rui, Takashi Iwai, Daniel Lezcano, Amit Kucheria,
Srinivas Pandruvada, Sumeet Pawnikar, Linux PM, kernel-janitors
On Thu, Sep 30, 2021 at 2:28 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> This check has a signedness bug and does not work. If "length" is
> larger than "PAGE_SIZE" then "PAGE_SIZE - length" is not negative
> but instead it is a large unsigned value. Fortunately, Takashi Iwai
> changed this code to use scnprint() instead of snprintf() so now
> "length" is never larger than "PAGE_SIZE - 1" and the check can be
> removed.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> index 19926beeb3b7..8502b7d8df89 100644
> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> @@ -129,11 +129,10 @@ static ssize_t available_uuids_show(struct device *dev,
>
> for (i = 0; i < INT3400_THERMAL_MAXIMUM_UUID; i++) {
> if (priv->uuid_bitmap & (1 << i))
> - if (PAGE_SIZE - length > 0)
> - length += scnprintf(&buf[length],
> - PAGE_SIZE - length,
> - "%s\n",
> - int3400_thermal_uuids[i]);
> + length += scnprintf(&buf[length],
> + PAGE_SIZE - length,
> + "%s\n",
> + int3400_thermal_uuids[i]);
> }
>
> return length;
> --
Applied as 5.16 material, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-05 14:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-30 12:28 [PATCH] thermal: int340x: delete bogus length check Dan Carpenter
2021-10-05 14:47 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox