[PATCH 2/3] hog: Improve report_value_cb() uHID error handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use similar uHID error handling and debug messages as uhid_send_input_report()
in profiles/input/device.c.
---
 profiles/input/hog.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index 9f10fa4..a6ffe79 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -112,6 +112,7 @@ static void report_value_cb(const guint8 *pdu, guint16 len, gpointer user_data)
 	struct uhid_event ev;
 	uint16_t report_size = len - 3;
 	uint8_t *buf;
+	ssize_t status;
 
 	if (len < 3) { /* 1-byte opcode + 2-byte handle */
 		error("Malformed ATT notification");
@@ -131,11 +132,21 @@ static void report_value_cb(const guint8 *pdu, guint16 len, gpointer user_data)
 
 	memcpy(buf, &pdu[3], MIN(report_size, UHID_DATA_MAX));
 
-	if (write(hogdev->uhid_fd, &ev, sizeof(ev)) < 0)
-		error("uHID write failed: %s", strerror(errno));
-	else
-		DBG("Report from HoG device 0x%04X written to uHID fd %d",
-						hogdev->id, hogdev->uhid_fd);
+	status = write(hogdev->uhid_fd, &ev, sizeof(ev));
+	if (status < 0) {
+		error("uHID dev write error: %s (%d)", strerror(errno), errno);
+		return;
+	}
+
+	/* uHID kernel driver does not handle partial writes */
+	if ((size_t) status < sizeof(ev)) {
+		error("uHID dev write error: partial write (%zd of %lu bytes)",
+							status, sizeof(ev));
+		return;
+	}
+
+	DBG("HoG report (%u bytes) -> uHID fd %d", ev.u.input.size,
+							hogdev->uhid_fd);
 }
 
 static void report_ccc_written_cb(guint8 status, const guint8 *pdu,
-- 
1.9.1.423.g4596e3a

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux