提交 826d5982 编写于 作者: D Dmitry Torokhov

Input: hiddev - use standard list implementation

Fixes Coverity #id 303
Signed-off-by: NDmitry Torokhov <dtor@mail.ru>
上级 b6d786db
...@@ -49,7 +49,7 @@ struct hiddev { ...@@ -49,7 +49,7 @@ struct hiddev {
int open; int open;
wait_queue_head_t wait; wait_queue_head_t wait;
struct hid_device *hid; struct hid_device *hid;
struct hiddev_list *list; struct list_head list;
}; };
struct hiddev_list { struct hiddev_list {
...@@ -59,7 +59,7 @@ struct hiddev_list { ...@@ -59,7 +59,7 @@ struct hiddev_list {
unsigned flags; unsigned flags;
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct hiddev *hiddev; struct hiddev *hiddev;
struct hiddev_list *next; struct list_head node;
}; };
static struct hiddev *hiddev_table[HIDDEV_MINORS]; static struct hiddev *hiddev_table[HIDDEV_MINORS];
...@@ -73,12 +73,15 @@ static struct hiddev *hiddev_table[HIDDEV_MINORS]; ...@@ -73,12 +73,15 @@ static struct hiddev *hiddev_table[HIDDEV_MINORS];
static struct hid_report * static struct hid_report *
hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo) hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
{ {
unsigned flags = rinfo->report_id & ~HID_REPORT_ID_MASK; unsigned int flags = rinfo->report_id & ~HID_REPORT_ID_MASK;
unsigned int rid = rinfo->report_id & HID_REPORT_ID_MASK;
struct hid_report_enum *report_enum; struct hid_report_enum *report_enum;
struct hid_report *report;
struct list_head *list; struct list_head *list;
if (rinfo->report_type < HID_REPORT_TYPE_MIN || if (rinfo->report_type < HID_REPORT_TYPE_MIN ||
rinfo->report_type > HID_REPORT_TYPE_MAX) return NULL; rinfo->report_type > HID_REPORT_TYPE_MAX)
return NULL;
report_enum = hid->report_enum + report_enum = hid->report_enum +
(rinfo->report_type - HID_REPORT_TYPE_MIN); (rinfo->report_type - HID_REPORT_TYPE_MIN);
...@@ -88,21 +91,25 @@ hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo) ...@@ -88,21 +91,25 @@ hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
break; break;
case HID_REPORT_ID_FIRST: case HID_REPORT_ID_FIRST:
list = report_enum->report_list.next; if (list_empty(&report_enum->report_list))
if (list == &report_enum->report_list)
return NULL; return NULL;
rinfo->report_id = ((struct hid_report *) list)->id;
list = report_enum->report_list.next;
report = list_entry(list, struct hid_report, list);
rinfo->report_id = report->id;
break; break;
case HID_REPORT_ID_NEXT: case HID_REPORT_ID_NEXT:
list = (struct list_head *) report = report_enum->report_id_hash[rid];
report_enum->report_id_hash[rinfo->report_id & HID_REPORT_ID_MASK]; if (!report)
if (list == NULL)
return NULL; return NULL;
list = list->next;
list = report->list.next;
if (list == &report_enum->report_list) if (list == &report_enum->report_list)
return NULL; return NULL;
rinfo->report_id = ((struct hid_report *) list)->id;
report = list_entry(list, struct hid_report, list);
rinfo->report_id = report->id;
break; break;
default: default:
...@@ -125,12 +132,13 @@ hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref) ...@@ -125,12 +132,13 @@ hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref)
struct hid_field *field; struct hid_field *field;
if (uref->report_type < HID_REPORT_TYPE_MIN || if (uref->report_type < HID_REPORT_TYPE_MIN ||
uref->report_type > HID_REPORT_TYPE_MAX) return NULL; uref->report_type > HID_REPORT_TYPE_MAX)
return NULL;
report_enum = hid->report_enum + report_enum = hid->report_enum +
(uref->report_type - HID_REPORT_TYPE_MIN); (uref->report_type - HID_REPORT_TYPE_MIN);
list_for_each_entry(report, &report_enum->report_list, list) list_for_each_entry(report, &report_enum->report_list, list) {
for (i = 0; i < report->maxfield; i++) { for (i = 0; i < report->maxfield; i++) {
field = report->field[i]; field = report->field[i];
for (j = 0; j < field->maxusage; j++) { for (j = 0; j < field->maxusage; j++) {
...@@ -142,6 +150,7 @@ hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref) ...@@ -142,6 +150,7 @@ hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref)
} }
} }
} }
}
return NULL; return NULL;
} }
...@@ -150,9 +159,9 @@ static void hiddev_send_event(struct hid_device *hid, ...@@ -150,9 +159,9 @@ static void hiddev_send_event(struct hid_device *hid,
struct hiddev_usage_ref *uref) struct hiddev_usage_ref *uref)
{ {
struct hiddev *hiddev = hid->hiddev; struct hiddev *hiddev = hid->hiddev;
struct hiddev_list *list = hiddev->list; struct hiddev_list *list;
while (list) { list_for_each_entry(list, &hiddev->list, node) {
if (uref->field_index != HID_FIELD_INDEX_NONE || if (uref->field_index != HID_FIELD_INDEX_NONE ||
(list->flags & HIDDEV_FLAG_REPORT) != 0) { (list->flags & HIDDEV_FLAG_REPORT) != 0) {
list->buffer[list->head] = *uref; list->buffer[list->head] = *uref;
...@@ -160,8 +169,6 @@ static void hiddev_send_event(struct hid_device *hid, ...@@ -160,8 +169,6 @@ static void hiddev_send_event(struct hid_device *hid,
(HIDDEV_BUFFER_SIZE - 1); (HIDDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&list->fasync, SIGIO, POLL_IN);
} }
list = list->next;
} }
wake_up_interruptible(&hiddev->wait); wake_up_interruptible(&hiddev->wait);
...@@ -180,7 +187,7 @@ void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, ...@@ -180,7 +187,7 @@ void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
uref.report_type = uref.report_type =
(type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0));
uref.report_id = field->report->id; uref.report_id = field->report->id;
uref.field_index = field->index; uref.field_index = field->index;
uref.usage_index = (usage - field->usage); uref.usage_index = (usage - field->usage);
...@@ -200,7 +207,7 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report) ...@@ -200,7 +207,7 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
uref.report_type = uref.report_type =
(type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0));
uref.report_id = report->id; uref.report_id = report->id;
uref.field_index = HID_FIELD_INDEX_NONE; uref.field_index = HID_FIELD_INDEX_NONE;
...@@ -213,7 +220,9 @@ static int hiddev_fasync(int fd, struct file *file, int on) ...@@ -213,7 +220,9 @@ static int hiddev_fasync(int fd, struct file *file, int on)
{ {
int retval; int retval;
struct hiddev_list *list = file->private_data; struct hiddev_list *list = file->private_data;
retval = fasync_helper(fd, file, on, &list->fasync); retval = fasync_helper(fd, file, on, &list->fasync);
return retval < 0 ? retval : 0; return retval < 0 ? retval : 0;
} }
...@@ -224,14 +233,9 @@ static int hiddev_fasync(int fd, struct file *file, int on) ...@@ -224,14 +233,9 @@ static int hiddev_fasync(int fd, struct file *file, int on)
static int hiddev_release(struct inode * inode, struct file * file) static int hiddev_release(struct inode * inode, struct file * file)
{ {
struct hiddev_list *list = file->private_data; struct hiddev_list *list = file->private_data;
struct hiddev_list **listptr;
listptr = &list->hiddev->list;
hiddev_fasync(-1, file, 0); hiddev_fasync(-1, file, 0);
list_del(&list->node);
while (*listptr && (*listptr != list))
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
if (!--list->hiddev->open) { if (!--list->hiddev->open) {
if (list->hiddev->exist) if (list->hiddev->exist)
...@@ -248,7 +252,8 @@ static int hiddev_release(struct inode * inode, struct file * file) ...@@ -248,7 +252,8 @@ static int hiddev_release(struct inode * inode, struct file * file)
/* /*
* open file op * open file op
*/ */
static int hiddev_open(struct inode * inode, struct file * file) { static int hiddev_open(struct inode *inode, struct file *file)
{
struct hiddev_list *list; struct hiddev_list *list;
int i = iminor(inode) - HIDDEV_MINOR_BASE; int i = iminor(inode) - HIDDEV_MINOR_BASE;
...@@ -260,9 +265,7 @@ static int hiddev_open(struct inode * inode, struct file * file) { ...@@ -260,9 +265,7 @@ static int hiddev_open(struct inode * inode, struct file * file) {
return -ENOMEM; return -ENOMEM;
list->hiddev = hiddev_table[i]; list->hiddev = hiddev_table[i];
list->next = hiddev_table[i]->list; list_add_tail(&list->node, &hiddev_table[i]->list);
hiddev_table[i]->list = list;
file->private_data = list; file->private_data = list;
if (!list->hiddev->open++) if (!list->hiddev->open++)
...@@ -362,6 +365,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun ...@@ -362,6 +365,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
static unsigned int hiddev_poll(struct file *file, poll_table *wait) static unsigned int hiddev_poll(struct file *file, poll_table *wait)
{ {
struct hiddev_list *list = file->private_data; struct hiddev_list *list = file->private_data;
poll_wait(file, &list->hiddev->wait, wait); poll_wait(file, &list->hiddev->wait, wait);
if (list->head != list->tail) if (list->head != list->tail)
return POLLIN | POLLRDNORM; return POLLIN | POLLRDNORM;
...@@ -382,7 +386,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd ...@@ -382,7 +386,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
struct hiddev_collection_info cinfo; struct hiddev_collection_info cinfo;
struct hiddev_report_info rinfo; struct hiddev_report_info rinfo;
struct hiddev_field_info finfo; struct hiddev_field_info finfo;
struct hiddev_usage_ref_multi *uref_multi=NULL; struct hiddev_usage_ref_multi *uref_multi = NULL;
struct hiddev_usage_ref *uref; struct hiddev_usage_ref *uref;
struct hiddev_devinfo dinfo; struct hiddev_devinfo dinfo;
struct hid_report *report; struct hid_report *report;
...@@ -764,15 +768,15 @@ int hiddev_connect(struct hid_device *hid) ...@@ -764,15 +768,15 @@ int hiddev_connect(struct hid_device *hid)
} }
init_waitqueue_head(&hiddev->wait); init_waitqueue_head(&hiddev->wait);
INIT_LIST_HEAD(&hiddev->list);
hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
hiddev->hid = hid; hiddev->hid = hid;
hiddev->exist = 1; hiddev->exist = 1;
hid->minor = hid->intf->minor; hid->minor = hid->intf->minor;
hid->hiddev = hiddev; hid->hiddev = hiddev;
hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册