[media] v4l2-device: add kref and a release function
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / video / v4l2-device.c
index fd7a445ce34cec5bdea6dd737763453cd1a3f9ec..5aeaf876ba9b2ca4a04221e41fd4cf2bfbd7c0e1 100644 (file)
@@ -37,6 +37,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
        spin_lock_init(&v4l2_dev->lock);
        mutex_init(&v4l2_dev->ioctl_lock);
        v4l2_prio_init(&v4l2_dev->prio);
+       kref_init(&v4l2_dev->ref);
        v4l2_dev->dev = dev;
        if (dev == NULL) {
                /* If dev == NULL, then name must be filled in by the caller */
@@ -54,6 +55,21 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
 }
 EXPORT_SYMBOL_GPL(v4l2_device_register);
 
+static void v4l2_device_release(struct kref *ref)
+{
+       struct v4l2_device *v4l2_dev =
+               container_of(ref, struct v4l2_device, ref);
+
+       if (v4l2_dev->release)
+               v4l2_dev->release(v4l2_dev);
+}
+
+int v4l2_device_put(struct v4l2_device *v4l2_dev)
+{
+       return kref_put(&v4l2_dev->ref, v4l2_device_release);
+}
+EXPORT_SYMBOL_GPL(v4l2_device_put);
+
 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
                                                atomic_t *instance)
 {