[media] usbvision: fix locking error
[deliverable/linux.git] / drivers / media / rc / rc-main.c
index 9d015db652808fcb54fc0abfff19e9018dbad488..c80816561181bc6def3c2caf3203bfecb16f90c3 100644 (file)
 #include <linux/input.h>
 #include <linux/leds.h>
 #include <linux/slab.h>
+#include <linux/idr.h>
 #include <linux/device.h>
 #include <linux/module.h>
 #include "rc-core-priv.h"
 
-/* Bitmap to store allocated device numbers from 0 to IRRCV_NUM_DEVICES - 1 */
-#define IRRCV_NUM_DEVICES      256
-static DECLARE_BITMAP(ir_core_dev_number, IRRCV_NUM_DEVICES);
-
 /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
 #define IR_TAB_MIN_SIZE        256
 #define IR_TAB_MAX_SIZE        8192
+#define RC_DEV_MAX     256
 
 /* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */
 #define IR_KEYPRESS_TIMEOUT 250
@@ -38,6 +36,9 @@ static LIST_HEAD(rc_map_list);
 static DEFINE_SPINLOCK(rc_map_lock);
 static struct led_trigger *led_feedback;
 
+/* Used to keep track of rc devices */
+static DEFINE_IDA(rc_ida);
+
 static struct rc_map_list *seek_rc_map(const char *name)
 {
        struct rc_map_list *map = NULL;
@@ -799,7 +800,6 @@ static struct {
        { RC_BIT_SANYO,         "sanyo"         },
        { RC_BIT_SHARP,         "sharp"         },
        { RC_BIT_MCE_KBD,       "mce_kbd"       },
-       { RC_BIT_LIRC,          "lirc"          },
        { RC_BIT_XMP,           "xmp"           },
 };
 
@@ -884,6 +884,9 @@ static ssize_t show_protocols(struct device *device,
                        allowed &= ~proto_names[i].type;
        }
 
+       if (dev->driver_type == RC_DRIVER_IR_RAW)
+               tmp += sprintf(tmp, "[lirc] ");
+
        if (tmp != buf)
                tmp--;
        *tmp = '\n';
@@ -935,8 +938,12 @@ static int parse_protocol_change(u64 *protocols, const char *buf)
                }
 
                if (i == ARRAY_SIZE(proto_names)) {
-                       IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
-                       return -EINVAL;
+                       if (!strcasecmp(tmp, "lirc"))
+                               mask = 0;
+                       else {
+                               IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
+                               return -EINVAL;
+                       }
                }
 
                count++;
@@ -1193,9 +1200,6 @@ static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
 {
        struct rc_dev *dev = to_rc_dev(device);
 
-       if (!dev || !dev->input_dev)
-               return -ENODEV;
-
        if (dev->rc_map.name)
                ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name);
        if (dev->driver_name)
@@ -1314,7 +1318,9 @@ int rc_register_device(struct rc_dev *dev)
        static bool raw_init = false; /* raw decoders loaded? */
        struct rc_map *rc_map;
        const char *path;
-       int rc, devno, attr = 0;
+       int attr = 0;
+       int minor;
+       int rc;
 
        if (!dev || !dev->map_name)
                return -EINVAL;
@@ -1334,13 +1340,13 @@ int rc_register_device(struct rc_dev *dev)
        if (dev->close)
                dev->input_dev->close = ir_close;
 
-       do {
-               devno = find_first_zero_bit(ir_core_dev_number,
-                                           IRRCV_NUM_DEVICES);
-               /* No free device slots */
-               if (devno >= IRRCV_NUM_DEVICES)
-                       return -ENOMEM;
-       } while (test_and_set_bit(devno, ir_core_dev_number));
+       minor = ida_simple_get(&rc_ida, 0, RC_DEV_MAX, GFP_KERNEL);
+       if (minor < 0)
+               return minor;
+
+       dev->minor = minor;
+       dev_set_name(&dev->dev, "rc%u", dev->minor);
+       dev_set_drvdata(&dev->dev, dev);
 
        dev->dev.groups = dev->sysfs_groups;
        dev->sysfs_groups[attr++] = &rc_dev_protocol_attr_grp;
@@ -1360,9 +1366,6 @@ int rc_register_device(struct rc_dev *dev)
         */
        mutex_lock(&dev->lock);
 
-       dev->devno = devno;
-       dev_set_name(&dev->dev, "rc%ld", dev->devno);
-       dev_set_drvdata(&dev->dev, dev);
        rc = device_add(&dev->dev);
        if (rc)
                goto out_unlock;
@@ -1428,8 +1431,6 @@ int rc_register_device(struct rc_dev *dev)
 
        if (dev->change_protocol) {
                u64 rc_type = (1ll << rc_map->rc_type);
-               if (dev->driver_type == RC_DRIVER_IR_RAW)
-                       rc_type |= RC_BIT_LIRC;
                rc = dev->change_protocol(dev, &rc_type);
                if (rc < 0)
                        goto out_raw;
@@ -1438,8 +1439,8 @@ int rc_register_device(struct rc_dev *dev)
 
        mutex_unlock(&dev->lock);
 
-       IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n",
-                  dev->devno,
+       IR_dprintk(1, "Registered rc%u (driver: %s, remote: %s, mode %s)\n",
+                  dev->minor,
                   dev->driver_name ? dev->driver_name : "unknown",
                   rc_map->name ? rc_map->name : "unknown",
                   dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked");
@@ -1458,7 +1459,7 @@ out_dev:
        device_del(&dev->dev);
 out_unlock:
        mutex_unlock(&dev->lock);
-       clear_bit(dev->devno, ir_core_dev_number);
+       ida_simple_remove(&rc_ida, minor);
        return rc;
 }
 EXPORT_SYMBOL_GPL(rc_register_device);
@@ -1470,8 +1471,6 @@ void rc_unregister_device(struct rc_dev *dev)
 
        del_timer_sync(&dev->timer_keyup);
 
-       clear_bit(dev->devno, ir_core_dev_number);
-
        if (dev->driver_type == RC_DRIVER_IR_RAW)
                ir_raw_event_unregister(dev);
 
@@ -1484,6 +1483,8 @@ void rc_unregister_device(struct rc_dev *dev)
 
        device_del(&dev->dev);
 
+       ida_simple_remove(&rc_ida, dev->minor);
+
        rc_free_device(dev);
 }
 
This page took 0.034631 seconds and 5 git commands to generate.