* [PATCH] HID: wiimote: check completion in wiimod_battery_get_property
@ 2023-03-20 15:34 Nikita Zhandarovich
2023-03-20 19:08 ` David Rheinsberg
0 siblings, 1 reply; 3+ messages in thread
From: Nikita Zhandarovich @ 2023-03-20 15:34 UTC (permalink / raw)
To: David Rheinsberg
Cc: Nikita Zhandarovich, Jiri Kosina, Benjamin Tissoires,
David Herrmann, linux-input, linux-kernel, lvc-project
wiimote_cmd_wait() in wiimod_battery_get_property() may signal that the
task of getting specific battery property was interrupted or timed out.
There is no need to do any further computation in such cases, so just
return the error.
Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.
Fixes: dcf392313817 ("HID: wiimote: convert BATTERY to module")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
drivers/hid/hid-wiimote-modules.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
index dbccdfa63916..9755718d9856 100644
--- a/drivers/hid/hid-wiimote-modules.c
+++ b/drivers/hid/hid-wiimote-modules.c
@@ -220,8 +220,10 @@ static int wiimod_battery_get_property(struct power_supply *psy,
wiiproto_req_status(wdata);
spin_unlock_irqrestore(&wdata->state.lock, flags);
- wiimote_cmd_wait(wdata);
+ ret = wiimote_cmd_wait(wdata);
wiimote_cmd_release(wdata);
+ if (ret)
+ return ret;
spin_lock_irqsave(&wdata->state.lock, flags);
state = wdata->state.cmd_battery;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: wiimote: check completion in wiimod_battery_get_property
2023-03-20 15:34 [PATCH] HID: wiimote: check completion in wiimod_battery_get_property Nikita Zhandarovich
@ 2023-03-20 19:08 ` David Rheinsberg
2023-03-21 6:13 ` Nikita Zhandarovich
0 siblings, 1 reply; 3+ messages in thread
From: David Rheinsberg @ 2023-03-20 19:08 UTC (permalink / raw)
To: Nikita Zhandarovich
Cc: Jiri Kosina, Benjamin Tissoires, David Herrmann, linux-input,
linux-kernel, lvc-project
Hi
On Mon, 20 Mar 2023 at 16:34, Nikita Zhandarovich
<n.zhandarovich@fintech.ru> wrote:
>
> wiimote_cmd_wait() in wiimod_battery_get_property() may signal that the
> task of getting specific battery property was interrupted or timed out.
> There is no need to do any further computation in such cases, so just
> return the error.
>
> Found by Linux Verification Center (linuxtesting.org) with static
> analysis tool SVACE.
>
> Fixes: dcf392313817 ("HID: wiimote: convert BATTERY to module")
> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
> ---
> drivers/hid/hid-wiimote-modules.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
> index dbccdfa63916..9755718d9856 100644
> --- a/drivers/hid/hid-wiimote-modules.c
> +++ b/drivers/hid/hid-wiimote-modules.c
> @@ -220,8 +220,10 @@ static int wiimod_battery_get_property(struct power_supply *psy,
> wiiproto_req_status(wdata);
> spin_unlock_irqrestore(&wdata->state.lock, flags);
>
> - wiimote_cmd_wait(wdata);
> + ret = wiimote_cmd_wait(wdata);
> wiimote_cmd_release(wdata);
> + if (ret)
> + return ret;
The current code returns cached battery-information in case a
synchronous update did not succeed. Battery information is likely
updated regularly, anyway, so the synchronous update is usually not
required.
I don't think bailing out and returning the error to the caller is
required or gains us anything but more complexity. Or am I missing
something here?
Thanks
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: wiimote: check completion in wiimod_battery_get_property
2023-03-20 19:08 ` David Rheinsberg
@ 2023-03-21 6:13 ` Nikita Zhandarovich
0 siblings, 0 replies; 3+ messages in thread
From: Nikita Zhandarovich @ 2023-03-21 6:13 UTC (permalink / raw)
To: David Rheinsberg
Cc: Jiri Kosina, Benjamin Tissoires, David Herrmann, linux-input,
linux-kernel, lvc-project
On 3/20/23 12:08, David Rheinsberg wrote:
> Hi
>
> On Mon, 20 Mar 2023 at 16:34, Nikita Zhandarovich
> <n.zhandarovich@fintech.ru> wrote:
>>
>> wiimote_cmd_wait() in wiimod_battery_get_property() may signal that the
>> task of getting specific battery property was interrupted or timed out.
>> There is no need to do any further computation in such cases, so just
>> return the error.
>>
>> Found by Linux Verification Center (linuxtesting.org) with static
>> analysis tool SVACE.
>>
>> Fixes: dcf392313817 ("HID: wiimote: convert BATTERY to module")
>> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
>> ---
>> drivers/hid/hid-wiimote-modules.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
>> index dbccdfa63916..9755718d9856 100644
>> --- a/drivers/hid/hid-wiimote-modules.c
>> +++ b/drivers/hid/hid-wiimote-modules.c
>> @@ -220,8 +220,10 @@ static int wiimod_battery_get_property(struct power_supply *psy,
>> wiiproto_req_status(wdata);
>> spin_unlock_irqrestore(&wdata->state.lock, flags);
>>
>> - wiimote_cmd_wait(wdata);
>> + ret = wiimote_cmd_wait(wdata);
>> wiimote_cmd_release(wdata);
>> + if (ret)
>> + return ret;
>
> The current code returns cached battery-information in case a
> synchronous update did not succeed. Battery information is likely
> updated regularly, anyway, so the synchronous update is usually not
> required.
>
> I don't think bailing out and returning the error to the caller is
> required or gains us anything but more complexity. Or am I missing
> something here?
>
> Thanks
> David
Hi. I think you are right, my change is not that essential to begin with
and there is no urgency to patch this.
Thanks for your patience,
Nikita
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-21 6:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20 15:34 [PATCH] HID: wiimote: check completion in wiimod_battery_get_property Nikita Zhandarovich
2023-03-20 19:08 ` David Rheinsberg
2023-03-21 6:13 ` Nikita Zhandarovich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).