]> Pileus Git - ~andy/linux/blobdiff - drivers/media/rc/rc-main.c
Merge branch 'modsplit-Oct31_2011' of git://git.kernel.org/pub/scm/linux/kernel/git...
[~andy/linux] / drivers / media / rc / rc-main.c
index 51a23f48bc7d83f99eed629a32188083f22786c3..29f900065d8ad7c74f252cb8b8a3479b0c456838 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/input.h>
 #include <linux/slab.h>
 #include <linux/device.h>
+#include <linux/module.h>
 #include "rc-core-priv.h"
 
 /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
@@ -928,10 +929,6 @@ out:
 
 static void rc_dev_release(struct device *device)
 {
-       struct rc_dev *dev = to_rc_dev(device);
-
-       kfree(dev);
-       module_put(THIS_MODULE);
 }
 
 #define ADD_HOTPLUG_VAR(fmt, val...)                                   \
@@ -945,6 +942,9 @@ 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)
@@ -1013,10 +1013,16 @@ EXPORT_SYMBOL_GPL(rc_allocate_device);
 
 void rc_free_device(struct rc_dev *dev)
 {
-       if (dev) {
+       if (!dev)
+               return;
+
+       if (dev->input_dev)
                input_free_device(dev->input_dev);
-               put_device(&dev->dev);
-       }
+
+       put_device(&dev->dev);
+
+       kfree(dev);
+       module_put(THIS_MODULE);
 }
 EXPORT_SYMBOL_GPL(rc_free_device);
 
@@ -1143,14 +1149,18 @@ void rc_unregister_device(struct rc_dev *dev)
        if (dev->driver_type == RC_DRIVER_IR_RAW)
                ir_raw_event_unregister(dev);
 
+       /* Freeing the table should also call the stop callback */
+       ir_free_table(&dev->rc_map);
+       IR_dprintk(1, "Freed keycode table\n");
+
        input_unregister_device(dev->input_dev);
        dev->input_dev = NULL;
 
-       ir_free_table(&dev->rc_map);
-       IR_dprintk(1, "Freed keycode table\n");
+       device_del(&dev->dev);
 
-       device_unregister(&dev->dev);
+       rc_free_device(dev);
 }
+
 EXPORT_SYMBOL_GPL(rc_unregister_device);
 
 /*