Skip to contentSkip to conversation

HID: logitech-hidpp: Add more debug statements

PATCH Applied Bastien Nocera 2 participants 9 messages Feb 6, 2023 – Feb 9, 2023

Subsystems (3)
lore
Share & tools
lore

Bastien Nocera

author reviewer
#0 lore raw

PATCH v2 1/3 HID: logitech-hidpp: Add more debug statements

This should help us figure out some hairy problems with some devices.

---

Fixed kernel test bot warning:
drivers/hid/hid-logitech-hidpp.c: In function 'hidpp_send_fap_command_sync':

Quoted 1 line
Quoted 1 line

drivers/hid/hid-logitech-hidpp.c:343:25: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'unsigned int' [-Wformat=]

     343 |                         "Invalid number of parameters passed to command (%d != %ld)\n",
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 drivers/hid/hid-logitech-hidpp.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/hid/hid-logitech-hidpp.c +14 -3
index f44ba7be3cc5..1952d8d3b6b2 100644
@@ -338,8 +338,13 @@ static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
 	struct hidpp_report *message;
 	int ret;
 
-	if (param_count > sizeof(message->fap.params))
+	if (param_count > sizeof(message->fap.params)) {
+		hid_dbg(hidpp->hid_dev,
+			"Invalid number of parameters passed to command (%d != %llu)\n",
+			param_count,
+			(unsigned long long) sizeof(message->fap.params));
 		return -EINVAL;
+	}
 
 	message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
 	if (!message)
@@ -3440,11 +3445,17 @@ static int hi_res_scroll_enable(struct hidpp_device *hidpp)
 		ret = hidpp10_enable_scrolling_acceleration(hidpp);
 		multiplier = 8;
 	}
-	if (ret)
+	if (ret) {
+		hid_dbg(hidpp->hid_dev,
+			"Could not enable hi-res scrolling: %d\n", ret);
 		return ret;
+	}
 
-	if (multiplier == 0)
+	if (multiplier == 0) {
+		hid_dbg(hidpp->hid_dev,
+			"Invalid multiplier 0 from device, setting it to 1\n");
 		multiplier = 1;
+	}
 
 	hidpp->vertical_wheel_counter.wheel_multiplier = multiplier;
 	hid_dbg(hidpp->hid_dev, "wheel multiplier = %d\n", multiplier);
Signature · 1 line
2.39.1
author reviewer
#1 lore raw

PATCH v2 2/3 HID: logitech-hidpp: Retry commands when device is busy

Handle the busy error coming from the device or receiver. The documentation says a busy error can be returned when:
"
Device (or receiver) cannot answer immediately to this request for any reason i.e:
- already processing a request from the same or another SW
- pipe full
"

---

Same as v1

 drivers/hid/hid-logitech-hidpp.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/hid/hid-logitech-hidpp.c +5 -0
index 1952d8d3b6b2..9e94026de437 100644
@@ -295,6 +295,7 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
 	 */
 	*response = *message;
 
+retry:
 	ret = __hidpp_send_report(hidpp->hid_dev, message);
 
 	if (ret) {
@@ -321,6 +322,10 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
 			response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
 			response->fap.feature_index == HIDPP20_ERROR) {
 		ret = response->fap.params[1];
+		if (ret == HIDPP20_ERROR_BUSY) {
+			dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret);
+			goto retry;
+		}
 		dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
 		goto exit;
 	}
Signature · 1 line
2.39.1
#2 lore raw

Re: [PATCH v2 2/3] HID: logitech-hidpp: Retry commands when device is busy

Quoted 30 lines · Bastien Nocera

Handle the busy error coming from the device or receiver. The documentation says a busy error can be returned when:
"
Device (or receiver) cannot answer immediately to this request for any reason i.e:
- already processing a request from the same or another SW
- pipe full
"

---

Same as v1

 drivers/hid/hid-logitech-hidpp.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/hid/hid-logitech-hidpp.c +1 -0
index 1952d8d3b6b2..9e94026de437 100644
@@ -295,6 +295,7 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
 	 */
 	*response = *message;
 
+retry:
 	ret = __hidpp_send_report(hidpp->hid_dev, message);
 
 	if (ret) {

drivers/hid/hid-logitech-hidpp.c static int hidpp_send_message_sync(struct hidpp_device *hidpp, · line 327

Quoted 6 lines
drivers/hid/hid-logitech-hidpp.c +3 -0
@@ -321,6 +322,10 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
 			response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
 			response->fap.feature_index == HIDPP20_ERROR) {
 		ret = response->fap.params[1];
+		if (ret == HIDPP20_ERROR_BUSY) {
+			dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret);
+			goto retry;

I must confess, I blocked a little bit there to decide whether or not using goto here was OK.

But then I reliazed that there is no way to leave that function if the device is buggy and constantly sends back ERROR_BUSY. So I am not very found of the idea of having that got after all.

Would you mind respinning that patch with a bounded loop for the retries instead of using a goto? I'd like the driver to give up after a few retries if the device is not fair.

Cheers,
Benjamin

Quoted 7 lines
drivers/hid/hid-logitech-hidpp.c +1 -0
+		}
 		dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
 		goto exit;
 	}
Signature · 1 line
2.39.1
author reviewer
#3 lore raw

Re: [PATCH v2 2/3] HID: logitech-hidpp: Retry commands when device is busy

Quoted 53 lines · Benjamin Tissoires
Quoted 34 lines · Bastien Nocera

Handle the busy error coming from the device or receiver. The documentation says a busy error can be returned when:
"
Device (or receiver) cannot answer immediately to this request for any reason i.e:
- already processing a request from the same or another SW
- pipe full
"

---

Same as v1

 drivers/hid/hid-logitech-hidpp.c | 5 +++++

 1 file changed, 5 insertions(+)
drivers/hid/hid- renamed from drivers/hid/hid-logitech-hidpp.c +0 -0

logitech-hidpp.c
index 1952d8d3b6b2..9e94026de437 100644

drivers/hid/hid-logitech-hidpp.c +0 -0
@@ -295,6 +295,7 @@ static int hidpp_send_message_sync(struct
 hidpp_device *hidpp,
          */
         *response = *message;


+retry:
        ret = __hidpp_send_report(hidpp->hid_dev, message);
        if (ret) {

drivers/hid/hid-logitech-hidpp.c +0 -0
@@ -321,6 +322,10 @@ static int hidpp_send_message_sync(struct
 hidpp_device *hidpp,

                        response->report_id ==

Quoted 8 lines

REPORT_ID_HIDPP_VERY_LONG) && response->fap.feature_index == HIDPP20_ERROR) {
                ret = response->fap.params[1];
+               if (ret == HIDPP20_ERROR_BUSY) {
+                       dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret);
+                       goto retry;

I must confess, I blocked a little bit there to decide whether or not using goto here was OK.

But then I reliazed that there is no way to leave that function if the
device is buggy and constantly sends back ERROR_BUSY. So I am not very
found of the idea of having that got after all.

Quoted 4 lines

Would you mind respinning that patch with a bounded loop for the retries
instead of using a goto? I'd like the driver to give up after a few retries if the device is not fair.

Done in v3.

author reviewer
#4 lore raw

PATCH v2 3/3 HID: logitech-hidpp: Add myself to authors

In reply to Bastien Nocera

---

Same as v1

 drivers/hid/hid-logitech-hidpp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/hid-logitech-hidpp.c +1 -0
index 9e94026de437..03b77ca03081 100644
@@ -30,6 +30,7 @@
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Benjamin Tissoires <[email protected]>");
 MODULE_AUTHOR("Nestor Lopez Casado <[email protected]>");
+MODULE_AUTHOR("Bastien Nocera <[email protected]>");
 
 static bool disable_tap_to_click;
 module_param(disable_tap_to_click, bool, 0644);
Signature · 1 line
2.39.1
#5 lore raw

Re: [PATCH v2 3/3] HID: logitech-hidpp: Add myself to authors

Quoted 13 lines · Bastien Nocera

---

Same as v1

 drivers/hid/hid-logitech-hidpp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/hid-logitech-hidpp.c +0 -0
index 9e94026de437..03b77ca03081 100644

drivers/hid/hid-logitech-hidpp.c line 33

Quoted 4 lines
drivers/hid/hid-logitech-hidpp.c +1 -0
@@ -30,6 +30,7 @@
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Benjamin Tissoires <[email protected]>");
 MODULE_AUTHOR("Nestor Lopez Casado <[email protected]>");
+MODULE_AUTHOR("Bastien Nocera <[email protected]>");

Just FTR, I have asked Bastien to set himself as an author given all of the work he has been doing on this and to have one more person to be the go-to person from folks having an issue.

And Bastien, would you mind adding yourself to the MAINTAINERS file too? This way you'll get Cc-ed when people submit patches.

Cheers,
Benjamin

Quoted 6 lines
drivers/hid/hid-logitech-hidpp.c +0 -0
 static bool disable_tap_to_click;
 module_param(disable_tap_to_click, bool, 0644);
Signature · 1 line
2.39.1
author reviewer
#6 lore raw

Re: [PATCH v2 3/3] HID: logitech-hidpp: Add myself to authors

Quoted 27 lines · Benjamin Tissoires
Quoted 15 lines · Bastien Nocera

---

Same as v1

 drivers/hid/hid-logitech-hidpp.c | 1 +

 1 file changed, 1 insertion(+)
drivers/hid/hid- renamed from drivers/hid/hid-logitech-hidpp.c +0 -0

logitech-hidpp.c
index 9e94026de437..03b77ca03081 100644

drivers/hid/hid-logitech-hidpp.c +0 -0
@@ -30,6 +30,7 @@
  MODULE_LICENSE("GPL");
Quoted 4 lines

 MODULE_AUTHOR("Benjamin Tissoires <[email protected]>");
 MODULE_AUTHOR("Nestor Lopez Casado <[email protected]>"); +MODULE_AUTHOR("Bastien Nocera <[email protected]>");

Just FTR, I have asked Bastien to set himself as an author given all of
the work he has been doing on this and to have one more person to be the
go-to person from folks having an issue.

Quoted 3 lines

And Bastien, would you mind adding yourself to the MAINTAINERS file too?
This way you'll get Cc-ed when people submit patches.

Done in v3 specifically for the hidpp file.

#7 lore raw
In reply to Bastien Nocera
Quoted 3 lines · Bastien Nocera

This should help us figure out some hairy problems with some devices.

FWIW, I am currently testing this patch and will probably push it today.

Cheers,
Benjamin

Quoted 53 lines

---

Fixed kernel test bot warning:
drivers/hid/hid-logitech-hidpp.c: In function 'hidpp_send_fap_command_sync':

Quoted 1 line
Quoted 1 line

drivers/hid/hid-logitech-hidpp.c:343:25: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'unsigned int' [-Wformat=]

     343 |                         "Invalid number of parameters passed to command (%d != %ld)\n",
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 drivers/hid/hid-logitech-hidpp.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/hid/hid-logitech-hidpp.c +14 -3
index f44ba7be3cc5..1952d8d3b6b2 100644
@@ -338,8 +338,13 @@ static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
 	struct hidpp_report *message;
 	int ret;
 
-	if (param_count > sizeof(message->fap.params))
+	if (param_count > sizeof(message->fap.params)) {
+		hid_dbg(hidpp->hid_dev,
+			"Invalid number of parameters passed to command (%d != %llu)\n",
+			param_count,
+			(unsigned long long) sizeof(message->fap.params));
 		return -EINVAL;
+	}
 
 	message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
 	if (!message)
@@ -3440,11 +3445,17 @@ static int hi_res_scroll_enable(struct hidpp_device *hidpp)
 		ret = hidpp10_enable_scrolling_acceleration(hidpp);
 		multiplier = 8;
 	}
-	if (ret)
+	if (ret) {
+		hid_dbg(hidpp->hid_dev,
+			"Could not enable hi-res scrolling: %d\n", ret);
 		return ret;
+	}
 
-	if (multiplier == 0)
+	if (multiplier == 0) {
+		hid_dbg(hidpp->hid_dev,
+			"Invalid multiplier 0 from device, setting it to 1\n");
 		multiplier = 1;
+	}
 
 	hidpp->vertical_wheel_counter.wheel_multiplier = multiplier;
 	hid_dbg(hidpp->hid_dev, "wheel multiplier = %d\n", multiplier);
Signature · 1 line
2.39.1