Skip to content

Commit cd667ce

Browse files
author
Jiri Kosina
committed
HID: use debugfs for events/reports dumping
This is a followup patch to the one implemeting rdesc representation in debugfs rather than being dependent on compile-time CONFIG_HID_DEBUG setting. The API of the appropriate formatting functions is slightly modified -- if they are passed seq_file pointer, the one-shot output for 'rdesc' file mode is used, and therefore the message is formatted into the corresponding seq_file immediately. Otherwise the called function allocated a new buffer, formats the text into the buffer and returns the pointer to it, so that it can be queued into the ring-buffer of the processess blocked waiting on input on 'events' file in debugfs. 'debug' parameter to the 'hid' module is now used solely for the prupose of inetrnal driver state debugging (parser, transport, etc). Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent a635f9d commit cd667ce

File tree

4 files changed

+276
-49
lines changed

4 files changed

+276
-49
lines changed

drivers/hid/hid-core.c

+32-10
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
int hid_debug = 0;
4848
module_param_named(debug, hid_debug, int, 0600);
49-
MODULE_PARM_DESC(debug, "HID debugging (0=off, 1=probing info, 2=continuous data dumping)");
49+
MODULE_PARM_DESC(debug, "toggle HID debugging messages");
5050
EXPORT_SYMBOL_GPL(hid_debug);
5151

5252
/*
@@ -859,7 +859,7 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field,
859859
struct hid_driver *hdrv = hid->driver;
860860
int ret;
861861

862-
hid_dump_input(usage, value);
862+
hid_dump_input(hid, usage, value);
863863

864864
if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
865865
ret = hdrv->event(hid, field, usage, value);
@@ -981,7 +981,7 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
981981
{
982982
unsigned size = field->report_size;
983983

984-
hid_dump_input(field->usage + offset, value);
984+
hid_dump_input(field->report->device, field->usage + offset, value);
985985

986986
if (offset >= field->report_count) {
987987
dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
@@ -1075,6 +1075,7 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
10751075
struct hid_report_enum *report_enum = hid->report_enum + type;
10761076
struct hid_driver *hdrv = hid->driver;
10771077
struct hid_report *report;
1078+
char *buf;
10781079
unsigned int i;
10791080
int ret;
10801081

@@ -1086,18 +1087,36 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
10861087
return -1;
10871088
}
10881089

1089-
dbg_hid("report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un");
1090+
buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE,
1091+
interrupt ? GFP_ATOMIC : GFP_KERNEL);
1092+
1093+
if (!buf) {
1094+
report = hid_get_report(report_enum, data);
1095+
goto nomem;
1096+
}
1097+
1098+
snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1099+
"\nreport (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un");
1100+
hid_debug_event(hid, buf);
10901101

10911102
report = hid_get_report(report_enum, data);
10921103
if (!report)
10931104
return -1;
10941105

10951106
/* dump the report */
1096-
dbg_hid("report %d (size %u) = ", report->id, size);
1097-
for (i = 0; i < size; i++)
1098-
dbg_hid_line(" %02x", data[i]);
1099-
dbg_hid_line("\n");
1107+
snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1108+
"report %d (size %u) = ", report->id, size);
1109+
hid_debug_event(hid, buf);
1110+
for (i = 0; i < size; i++) {
1111+
snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1112+
" %02x", data[i]);
1113+
hid_debug_event(hid, buf);
1114+
}
1115+
hid_debug_event(hid, "\n");
1116+
1117+
kfree(buf);
11001118

1119+
nomem:
11011120
if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
11021121
ret = hdrv->raw_event(hid, report, data, size);
11031122
if (ret != 0)
@@ -1756,6 +1775,9 @@ struct hid_device *hid_allocate_device(void)
17561775
for (i = 0; i < HID_REPORT_TYPES; i++)
17571776
INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
17581777

1778+
init_waitqueue_head(&hdev->debug_wait);
1779+
INIT_LIST_HEAD(&hdev->debug_list);
1780+
17591781
return hdev;
17601782
err:
17611783
put_device(&hdev->dev);
@@ -1844,8 +1866,8 @@ static int __init hid_init(void)
18441866
int ret;
18451867

18461868
if (hid_debug)
1847-
printk(KERN_WARNING "HID: hid_debug parameter has been deprecated. "
1848-
"Debugging data are now provided via debugfs\n");
1869+
printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n"
1870+
"HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
18491871

18501872
ret = bus_register(&hid_bus_type);
18511873
if (ret) {

0 commit comments

Comments
 (0)