lkml.org 
[lkml]   [2010]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] hid: avoid '\0' in hid debugfs events file
When dumping /sys/kernel/debug/hid/$device/events '\0' characters show up
(invisible if cat to console but shown by less or while looking at a dump
file).
These are due to hid_debug_event() adding strlen()+1 bytes to the ring
buffer (e.g. including the trailing '\0').
Any roll-over causes a '\0' as well as hid_debug_event() handles the ring
buffers with HID_DEBUG_BUFSIZE-1 size while hid_debug_events_read() handles
it with full HID_DEBUG_BUFSIZE size.

Signed-off-by: Bruno Prémont <bonbons@linux-vserver.org>
---
Note:
The ring buffer overflow case (when tail crosses head) seems to be
suboptimal at best.
Would there be a good way to mark those cases so reader can know where
data got lost. (though this might not be easy keeping the lockless
design)

diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 6abd036..2602695 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -564,10 +564,10 @@ void hid_debug_event(struct hid_device *hdev, char *buf)
struct hid_debug_list *list;

list_for_each_entry(list, &hdev->debug_list, node) {
- for (i = 0; i <= strlen(buf); i++)
- list->hid_debug_buf[(list->tail + i) % (HID_DEBUG_BUFSIZE - 1)] =
+ for (i = 0; i < strlen(buf); i++)
+ list->hid_debug_buf[(list->tail + i) % HID_DEBUG_BUFSIZE] =
buf[i];
- list->tail = (list->tail + i) % (HID_DEBUG_BUFSIZE - 1);
+ list->tail = (list->tail + i) % HID_DEBUG_BUFSIZE;
}
}
EXPORT_SYMBOL_GPL(hid_debug_event);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2010-03-15 19:03    [W:0.035 / U:26.832 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site