Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

David Härdeman and committed by
Mauro Carvalho Chehab
fcb13097 a66b0c41

+23 -23
+1 -1
drivers/media/rc/rc-ir-raw.c
··· 406 406 407 407 spin_lock_init(&dev->raw->lock); 408 408 dev->raw->thread = kthread_run(ir_raw_event_thread, dev->raw, 409 - "rc%ld", dev->devno); 409 + "rc%u", dev->minor); 410 410 411 411 if (IS_ERR(dev->raw->thread)) { 412 412 rc = PTR_ERR(dev->raw->thread);
+20 -20
drivers/media/rc/rc-main.c
··· 18 18 #include <linux/input.h> 19 19 #include <linux/leds.h> 20 20 #include <linux/slab.h> 21 + #include <linux/idr.h> 21 22 #include <linux/device.h> 22 23 #include <linux/module.h> 23 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 26 /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ 30 27 #define IR_TAB_MIN_SIZE 256 31 28 #define IR_TAB_MAX_SIZE 8192 29 + #define RC_DEV_MAX 256 32 30 33 31 /* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */ 34 32 #define IR_KEYPRESS_TIMEOUT 250 ··· 35 37 static LIST_HEAD(rc_map_list); 36 38 static DEFINE_SPINLOCK(rc_map_lock); 37 39 static struct led_trigger *led_feedback; 40 + 41 + /* Used to keep track of rc devices */ 42 + static DEFINE_IDA(rc_ida); 38 43 39 44 static struct rc_map_list *seek_rc_map(const char *name) 40 45 { ··· 1312 1311 static bool raw_init = false; /* raw decoders loaded? */ 1313 1312 struct rc_map *rc_map; 1314 1313 const char *path; 1315 - int rc, devno, attr = 0; 1314 + int attr = 0; 1315 + int minor; 1316 + int rc; 1316 1317 1317 1318 if (!dev || !dev->map_name) 1318 1319 return -EINVAL; ··· 1334 1331 if (dev->close) 1335 1332 dev->input_dev->close = ir_close; 1336 1333 1337 - do { 1338 - devno = find_first_zero_bit(ir_core_dev_number, 1339 - IRRCV_NUM_DEVICES); 1340 - /* No free device slots */ 1341 - if (devno >= IRRCV_NUM_DEVICES) 1342 - return -ENOMEM; 1343 - } while (test_and_set_bit(devno, ir_core_dev_number)); 1334 + minor = ida_simple_get(&rc_ida, 0, RC_DEV_MAX, GFP_KERNEL); 1335 + if (minor < 0) 1336 + return minor; 1337 + 1338 + dev->minor = minor; 1339 + dev_set_name(&dev->dev, "rc%u", dev->minor); 1340 + dev_set_drvdata(&dev->dev, dev); 1344 1341 1345 1342 dev->dev.groups = dev->sysfs_groups; 1346 1343 dev->sysfs_groups[attr++] = &rc_dev_protocol_attr_grp; ··· 1360 1357 */ 1361 1358 mutex_lock(&dev->lock); 1362 1359 1363 - dev->devno = devno; 1364 - dev_set_name(&dev->dev, "rc%ld", dev->devno); 1365 - dev_set_drvdata(&dev->dev, dev); 1366 1360 rc = device_add(&dev->dev); 1367 1361 if (rc) 1368 1362 goto out_unlock; ··· 1435 1435 1436 1436 mutex_unlock(&dev->lock); 1437 1437 1438 - IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n", 1439 - dev->devno, 1438 + IR_dprintk(1, "Registered rc%u (driver: %s, remote: %s, mode %s)\n", 1439 + dev->minor, 1440 1440 dev->driver_name ? dev->driver_name : "unknown", 1441 1441 rc_map->name ? rc_map->name : "unknown", 1442 1442 dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked"); ··· 1455 1455 device_del(&dev->dev); 1456 1456 out_unlock: 1457 1457 mutex_unlock(&dev->lock); 1458 - clear_bit(dev->devno, ir_core_dev_number); 1458 + ida_simple_remove(&rc_ida, minor); 1459 1459 return rc; 1460 1460 } 1461 1461 EXPORT_SYMBOL_GPL(rc_register_device); ··· 1466 1466 return; 1467 1467 1468 1468 del_timer_sync(&dev->timer_keyup); 1469 - 1470 - clear_bit(dev->devno, ir_core_dev_number); 1471 1469 1472 1470 if (dev->driver_type == RC_DRIVER_IR_RAW) 1473 1471 ir_raw_event_unregister(dev); ··· 1478 1480 dev->input_dev = NULL; 1479 1481 1480 1482 device_del(&dev->dev); 1483 + 1484 + ida_simple_remove(&rc_ida, dev->minor); 1481 1485 1482 1486 rc_free_device(dev); 1483 1487 }
+2 -2
include/media/rc-core.h
··· 69 69 * @rc_map: current scan/key table 70 70 * @lock: used to ensure we've filled in all protocol details before 71 71 * anyone can call show_protocols or store_protocols 72 - * @devno: unique remote control device number 72 + * @minor: unique minor remote control device number 73 73 * @raw: additional data for raw pulse/space devices 74 74 * @input_dev: the input child device used to communicate events to userspace 75 75 * @driver_type: specifies if protocol decoding is done in hardware or software ··· 131 131 const char *map_name; 132 132 struct rc_map rc_map; 133 133 struct mutex lock; 134 - unsigned long devno; 134 + unsigned int minor; 135 135 struct ir_raw_event_ctrl *raw; 136 136 struct input_dev *input_dev; 137 137 enum rc_driver_type driver_type;