2 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
4 * This source file is released under GPL v2 license (no other versions).
5 * See the COPYING file included in the main directory of this source
6 * distribution for the license terms and conditions.
11 * This file contains the implementation of generic input mapper operations
12 * for input mapper management.
20 #include <linux/slab.h>
22 int input_mapper_add(struct list_head
*mappers
, struct imapper
*entry
,
23 int (*map_op
)(void *, struct imapper
*), void *data
)
25 struct list_head
*pos
, *pre
, *head
;
26 struct imapper
*pre_ent
, *pos_ent
;
30 if (list_empty(head
)) {
31 entry
->next
= entry
->addr
;
33 list_add(&entry
->list
, head
);
37 list_for_each(pos
, head
) {
38 pos_ent
= list_entry(pos
, struct imapper
, list
);
39 if (pos_ent
->slot
> entry
->slot
) {
40 /* found a position in list */
50 __list_add(&entry
->list
, pos
->prev
, pos
);
54 list_add_tail(&entry
->list
, head
);
57 pre_ent
= list_entry(pre
, struct imapper
, list
);
58 pos_ent
= list_entry(pos
, struct imapper
, list
);
60 entry
->next
= pos_ent
->addr
;
62 pre_ent
->next
= entry
->addr
;
63 map_op(data
, pre_ent
);
68 int input_mapper_delete(struct list_head
*mappers
, struct imapper
*entry
,
69 int (*map_op
)(void *, struct imapper
*), void *data
)
71 struct list_head
*next
, *pre
, *head
;
72 struct imapper
*pre_ent
, *next_ent
;
79 pre
= (entry
->list
.prev
== head
) ? head
->prev
: entry
->list
.prev
;
80 next
= (entry
->list
.next
== head
) ? head
->next
: entry
->list
.next
;
82 if (pre
== &entry
->list
) {
83 /* entry is the only one node in mappers list */
84 entry
->next
= entry
->addr
= entry
->user
= entry
->slot
= 0;
86 list_del(&entry
->list
);
90 pre_ent
= list_entry(pre
, struct imapper
, list
);
91 next_ent
= list_entry(next
, struct imapper
, list
);
93 pre_ent
->next
= next_ent
->addr
;
94 map_op(data
, pre_ent
);
95 list_del(&entry
->list
);
100 void free_input_mapper_list(struct list_head
*head
)
102 struct imapper
*entry
;
103 struct list_head
*pos
;
105 while (!list_empty(head
)) {
108 entry
= list_entry(pos
, struct imapper
, list
);