Skip to contentSkip to conversation

platform/x86: huawei-wmi: make validation stricter in huawei_wmi_battery_set()

PATCH In review Dan Carpenter 2 participants 3 messages Oct 15, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: huawei-wmi: make validation stricter in huawei_wmi_battery_set()

I don't think it makes sense for "end" to be negative or for even for it to be less than "start". That also means that "start" can't be more than 100 which is good.

Fixes b7527d0f4502 ("platform/x86: huawei-wmi: Add battery charging thresholds")
---
 drivers/platform/x86/huawei-wmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/huawei-wmi.c +1 -1
index 6720f78c60c2..02a505a72172 100644
@@ -343,7 +343,7 @@ static int huawei_wmi_battery_set(int start, int end)
 	union hwmi_arg arg;
 	int err;
 
-	if (start < 0 || end > 100)
+	if (start < 0 || end < start || end > 100)
 		return -EINVAL;
 
 	arg.cmd = BATTERY_THRESH_SET;
Signature · 1 line
2.20.1

A message that is not in the archive (sent off-list or not yet received): CAB3uXr63uUwxBjkeeoftZ6HYm_hmN+E5EUhu15_Mta2qruOugA@mail.gmail.com

#2 lore raw
Quoted 13 lines · Ayman Bagabas

Hi Dan

Quoted 4 lines · Dan Carpenter

I don't think it makes sense for "end" to be negative or for even for it to be less than "start". That also means that "start" can't be more than 100 which is good.

While this makes sense, you run into issues where you cannot set "start" before "end" and vice versa.

Quoted 7 lines

Take this scenario, you have startp and end�, now you want to set these to start@ and end`, you would have to set "start" first before you can change the value of "end" otherwise you will run into EINVAL. Now imagine you wanna go the opposite direction, you would have to set "end" before you can change "start".
I think having a little wiggle room is fine for such scenarios.

I haven't tested this code... What you're describing sounds really very weird to me, but I will accept that you know more about your use cases than I do.

My other concern is that right now you can set start > 100 or end < 0.

regards,
dan carpenter

#3 lore raw
Quoted 30 lines · Dan Carpenter
Quoted 17 lines · Ayman Bagabas

Hi Dan

Quoted 6 lines · Dan Carpenter

I don't think it makes sense for "end" to be negative or for even for it
to be less than "start". That also means that "start" can't be more
than 100 which is good.

While this makes sense, you run into issues where you cannot set "start"
before "end" and vice versa.

Quoted 11 lines

Take this scenario, you have startp and end�, now you want to set these
to start@ and end`, you would have to set "start" first before you can
change the value of "end" otherwise you will run into EINVAL. Now imagine
you wanna go the opposite direction, you would have to set "end" before you
can change "start".
I think having a little wiggle room is fine for such scenarios.

Quoted 6 lines

I haven't tested this code... What you're describing sounds really very weird to me, but I will accept that you know more about your use cases than I do.

My other concern is that right now you can set start > 100 or end < 0.

We should check for these cases.

Quoted 4 lines

regards,
dan carpenter