Skip to contentSkip to conversation

Bluetooth: hidp: Fix error checks in hidp_get/set_raw_report

PATCH In review Dan Elkouby 5 participants 13 messages Sep 6, 2019 – Sep 23, 2019

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

PATCH 1/1 Bluetooth: hidp: Fix error checks in hidp_get/set_raw_report

Commit 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes") changed hidp_send_message to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some (all?) drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

---
 net/bluetooth/hidp/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/hidp/core.c +2 -2
index 8d889969ae7e..bef84b95e2c4 100644
@@ -267,7 +267,7 @@ static int hidp_get_raw_report(struct hid_device *hid,
 	set_bit(HIDP_WAITING_FOR_RETURN, &session->flags);
 	data[0] = report_number;
 	ret = hidp_send_ctrl_message(session, report_type, data, 1);
-	if (ret)
+	if (ret < 0)
 		goto err;
 
 	/* Wait for the return of the report. The returned report
@@ -343,7 +343,7 @@ static int hidp_set_raw_report(struct hid_device *hid, unsigned char reportnum,
 	data[0] = reportnum;
 	set_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags);
 	ret = hidp_send_ctrl_message(session, report_type, data, count);
-	if (ret)
+	if (ret < 0)
 		goto err;
 
 	/* Wait for the ACK from the device. */
Signature · 1 line
2.23.0
#1 lore raw
Quoted 7 lines · Dan Elkouby

Commit 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes") changed hidp_send_message to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some (all?) drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

I think we also need to update update ms_ff_worker() which assumes that hid_hw_output_report() returns zero on success. Please use the Fixes tag for this since a lot of scripts rely on it to decide what to backport.

Fixes 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes")

Otherwise, it looks good. Thanks for catching this.

regards,
dan carpenter

#2 lore raw
Quoted 2 lines · Dan Carpenter

I think we also need to update update ms_ff_worker() which assumes that hid_hw_output_report() returns zero on success.

Yes, it looks like that's the case. Should I amend my patch to include this fix, or should it be a separate patch? I don't have access to any hardware covered by hid-microsoft, so I won't be able to test it.

Quoted 5 lines

Please use the Fixes
tag for this since a lot of scripts rely on it to decide what to backport.

Fixes 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes")

Will do.

Quoted 1 line

Otherwise, it looks good. Thanks for catching this.

Thanks for taking a look!

(Sorry for sending this twice, I'm not used to mailing lists and forgot to reply to all.)

#3 lore raw
Quoted 8 lines · Dan Elkouby
Quoted 2 lines · Dan Carpenter

I think we also need to update update ms_ff_worker() which assumes that hid_hw_output_report() returns zero on success.

Yes, it looks like that's the case. Should I amend my patch to include this fix, or should it be a separate patch? I don't have access to any hardware covered by hid-microsoft, so I won't be able to test it.

Yes. Please amend the patch. We all understand that you don't have the hardware so it's not a problem. If you want to blame me in the commit message that's fine. "Dan Carpenter pointed out a related issue in ms_ff_worker()". But we're only silencing a warning so it can't really break anything.

You can add my Reviewed-by tag as well when you resend.

regards,
dan carpenter

#4 lore raw

PATCH 1/1 Bluetooth: hidp: Fix assumptions on the return value of hidp_send_message

In reply to Dan Carpenter

hidp_send_message was changed to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

As pointed out by Dan Carpenter, hid-microsoft directly relied on that assumption as well.

Fixes 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes")
---
 drivers/hid/hid-microsoft.c | 2 +-
 net/bluetooth/hidp/core.c   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-microsoft.c +1 -1
index 8b3a922bdad3..2cf83856f2e4 100644
@@ -303,7 +303,7 @@ static void ms_ff_worker(struct work_struct *work)
 	r->magnitude[MAGNITUDE_WEAK] = ms->weak;     /* right actuator */
 
 	ret = hid_hw_output_report(hdev, (__u8 *)r, sizeof(*r));
-	if (ret)
+	if (ret < 0)
 		hid_warn(hdev, "failed to send FF report\n");
 }
 
net/bluetooth/hidp/core.c +2 -2
index 8d889969ae7e..bef84b95e2c4 100644
@@ -267,7 +267,7 @@ static int hidp_get_raw_report(struct hid_device *hid,
 	set_bit(HIDP_WAITING_FOR_RETURN, &session->flags);
 	data[0] = report_number;
 	ret = hidp_send_ctrl_message(session, report_type, data, 1);
-	if (ret)
+	if (ret < 0)
 		goto err;
 
 	/* Wait for the return of the report. The returned report
@@ -343,7 +343,7 @@ static int hidp_set_raw_report(struct hid_device *hid, unsigned char reportnum,
 	data[0] = reportnum;
 	set_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags);
 	ret = hidp_send_ctrl_message(session, report_type, data, count);
-	if (ret)
+	if (ret < 0)
 		goto err;
 
 	/* Wait for the ACK from the device. */
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#5 lore raw

Re: [PATCH] Bluetooth: hidp: Fix assumptions on the return value of hidp_send_message

Quoted 11 lines · Dan Elkouby

hidp_send_message was changed to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

As pointed out by Dan Carpenter, hid-microsoft directly relied on that assumption as well.

Fixes 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes")

Thanks!

regards,
dan carpenter

maintainer Reviewed-by on v1 1/1
#6 lore raw

Re: [PATCH] Bluetooth: hidp: Fix assumptions on the return value of hidp_send_message

In reply to Dan Elkouby
Quoted 11 lines · Dan Elkouby

hidp_send_message was changed to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

As pointed out by Dan Carpenter, hid-microsoft directly relied on that assumption as well.

Fixes 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes")

Marcel, are you taking this through your tree?

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
maintainer
#7 lore raw

Re: [PATCH] Bluetooth: hidp: Fix assumptions on the return value of hidp_send_message

Hi Jiri,

Quoted 8 lines
Quoted 8 lines

hidp_send_message was changed to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

As pointed out by Dan Carpenter, hid-microsoft directly relied on that assumption as well.

Quoted 7 lines
Quoted 3 lines
Fixes 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes")

Marcel, are you taking this through your tree?

I am taking this through my tree. And yes, I applied the updated patch, but answered the other ;)

Regards

Marcel

#8 lore raw

Re: [PATCH] Bluetooth: hidp: Fix assumptions on the return value of hidp_send_message

Quoted 5 lines

I am taking this through my tree. And yes, I applied the updated patch, but answered the other ;)

