aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-keytable.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2010-09-10 00:59:11 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-09-10 01:01:49 -0400
commit9f470095068e415658ccc6977cf4b3f5be418526 (patch)
treeb562b84cf87d9f28cd658365bf98a8012238a8d3 /drivers/media/IR/ir-keytable.c
parent67127f3061cc486572a50990a1fd919ddde48c40 (diff)
Input: media/IR - switch to using new keycode interface
Switch the code to use new style of getkeycode and setkeycode methods to allow retrieving and setting keycodes not only by their scancodes but also by index. Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/media/IR/ir-keytable.c')
-rw-r--r--drivers/media/IR/ir-keytable.c393
1 files changed, 262 insertions, 131 deletions
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 7e82a9df726..5ca36a42f01 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -25,14 +25,56 @@
25#define IR_KEYPRESS_TIMEOUT 250 25#define IR_KEYPRESS_TIMEOUT 250
26 26
27/** 27/**
28 * ir_create_table() - initializes a scancode table
29 * @rc_tab: the ir_scancode_table to initialize
30 * @name: name to assign to the table
31 * @ir_type: ir type to assign to the new table
32 * @size: initial size of the table
33 * @return: zero on success or a negative error code
34 *
35 * This routine will initialize the ir_scancode_table and will allocate
36 * memory to hold at least the specified number elements.
37 */
38static int ir_create_table(struct ir_scancode_table *rc_tab,
39 const char *name, u64 ir_type, size_t size)
40{
41 rc_tab->name = name;
42 rc_tab->ir_type = ir_type;
43 rc_tab->alloc = roundup_pow_of_two(size * sizeof(struct ir_scancode));
44 rc_tab->size = rc_tab->alloc / sizeof(struct ir_scancode);
45 rc_tab->scan = kmalloc(rc_tab->alloc, GFP_KERNEL);
46 if (!rc_tab->scan)
47 return -ENOMEM;
48
49 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
50 rc_tab->size, rc_tab->alloc);
51 return 0;
52}
53
54/**
55 * ir_free_table() - frees memory allocated by a scancode table
56 * @rc_tab: the table whose mappings need to be freed
57 *
58 * This routine will free memory alloctaed for key mappings used by given
59 * scancode table.
60 */
61static void ir_free_table(struct ir_scancode_table *rc_tab)
62{
63 rc_tab->size = 0;
64 kfree(rc_tab->scan);
65 rc_tab->scan = NULL;
66}
67
68/**
28 * ir_resize_table() - resizes a scancode table if necessary 69 * ir_resize_table() - resizes a scancode table if necessary
29 * @rc_tab: the ir_scancode_table to resize 70 * @rc_tab: the ir_scancode_table to resize
71 * @gfp_flags: gfp flags to use when allocating memory
30 * @return: zero on success or a negative error code 72 * @return: zero on success or a negative error code
31 * 73 *
32 * This routine will shrink the ir_scancode_table if it has lots of 74 * This routine will shrink the ir_scancode_table if it has lots of
33 * unused entries and grow it if it is full. 75 * unused entries and grow it if it is full.
34 */ 76 */
35static int ir_resize_table(struct ir_scancode_table *rc_tab) 77static int ir_resize_table(struct ir_scancode_table *rc_tab, gfp_t gfp_flags)
36{ 78{
37 unsigned int oldalloc = rc_tab->alloc; 79 unsigned int oldalloc = rc_tab->alloc;
38 unsigned int newalloc = oldalloc; 80 unsigned int newalloc = oldalloc;
@@ -57,7 +99,7 @@ static int ir_resize_table(struct ir_scancode_table *rc_tab)
57 if (newalloc == oldalloc) 99 if (newalloc == oldalloc)
58 return 0; 100 return 0;
59 101
60 newscan = kmalloc(newalloc, GFP_ATOMIC); 102 newscan = kmalloc(newalloc, gfp_flags);
61 if (!newscan) { 103 if (!newscan) {
62 IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc); 104 IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc);
63 return -ENOMEM; 105 return -ENOMEM;
@@ -72,26 +114,78 @@ static int ir_resize_table(struct ir_scancode_table *rc_tab)
72} 114}
73 115
74/** 116/**
75 * ir_do_setkeycode() - internal function to set a keycode in the 117 * ir_update_mapping() - set a keycode in the scancode->keycode table
76 * scancode->keycode table
77 * @dev: the struct input_dev device descriptor 118 * @dev: the struct input_dev device descriptor
78 * @rc_tab: the struct ir_scancode_table to set the keycode in 119 * @rc_tab: scancode table to be adjusted
79 * @scancode: the scancode for the ir command 120 * @index: index of the mapping that needs to be updated
80 * @keycode: the keycode for the ir command 121 * @keycode: the desired keycode
81 * @resize: whether the keytable may be shrunk 122 * @return: previous keycode assigned to the mapping
82 * @return: -EINVAL if the keycode could not be inserted, otherwise zero. 123 *
124 * This routine is used to update scancode->keycopde mapping at given
125 * position.
126 */
127static unsigned int ir_update_mapping(struct input_dev *dev,
128 struct ir_scancode_table *rc_tab,
129 unsigned int index,
130 unsigned int new_keycode)
131{
132 int old_keycode = rc_tab->scan[index].keycode;
133 int i;
134
135 /* Did the user wish to remove the mapping? */
136 if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) {
137 IR_dprintk(1, "#%d: Deleting scan 0x%04x\n",
138 index, rc_tab->scan[index].scancode);
139 rc_tab->len--;
140 memmove(&rc_tab->scan[index], &rc_tab->scan[index+ 1],
141 (rc_tab->len - index) * sizeof(struct ir_scancode));
142 } else {
143 IR_dprintk(1, "#%d: %s scan 0x%04x with key 0x%04x\n",
144 index,
145 old_keycode == KEY_RESERVED ? "New" : "Replacing",
146 rc_tab->scan[index].scancode, new_keycode);
147 rc_tab->scan[index].keycode = new_keycode;
148 __set_bit(new_keycode, dev->keybit);
149 }
150
151 if (old_keycode != KEY_RESERVED) {
152 /* A previous mapping was updated... */
153 __clear_bit(old_keycode, dev->keybit);
154 /* ... but another scancode might use the same keycode */
155 for (i = 0; i < rc_tab->len; i++) {
156 if (rc_tab->scan[i].keycode == old_keycode) {
157 __set_bit(old_keycode, dev->keybit);
158 break;
159 }
160 }
161
162 /* Possibly shrink the keytable, failure is not a problem */
163 ir_resize_table(rc_tab, GFP_ATOMIC);
164 }
165
166 return old_keycode;
167}
168
169/**
170 * ir_locate_scancode() - set a keycode in the scancode->keycode table
171 * @ir_dev: the struct ir_input_dev device descriptor
172 * @rc_tab: scancode table to be searched
173 * @scancode: the desired scancode
174 * @resize: controls whether we allowed to resize the table to
175 * accomodate not yet present scancodes
176 * @return: index of the mapping containing scancode in question
177 * or -1U in case of failure.
83 * 178 *
84 * This routine is used internally to manipulate the scancode->keycode table. 179 * This routine is used to locate given scancode in ir_scancode_table.
85 * The caller has to hold @rc_tab->lock. 180 * If scancode is not yet present the routine will allocate a new slot
181 * for it.
86 */ 182 */
87static int ir_do_setkeycode(struct input_dev *dev, 183static unsigned int ir_establish_scancode(struct ir_input_dev *ir_dev,
88 struct ir_scancode_table *rc_tab, 184 struct ir_scancode_table *rc_tab,
89 unsigned scancode, unsigned keycode, 185 unsigned int scancode,
90 bool resize) 186 bool resize)
91{ 187{
92 unsigned int i; 188 unsigned int i;
93 int old_keycode = KEY_RESERVED;
94 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
95 189
96 /* 190 /*
97 * Unfortunately, some hardware-based IR decoders don't provide 191 * Unfortunately, some hardware-based IR decoders don't provide
@@ -100,65 +194,34 @@ static int ir_do_setkeycode(struct input_dev *dev,
100 * the provided IR with another one, it is needed to allow loading 194 * the provided IR with another one, it is needed to allow loading
101 * IR tables from other remotes. So, 195 * IR tables from other remotes. So,
102 */ 196 */
103 if (ir_dev->props && ir_dev->props->scanmask) { 197 if (ir_dev->props && ir_dev->props->scanmask)
104 scancode &= ir_dev->props->scanmask; 198 scancode &= ir_dev->props->scanmask;
105 }
106 199
107 /* First check if we already have a mapping for this ir command */ 200 /* First check if we already have a mapping for this ir command */
108 for (i = 0; i < rc_tab->len; i++) { 201 for (i = 0; i < rc_tab->len; i++) {
202 if (rc_tab->scan[i].scancode == scancode)
203 return i;
204
109 /* Keytable is sorted from lowest to highest scancode */ 205 /* Keytable is sorted from lowest to highest scancode */
110 if (rc_tab->scan[i].scancode > scancode) 206 if (rc_tab->scan[i].scancode >= scancode)
111 break; 207 break;
112 else if (rc_tab->scan[i].scancode < scancode)
113 continue;
114
115 old_keycode = rc_tab->scan[i].keycode;
116 rc_tab->scan[i].keycode = keycode;
117
118 /* Did the user wish to remove the mapping? */
119 if (keycode == KEY_RESERVED || keycode == KEY_UNKNOWN) {
120 IR_dprintk(1, "#%d: Deleting scan 0x%04x\n",
121 i, scancode);
122 rc_tab->len--;
123 memmove(&rc_tab->scan[i], &rc_tab->scan[i + 1],
124 (rc_tab->len - i) * sizeof(struct ir_scancode));
125 }
126
127 /* Possibly shrink the keytable, failure is not a problem */
128 ir_resize_table(rc_tab);
129 break;
130 } 208 }
131 209
132 if (old_keycode == KEY_RESERVED && keycode != KEY_RESERVED) { 210 /* No previous mapping found, we might need to grow the table */
133 /* No previous mapping found, we might need to grow the table */ 211 if (rc_tab->size == rc_tab->len) {
134 if (resize && ir_resize_table(rc_tab)) 212 if (!resize || ir_resize_table(rc_tab, GFP_ATOMIC))
135 return -ENOMEM; 213 return -1U;
136 214 }
137 IR_dprintk(1, "#%d: New scan 0x%04x with key 0x%04x\n",
138 i, scancode, keycode);
139 215
140 /* i is the proper index to insert our new keycode */ 216 /* i is the proper index to insert our new keycode */
217 if (i < rc_tab->len)
141 memmove(&rc_tab->scan[i + 1], &rc_tab->scan[i], 218 memmove(&rc_tab->scan[i + 1], &rc_tab->scan[i],
142 (rc_tab->len - i) * sizeof(struct ir_scancode)); 219 (rc_tab->len - i) * sizeof(struct ir_scancode));
143 rc_tab->scan[i].scancode = scancode; 220 rc_tab->scan[i].scancode = scancode;
144 rc_tab->scan[i].keycode = keycode; 221 rc_tab->scan[i].keycode = KEY_RESERVED;
145 rc_tab->len++; 222 rc_tab->len++;
146 set_bit(keycode, dev->keybit);
147 } else {
148 IR_dprintk(1, "#%d: Replacing scan 0x%04x with key 0x%04x\n",
149 i, scancode, keycode);
150 /* A previous mapping was updated... */
151 clear_bit(old_keycode, dev->keybit);
152 /* ...but another scancode might use the same keycode */
153 for (i = 0; i < rc_tab->len; i++) {
154 if (rc_tab->scan[i].keycode == old_keycode) {
155 set_bit(old_keycode, dev->keybit);
156 break;
157 }
158 }
159 }
160 223
161 return 0; 224 return i;
162} 225}
163 226
164/** 227/**
@@ -171,17 +234,41 @@ static int ir_do_setkeycode(struct input_dev *dev,
171 * This routine is used to handle evdev EVIOCSKEY ioctl. 234 * This routine is used to handle evdev EVIOCSKEY ioctl.
172 */ 235 */
173static int ir_setkeycode(struct input_dev *dev, 236static int ir_setkeycode(struct input_dev *dev,
174 unsigned int scancode, unsigned int keycode) 237 const struct input_keymap_entry *ke,
238 unsigned int *old_keycode)
175{ 239{
176 int rc;
177 unsigned long flags;
178 struct ir_input_dev *ir_dev = input_get_drvdata(dev); 240 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
179 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; 241 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
242 unsigned int index;
243 unsigned int scancode;
244 int retval;
245 unsigned long flags;
180 246
181 spin_lock_irqsave(&rc_tab->lock, flags); 247 spin_lock_irqsave(&rc_tab->lock, flags);
182 rc = ir_do_setkeycode(dev, rc_tab, scancode, keycode, true); 248
249 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
250 index = ke->index;
251 if (index >= rc_tab->len) {
252 retval = -EINVAL;
253 goto out;
254 }
255 } else {
256 retval = input_scancode_to_scalar(ke, &scancode);
257 if (retval)
258 goto out;
259
260 index = ir_establish_scancode(ir_dev, rc_tab, scancode, true);
261 if (index >= rc_tab->len) {
262 retval = -ENOMEM;
263 goto out;
264 }
265 }
266
267 *old_keycode = ir_update_mapping(dev, rc_tab, index, ke->keycode);
268
269out:
183 spin_unlock_irqrestore(&rc_tab->lock, flags); 270 spin_unlock_irqrestore(&rc_tab->lock, flags);
184 return rc; 271 return retval;
185} 272}
186 273
187/** 274/**
@@ -189,32 +276,73 @@ static int ir_setkeycode(struct input_dev *dev,
189 * @dev: the struct input_dev device descriptor 276 * @dev: the struct input_dev device descriptor
190 * @to: the struct ir_scancode_table to copy entries to 277 * @to: the struct ir_scancode_table to copy entries to
191 * @from: the struct ir_scancode_table to copy entries from 278 * @from: the struct ir_scancode_table to copy entries from
192 * @return: -EINVAL if all keycodes could not be inserted, otherwise zero. 279 * @return: -ENOMEM if all keycodes could not be inserted, otherwise zero.
193 * 280 *
194 * This routine is used to handle table initialization. 281 * This routine is used to handle table initialization.
195 */ 282 */
196static int ir_setkeytable(struct input_dev *dev, 283static int ir_setkeytable(struct ir_input_dev *ir_dev,
197 struct ir_scancode_table *to,
198 const struct ir_scancode_table *from) 284 const struct ir_scancode_table *from)
199{ 285{
200 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
201 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; 286 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
202 unsigned long flags; 287 unsigned int i, index;
203 unsigned int i; 288 int rc;
204 int rc = 0; 289
290 rc = ir_create_table(&ir_dev->rc_tab,
291 from->name, from->ir_type, from->size);
292 if (rc)
293 return rc;
294
295 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
296 rc_tab->size, rc_tab->alloc);
205 297
206 spin_lock_irqsave(&rc_tab->lock, flags);
207 for (i = 0; i < from->size; i++) { 298 for (i = 0; i < from->size; i++) {
208 rc = ir_do_setkeycode(dev, to, from->scan[i].scancode, 299 index = ir_establish_scancode(ir_dev, rc_tab,
209 from->scan[i].keycode, false); 300 from->scan[i].scancode, false);
210 if (rc) 301 if (index >= rc_tab->len) {
302 rc = -ENOMEM;
211 break; 303 break;
304 }
305
306 ir_update_mapping(ir_dev->input_dev, rc_tab, index,
307 from->scan[i].keycode);
212 } 308 }
213 spin_unlock_irqrestore(&rc_tab->lock, flags); 309
310 if (rc)
311 ir_free_table(rc_tab);
312
214 return rc; 313 return rc;
215} 314}
216 315
217/** 316/**
317 * ir_lookup_by_scancode() - locate mapping by scancode
318 * @rc_tab: the &struct ir_scancode_table to search
319 * @scancode: scancode to look for in the table
320 * @return: index in the table, -1U if not found
321 *
322 * This routine performs binary search in RC keykeymap table for
323 * given scancode.
324 */
325static unsigned int ir_lookup_by_scancode(const struct ir_scancode_table *rc_tab,
326 unsigned int scancode)
327{
328 unsigned int start = 0;
329 unsigned int end = rc_tab->len - 1;
330 unsigned int mid;
331
332 while (start <= end) {
333 mid = (start + end) / 2;
334 if (rc_tab->scan[mid].scancode < scancode)
335 start = mid + 1;
336 else if (rc_tab->scan[mid].scancode > scancode)
337 end = mid - 1;
338 else
339 return mid;
340 }
341
342 return -1U;
343}
344
345/**
218 * ir_getkeycode() - get a keycode from the scancode->keycode table 346 * ir_getkeycode() - get a keycode from the scancode->keycode table
219 * @dev: the struct input_dev device descriptor 347 * @dev: the struct input_dev device descriptor
220 * @scancode: the desired scancode 348 * @scancode: the desired scancode
@@ -224,36 +352,46 @@ static int ir_setkeytable(struct input_dev *dev,
224 * This routine is used to handle evdev EVIOCGKEY ioctl. 352 * This routine is used to handle evdev EVIOCGKEY ioctl.
225 */ 353 */
226static int ir_getkeycode(struct input_dev *dev, 354static int ir_getkeycode(struct input_dev *dev,
227 unsigned int scancode, unsigned int *keycode) 355 struct input_keymap_entry *ke)
228{ 356{
229 int start, end, mid;
230 unsigned long flags;
231 int key = KEY_RESERVED;
232 struct ir_input_dev *ir_dev = input_get_drvdata(dev); 357 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
233 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; 358 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
359 struct ir_scancode *entry;
360 unsigned long flags;
361 unsigned int index;
362 unsigned int scancode;
363 int retval;
234 364
235 spin_lock_irqsave(&rc_tab->lock, flags); 365 spin_lock_irqsave(&rc_tab->lock, flags);
236 start = 0; 366
237 end = rc_tab->len - 1; 367 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
238 while (start <= end) { 368 index = ke->index;
239 mid = (start + end) / 2; 369 } else {
240 if (rc_tab->scan[mid].scancode < scancode) 370 retval = input_scancode_to_scalar(ke, &scancode);
241 start = mid + 1; 371 if (retval)
242 else if (rc_tab->scan[mid].scancode > scancode) 372 goto out;
243 end = mid - 1; 373
244 else { 374 index = ir_lookup_by_scancode(rc_tab, scancode);
245 key = rc_tab->scan[mid].keycode; 375 }
246 break; 376
247 } 377 if (index >= rc_tab->len) {
378 if (!(ke->flags & INPUT_KEYMAP_BY_INDEX))
379 IR_dprintk(1, "unknown key for scancode 0x%04x\n",
380 scancode);
381 retval = -EINVAL;
382 goto out;
248 } 383 }
249 spin_unlock_irqrestore(&rc_tab->lock, flags);
250 384
251 if (key == KEY_RESERVED) 385 entry = &rc_tab->scan[index];
252 IR_dprintk(1, "unknown key for scancode 0x%04x\n",
253 scancode);
254 386
255 *keycode = key; 387 ke->index = index;
256 return 0; 388 ke->keycode = entry->keycode;
389 ke->len = sizeof(entry->scancode);
390 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
391
392out:
393 spin_unlock_irqrestore(&rc_tab->lock, flags);
394 return retval;
257} 395}
258 396
259/** 397/**
@@ -268,12 +406,24 @@ static int ir_getkeycode(struct input_dev *dev,
268 */ 406 */
269u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) 407u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
270{ 408{
271 int keycode; 409 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
410 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
411 unsigned int keycode;
412 unsigned int index;
413 unsigned long flags;
414
415 spin_lock_irqsave(&rc_tab->lock, flags);
416
417 index = ir_lookup_by_scancode(rc_tab, scancode);
418 keycode = index < rc_tab->len ?
419 rc_tab->scan[index].keycode : KEY_RESERVED;
420
421 spin_unlock_irqrestore(&rc_tab->lock, flags);
272 422
273 ir_getkeycode(dev, scancode, &keycode);
274 if (keycode != KEY_RESERVED) 423 if (keycode != KEY_RESERVED)
275 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n", 424 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
276 dev->name, scancode, keycode); 425 dev->name, scancode, keycode);
426
277 return keycode; 427 return keycode;
278} 428}
279EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); 429EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
@@ -453,8 +603,8 @@ int __ir_input_register(struct input_dev *input_dev,
453 goto out_dev; 603 goto out_dev;
454 } 604 }
455 605
456 input_dev->getkeycode = ir_getkeycode; 606 input_dev->getkeycode_new = ir_getkeycode;
457 input_dev->setkeycode = ir_setkeycode; 607 input_dev->setkeycode_new = ir_setkeycode;
458 input_set_drvdata(input_dev, ir_dev); 608 input_set_drvdata(input_dev, ir_dev);
459 ir_dev->input_dev = input_dev; 609 ir_dev->input_dev = input_dev;
460 610
@@ -462,12 +612,6 @@ int __ir_input_register(struct input_dev *input_dev,
462 spin_lock_init(&ir_dev->keylock); 612 spin_lock_init(&ir_dev->keylock);
463 setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev); 613 setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev);
464 614
465 ir_dev->rc_tab.name = rc_tab->name;
466 ir_dev->rc_tab.ir_type = rc_tab->ir_type;
467 ir_dev->rc_tab.alloc = roundup_pow_of_two(rc_tab->size *
468 sizeof(struct ir_scancode));
469 ir_dev->rc_tab.scan = kmalloc(ir_dev->rc_tab.alloc, GFP_KERNEL);
470 ir_dev->rc_tab.size = ir_dev->rc_tab.alloc / sizeof(struct ir_scancode);
471 if (props) { 615 if (props) {
472 ir_dev->props = props; 616 ir_dev->props = props;
473 if (props->open) 617 if (props->open)
@@ -476,23 +620,14 @@ int __ir_input_register(struct input_dev *input_dev,
476 input_dev->close = ir_close; 620 input_dev->close = ir_close;
477 } 621 }
478 622
479 if (!ir_dev->rc_tab.scan) {
480 rc = -ENOMEM;
481 goto out_name;
482 }
483
484 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
485 ir_dev->rc_tab.size, ir_dev->rc_tab.alloc);
486
487 set_bit(EV_KEY, input_dev->evbit); 623 set_bit(EV_KEY, input_dev->evbit);
488 set_bit(EV_REP, input_dev->evbit); 624 set_bit(EV_REP, input_dev->evbit);
489 set_bit(EV_MSC, input_dev->evbit); 625 set_bit(EV_MSC, input_dev->evbit);
490 set_bit(MSC_SCAN, input_dev->mscbit); 626 set_bit(MSC_SCAN, input_dev->mscbit);
491 627
492 if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) { 628 rc = ir_setkeytable(ir_dev, rc_tab);
493 rc = -ENOMEM; 629 if (rc)
494 goto out_table; 630 goto out_name;
495 }
496 631
497 rc = ir_register_class(input_dev); 632 rc = ir_register_class(input_dev);
498 if (rc < 0) 633 if (rc < 0)
@@ -515,7 +650,7 @@ int __ir_input_register(struct input_dev *input_dev,
515out_event: 650out_event:
516 ir_unregister_class(input_dev); 651 ir_unregister_class(input_dev);
517out_table: 652out_table:
518 kfree(ir_dev->rc_tab.scan); 653 ir_free_table(&ir_dev->rc_tab);
519out_name: 654out_name:
520 kfree(ir_dev->driver_name); 655 kfree(ir_dev->driver_name);
521out_dev: 656out_dev:
@@ -533,7 +668,6 @@ EXPORT_SYMBOL_GPL(__ir_input_register);
533void ir_input_unregister(struct input_dev *input_dev) 668void ir_input_unregister(struct input_dev *input_dev)
534{ 669{
535 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 670 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
536 struct ir_scancode_table *rc_tab;
537 671
538 if (!ir_dev) 672 if (!ir_dev)
539 return; 673 return;
@@ -545,10 +679,7 @@ void ir_input_unregister(struct input_dev *input_dev)
545 if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) 679 if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW)
546 ir_raw_event_unregister(input_dev); 680 ir_raw_event_unregister(input_dev);
547 681
548 rc_tab = &ir_dev->rc_tab; 682 ir_free_table(&ir_dev->rc_tab);
549 rc_tab->size = 0;
550 kfree(rc_tab->scan);
551 rc_tab->scan = NULL;
552 683
553 ir_unregister_class(input_dev); 684 ir_unregister_class(input_dev);
554 685