All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: "Frank Schäfer" <fschaefer.oss@googlemail.com>, m.chehab@samsung.com
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH 4/4] em28xx-v4l: get rid of field "users" in struct em28xx_v4l2
Date: Thu, 18 Sep 2014 21:13:10 +0200	[thread overview]
Message-ID: <541B2EC6.1020601@xs4all.nl> (raw)
In-Reply-To: <1406310538-5001-5-git-send-email-fschaefer.oss@googlemail.com>

Hi Frank,

On 07/25/2014 07:48 PM, Frank Schäfer wrote:
> 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.

This won't work: if you capture from both /dev/video and /dev/vbi and close
one, then it stops all streaming.

I would just revert this patch completely.

There is currently no core support for detecting when all users of all devices
registered by a driver have left, so you don't have really have an alternative
but to use your old code.

Regards,

	Hans

> 
> Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
> ---
>  drivers/media/usb/em28xx/em28xx-video.c | 23 +++++++++++++----------
>  drivers/media/usb/em28xx/em28xx.h       |  1 -
>  2 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
> index 3a7ec3b..087ccf9 100644
> --- a/drivers/media/usb/em28xx/em28xx-video.c
> +++ b/drivers/media/usb/em28xx/em28xx-video.c
> @@ -1883,9 +1883,8 @@ static int em28xx_v4l2_open(struct file *filp)
>  		return -EINVAL;
>  	}
>  
> -	em28xx_videodbg("open dev=%s type=%s users=%d\n",
> -			video_device_node_name(vdev), v4l2_type_names[fh_type],
> -			v4l2->users);
> +	em28xx_videodbg("open dev=%s type=%s\n",
> +			video_device_node_name(vdev), v4l2_type_names[fh_type]);
>  
>  	if (mutex_lock_interruptible(&dev->lock))
>  		return -ERESTARTSYS;
> @@ -1898,7 +1897,9 @@ static int em28xx_v4l2_open(struct file *filp)
>  		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);
>  
>  		if (vdev->vfl_type != VFL_TYPE_RADIO)
> @@ -1909,6 +1910,8 @@ static int em28xx_v4l2_open(struct file *filp)
>  		 * of some i2c devices
>  		 */
>  		em28xx_wake_i2c(dev);
> +	} else {
> +		em28xx_videodbg("further filehandles are already opened\n");
>  	}
>  
>  	if (vdev->vfl_type == VFL_TYPE_RADIO) {
> @@ -1918,7 +1921,6 @@ static int em28xx_v4l2_open(struct file *filp)
>  
>  	kref_get(&dev->ref);
>  	kref_get(&v4l2->ref);
> -	v4l2->users++;
>  
>  	mutex_unlock(&dev->lock);
>  
> @@ -2025,12 +2027,11 @@ static int em28xx_v4l2_close(struct file *filp)
>  	struct em28xx_v4l2    *v4l2 = dev->v4l2;
>  	int              errCode;
>  
> -	em28xx_videodbg("users=%d\n", v4l2->users);
> -
> -	vb2_fop_release(filp);
>  	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 */
>  		if (dev->disconnected)
>  			goto exit;
> @@ -2049,10 +2050,12 @@ static int em28xx_v4l2_close(struct file *filp)
>  			em28xx_errdev("cannot change alternate number to "
>  					"0 (error=%i)\n", errCode);
>  		}
> +	} else {
> +		em28xx_videodbg("further opened filehandles left\n");
>  	}
>  
>  exit:
> -	v4l2->users--;
> +	vb2_fop_release(filp);
>  	kref_put(&v4l2->ref, em28xx_free_v4l2);
>  	mutex_unlock(&dev->lock);
>  	kref_put(&dev->ref, em28xx_free_device);
> diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
> index 4360338..84ef8ef 100644
> --- a/drivers/media/usb/em28xx/em28xx.h
> +++ b/drivers/media/usb/em28xx/em28xx.h
> @@ -524,7 +524,6 @@ struct em28xx_v4l2 {
>  	int sensor_yres;
>  	int sensor_xtal;
>  
> -	int users;		/* user count for exclusive use */
>  	int streaming_users;    /* number of actively streaming users */
>  
>  	u32 frequency;		/* selected tuner frequency */
> 


  reply	other threads:[~2014-09-18 19:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-25 17:48 [PATCH 0/4] some em28xx-v4l cleanup patches Frank Schäfer
2014-07-25 17:48 ` [PATCH 1/4] em28xx-v4l: simplify some pointers in em28xx_init_camera() Frank Schäfer
2014-07-25 17:48 ` [PATCH 2/4] em28xx-v4l: get rid of struct em28xx_fh Frank Schäfer
2014-07-25 17:48 ` [PATCH 3/4] em28xx-v4l: simplify em28xx_v4l2_open() by using v4l2_fh_open() Frank Schäfer
2014-07-25 17:48 ` [PATCH 4/4] em28xx-v4l: get rid of field "users" in struct em28xx_v4l2 Frank Schäfer
2014-09-18 19:13   ` Hans Verkuil [this message]
2014-09-18 20:49     ` Frank Schäfer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=541B2EC6.1020601@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=fschaefer.oss@googlemail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.