Regards

Marcel

Are you also going to mark this patch for inclusion to stable tree? I haven't seen it in any of the stable queues (netdev, Greg's), so just wanted to check.

Thanks,
Andrey Smirnov

maintainer
#9 lore raw
In reply to Dan Elkouby

Hi Dan,

Quoted 10 lines

Commit 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes") changed hidp_send_message to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some (all?) drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

---
net/bluetooth/hidp/core.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#10 lore raw
Quoted 2 lines · Marcel Holtmann

patch has been applied to bluetooth-next tree.

Thanks a lot!

#11 lore raw
In reply to Marcel Holtmann
Quoted 8 lines · Marcel Holtmann

Hi Dan,

Quoted 6 lines

Commit 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes") changed hidp_send_message to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some (all?) drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

Quoted 7 lines
Quoted 4 lines

---
net/bluetooth/hidp/core.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)

patch has been applied to bluetooth-next tree.

The v2 added an additional fix and used the Fixes tag. Could you apply that instead?

regards,
dan carpenter

maintainer
#12 lore raw

Hi Dan,

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Commit 48d9cc9d85dd ("Bluetooth: hidp: Let hidp_send_message return number of queued bytes") changed hidp_send_message to return non-zero values on success, which some other bits did not expect. This caused spurious errors to be propagated through the stack, breaking some (all?) drivers, such as hid-sony for the Dualshock 4 in Bluetooth mode.

---
net/bluetooth/hidp/core.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 2 lines

patch has been applied to bluetooth-next tree.

The v2 added an additional fix and used the Fixes tag. Could you apply that instead?

see my reply to Jiri. I replied to the wrong patch, but actually applied to the updated one.

Regards

Marcel