diff options
author | David Härdeman <david@hardeman.nu> | 2015-05-19 18:03:17 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-07-06 07:26:15 -0400 |
commit | fcb13097867757d360d5226d36ed3ffe849dc3ae (patch) | |
tree | 23404ba90bcf2895232f877321d26c84abccb121 /drivers/media/rc/rc-main.c | |
parent | a66b0c41ad277ae62a3ae6ac430a71882f899557 (diff) |
[media] rc-core: use an IDA rather than a bitmap
This patch changes rc-core to use the kernel facilities that are already
available for handling unique numbers instead of rolling its own bitmap
stuff.
Signed-off-by: David Härdeman <david@hardeman.nu>
Tested-by: Stefan Lippers-Hollmann <s.l-h@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/rc/rc-main.c')
-rw-r--r-- | drivers/media/rc/rc-main.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 84d142bdb7a2..20914edd5a10 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c | |||
@@ -18,17 +18,15 @@ | |||
18 | #include <linux/input.h> | 18 | #include <linux/input.h> |
19 | #include <linux/leds.h> | 19 | #include <linux/leds.h> |
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/idr.h> | ||
21 | #include <linux/device.h> | 22 | #include <linux/device.h> |
22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
23 | #include "rc-core-priv.h" | 24 | #include "rc-core-priv.h" |
24 | 25 | ||
25 | /* Bitmap to store allocated device numbers from 0 to IRRCV_NUM_DEVICES - 1 */ | ||
26 | #define IRRCV_NUM_DEVICES 256 | ||
27 | static DECLARE_BITMAP(ir_core_dev_number, IRRCV_NUM_DEVICES); | ||
28 | |||
29 | /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ | 26 | /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ |
30 | #define IR_TAB_MIN_SIZE 256 | 27 | #define IR_TAB_MIN_SIZE 256 |
31 | #define IR_TAB_MAX_SIZE 8192 | 28 | #define IR_TAB_MAX_SIZE 8192 |
29 | #define RC_DEV_MAX 256 | ||
32 | 30 | ||
33 | /* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */ | 31 | /* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */ |
34 | #define IR_KEYPRESS_TIMEOUT 250 | 32 | #define IR_KEYPRESS_TIMEOUT 250 |
@@ -38,6 +36,9 @@ static LIST_HEAD(rc_map_list); | |||
38 | static DEFINE_SPINLOCK(rc_map_lock); | 36 | static DEFINE_SPINLOCK(rc_map_lock); |
39 | static struct led_trigger *led_feedback; | 37 | static struct led_trigger *led_feedback; |
40 | 38 | ||
39 | /* Used to keep track of rc devices */ | ||
40 | static DEFINE_IDA(rc_ida); | ||
41 | |||
41 | static struct rc_map_list *seek_rc_map(const char *name) | 42 | static struct rc_map_list *seek_rc_map(const char *name) |
42 | { | 43 | { |
43 | struct rc_map_list *map = NULL; | 44 | struct rc_map_list *map = NULL; |
@@ -1311,7 +1312,9 @@ int rc_register_device(struct rc_dev *dev) | |||
1311 | static bool raw_init = false; /* raw decoders loaded? */ | 1312 | static bool raw_init = false; /* raw decoders loaded? */ |
1312 | struct rc_map *rc_map; | 1313 | struct rc_map *rc_map; |
1313 | const char *path; | 1314 | const char *path; |
1314 | int rc, devno, attr = 0; | 1315 | int attr = 0; |
1316 | int minor; | ||
1317 | int rc; | ||
1315 | 1318 | ||
1316 | if (!dev || !dev->map_name) | 1319 | if (!dev || !dev->map_name) |
1317 | return -EINVAL; | 1320 | return -EINVAL; |
@@ -1331,13 +1334,13 @@ int rc_register_device(struct rc_dev *dev) | |||
1331 | if (dev->close) | 1334 | if (dev->close) |
1332 | dev->input_dev->close = ir_close; | 1335 | dev->input_dev->close = ir_close; |
1333 | 1336 | ||
1334 | do { | 1337 | minor = ida_simple_get(&rc_ida, 0, RC_DEV_MAX, GFP_KERNEL); |
1335 | devno = find_first_zero_bit(ir_core_dev_number, | 1338 | if (minor < 0) |
1336 | IRRCV_NUM_DEVICES); | 1339 | return minor; |
1337 | /* No free device slots */ | 1340 | |
1338 | if (devno >= IRRCV_NUM_DEVICES) | 1341 | dev->minor = minor; |
1339 | return -ENOMEM; | 1342 | dev_set_name(&dev->dev, "rc%u", dev->minor); |
1340 | } while (test_and_set_bit(devno, ir_core_dev_number)); | 1343 | dev_set_drvdata(&dev->dev, dev); |
1341 | 1344 | ||
1342 | dev->dev.groups = dev->sysfs_groups; | 1345 | dev->dev.groups = dev->sysfs_groups; |
1343 | dev->sysfs_groups[attr++] = &rc_dev_protocol_attr_grp; | 1346 | dev->sysfs_groups[attr++] = &rc_dev_protocol_attr_grp; |
@@ -1357,9 +1360,6 @@ int rc_register_device(struct rc_dev *dev) | |||
1357 | */ | 1360 | */ |
1358 | mutex_lock(&dev->lock); | 1361 | mutex_lock(&dev->lock); |
1359 | 1362 | ||
1360 | dev->devno = devno; | ||
1361 | dev_set_name(&dev->dev, "rc%ld", dev->devno); | ||
1362 | dev_set_drvdata(&dev->dev, dev); | ||
1363 | rc = device_add(&dev->dev); | 1363 | rc = device_add(&dev->dev); |
1364 | if (rc) | 1364 | if (rc) |
1365 | goto out_unlock; | 1365 | goto out_unlock; |
@@ -1435,8 +1435,8 @@ int rc_register_device(struct rc_dev *dev) | |||
1435 | 1435 | ||
1436 | mutex_unlock(&dev->lock); | 1436 | mutex_unlock(&dev->lock); |
1437 | 1437 | ||
1438 | IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n", | 1438 | IR_dprintk(1, "Registered rc%u (driver: %s, remote: %s, mode %s)\n", |
1439 | dev->devno, | 1439 | dev->minor, |
1440 | dev->driver_name ? dev->driver_name : "unknown", | 1440 | dev->driver_name ? dev->driver_name : "unknown", |
1441 | rc_map->name ? rc_map->name : "unknown", | 1441 | rc_map->name ? rc_map->name : "unknown", |
1442 | dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked"); | 1442 | dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked"); |
@@ -1455,7 +1455,7 @@ out_dev: | |||
1455 | device_del(&dev->dev); | 1455 | device_del(&dev->dev); |
1456 | out_unlock: | 1456 | out_unlock: |
1457 | mutex_unlock(&dev->lock); | 1457 | mutex_unlock(&dev->lock); |
1458 | clear_bit(dev->devno, ir_core_dev_number); | 1458 | ida_simple_remove(&rc_ida, minor); |
1459 | return rc; | 1459 | return rc; |
1460 | } | 1460 | } |
1461 | EXPORT_SYMBOL_GPL(rc_register_device); | 1461 | EXPORT_SYMBOL_GPL(rc_register_device); |
@@ -1467,8 +1467,6 @@ void rc_unregister_device(struct rc_dev *dev) | |||
1467 | 1467 | ||
1468 | del_timer_sync(&dev->timer_keyup); | 1468 | del_timer_sync(&dev->timer_keyup); |
1469 | 1469 | ||
1470 | clear_bit(dev->devno, ir_core_dev_number); | ||
1471 | |||
1472 | if (dev->driver_type == RC_DRIVER_IR_RAW) | 1470 | if (dev->driver_type == RC_DRIVER_IR_RAW) |
1473 | ir_raw_event_unregister(dev); | 1471 | ir_raw_event_unregister(dev); |
1474 | 1472 | ||
@@ -1481,6 +1479,8 @@ void rc_unregister_device(struct rc_dev *dev) | |||
1481 | 1479 | ||
1482 | device_del(&dev->dev); | 1480 | device_del(&dev->dev); |
1483 | 1481 | ||
1482 | ida_simple_remove(&rc_ida, dev->minor); | ||
1483 | |||
1484 | rc_free_device(dev); | 1484 | rc_free_device(dev); |
1485 | } | 1485 | } |
1486 | 1486 | ||