Commit 747dba7d authored by Frank Schaefer's avatar Frank Schaefer Committed by Mauro Carvalho Chehab

[media] em28xx-v4l: get rid of field "users" in struct em28xx_v4l2

Instead of counting the number of opened file handles, use function
v4l2_fh_is_singular_file() in em28xx_v4l2_open() and em28xx_v4l2_close() to
determine if the file handle is the first/last opened one.
Signed-off-by: default avatarFrank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 3c0f90e1
...@@ -1883,9 +1883,8 @@ static int em28xx_v4l2_open(struct file *filp) ...@@ -1883,9 +1883,8 @@ static int em28xx_v4l2_open(struct file *filp)
return -EINVAL; return -EINVAL;
} }
em28xx_videodbg("open dev=%s type=%s users=%d\n", em28xx_videodbg("open dev=%s type=%s\n",
video_device_node_name(vdev), v4l2_type_names[fh_type], video_device_node_name(vdev), v4l2_type_names[fh_type]);
v4l2->users);
if (mutex_lock_interruptible(&dev->lock)) if (mutex_lock_interruptible(&dev->lock))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -1898,7 +1897,9 @@ static int em28xx_v4l2_open(struct file *filp) ...@@ -1898,7 +1897,9 @@ static int em28xx_v4l2_open(struct file *filp)
return ret; return ret;
} }
if (v4l2->users == 0) { if (v4l2_fh_is_singular_file(filp)) {
em28xx_videodbg("first opened filehandle, initializing device\n");
em28xx_set_mode(dev, EM28XX_ANALOG_MODE); em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
if (vdev->vfl_type != VFL_TYPE_RADIO) if (vdev->vfl_type != VFL_TYPE_RADIO)
...@@ -1909,6 +1910,8 @@ static int em28xx_v4l2_open(struct file *filp) ...@@ -1909,6 +1910,8 @@ static int em28xx_v4l2_open(struct file *filp)
* of some i2c devices * of some i2c devices
*/ */
em28xx_wake_i2c(dev); em28xx_wake_i2c(dev);
} else {
em28xx_videodbg("further filehandles are already opened\n");
} }
if (vdev->vfl_type == VFL_TYPE_RADIO) { if (vdev->vfl_type == VFL_TYPE_RADIO) {
...@@ -1918,7 +1921,6 @@ static int em28xx_v4l2_open(struct file *filp) ...@@ -1918,7 +1921,6 @@ static int em28xx_v4l2_open(struct file *filp)
kref_get(&dev->ref); kref_get(&dev->ref);
kref_get(&v4l2->ref); kref_get(&v4l2->ref);
v4l2->users++;
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
...@@ -2025,12 +2027,11 @@ static int em28xx_v4l2_close(struct file *filp) ...@@ -2025,12 +2027,11 @@ static int em28xx_v4l2_close(struct file *filp)
struct em28xx_v4l2 *v4l2 = dev->v4l2; struct em28xx_v4l2 *v4l2 = dev->v4l2;
int errCode; int errCode;
em28xx_videodbg("users=%d\n", v4l2->users);
vb2_fop_release(filp);
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
if (v4l2->users == 1) { if (v4l2_fh_is_singular_file(filp)) {
em28xx_videodbg("last opened filehandle, shutting down device\n");
/* No sense to try to write to the device */ /* No sense to try to write to the device */
if (dev->disconnected) if (dev->disconnected)
goto exit; goto exit;
...@@ -2049,10 +2050,12 @@ static int em28xx_v4l2_close(struct file *filp) ...@@ -2049,10 +2050,12 @@ static int em28xx_v4l2_close(struct file *filp)
em28xx_errdev("cannot change alternate number to " em28xx_errdev("cannot change alternate number to "
"0 (error=%i)\n", errCode); "0 (error=%i)\n", errCode);
} }
} else {
em28xx_videodbg("further opened filehandles left\n");
} }
exit: exit:
v4l2->users--; vb2_fop_release(filp);
kref_put(&v4l2->ref, em28xx_free_v4l2); kref_put(&v4l2->ref, em28xx_free_v4l2);
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
kref_put(&dev->ref, em28xx_free_device); kref_put(&dev->ref, em28xx_free_device);
......
...@@ -524,7 +524,6 @@ struct em28xx_v4l2 { ...@@ -524,7 +524,6 @@ struct em28xx_v4l2 {
int sensor_yres; int sensor_yres;
int sensor_xtal; int sensor_xtal;
int users; /* user count for exclusive use */
int streaming_users; /* number of actively streaming users */ int streaming_users; /* number of actively streaming users */
u32 frequency; /* selected tuner frequency */ u32 frequency; /* selected tuner frequency */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment