diff mbox series

HID: logitech-dj: Fix error handling in logi_dj_recv_switch_to_dj_mode()

Message ID 20230613101635.77820-1-n.zhandarovich@fintech.ru
State Accepted
Commit 6f20d3261265885f6a6be4cda49d7019728760e0
Headers show
Series HID: logitech-dj: Fix error handling in logi_dj_recv_switch_to_dj_mode() | expand

Commit Message

Nikita Zhandarovich June 13, 2023, 10:16 a.m. UTC
Presently, if a call to logi_dj_recv_send_report() fails, we do
not learn about the error until after sending short
HID_OUTPUT_REPORT with hid_hw_raw_request().
To handle this somewhat unlikely issue, return on error in
logi_dj_recv_send_report() (minding ugly sleep workaround) and
take into account the result of hid_hw_raw_request().

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: 6a9ddc897883 ("HID: logitech-dj: enable notifications on connect/disconnect")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
 drivers/hid/hid-logitech-dj.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jiri Kosina Aug. 14, 2023, 9:18 a.m. UTC | #1
On Tue, 13 Jun 2023, Nikita Zhandarovich wrote:

> Presently, if a call to logi_dj_recv_send_report() fails, we do
> not learn about the error until after sending short
> HID_OUTPUT_REPORT with hid_hw_raw_request().
> To handle this somewhat unlikely issue, return on error in
> logi_dj_recv_send_report() (minding ugly sleep workaround) and
> take into account the result of hid_hw_raw_request().
> 
> Found by Linux Verification Center (linuxtesting.org) with static
> analysis tool SVACE.
> 
> Fixes: 6a9ddc897883 ("HID: logitech-dj: enable notifications on connect/disconnect")
> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
> ---
>  drivers/hid/hid-logitech-dj.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
> index 62180414efcc..e6a8b6d8eab7 100644
> --- a/drivers/hid/hid-logitech-dj.c
> +++ b/drivers/hid/hid-logitech-dj.c
> @@ -1285,6 +1285,9 @@ static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
>  		 * 50 msec should gives enough time to the receiver to be ready.
>  		 */
>  		msleep(50);
> +
> +		if (retval)
> +			return retval;
>  	}
>  
>  	/*
> @@ -1306,7 +1309,7 @@ static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
>  	buf[5] = 0x09;
>  	buf[6] = 0x00;
>  
> -	hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf,
> +	retval = hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf,
>  			HIDPP_REPORT_SHORT_LENGTH, HID_OUTPUT_REPORT,
>  			HID_REQ_SET_REPORT);

Looks good to me. Benjamin, could you please Ack/apply it?

Thanks,
Benjamin Tissoires Aug. 22, 2023, 6:30 p.m. UTC | #2
On Tue, 13 Jun 2023 03:16:35 -0700, Nikita Zhandarovich wrote:
> Presently, if a call to logi_dj_recv_send_report() fails, we do
> not learn about the error until after sending short
> HID_OUTPUT_REPORT with hid_hw_raw_request().
> To handle this somewhat unlikely issue, return on error in
> logi_dj_recv_send_report() (minding ugly sleep workaround) and
> take into account the result of hid_hw_raw_request().
> 
> [...]

Applied to hid/hid.git (for-6.6/logitech), thanks!

[1/1] HID: logitech-dj: Fix error handling in logi_dj_recv_switch_to_dj_mode()
      https://git.kernel.org/hid/hid/c/6f20d3261265

Cheers,
diff mbox series

Patch

diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
index 62180414efcc..e6a8b6d8eab7 100644
--- a/drivers/hid/hid-logitech-dj.c
+++ b/drivers/hid/hid-logitech-dj.c
@@ -1285,6 +1285,9 @@  static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
 		 * 50 msec should gives enough time to the receiver to be ready.
 		 */
 		msleep(50);
+
+		if (retval)
+			return retval;
 	}
 
 	/*
@@ -1306,7 +1309,7 @@  static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
 	buf[5] = 0x09;
 	buf[6] = 0x00;
 
-	hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf,
+	retval = hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf,
 			HIDPP_REPORT_SHORT_LENGTH, HID_OUTPUT_REPORT,
 			HID_REQ_SET_REPORT);