public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>,
	LMML <linux-media@vger.kernel.org>,
	Hans Verkuil <hans.verkuil@cisco.com>
Cc: DLOS <davinci-linux-open-source@linux.davincidsp.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 21/49] media: davinci: vpif_display: use SIMPLE_DEV_PM_OPS
Date: Fri, 23 May 2014 10:48:13 +0200	[thread overview]
Message-ID: <537F0B4D.60700@xs4all.nl> (raw)
In-Reply-To: <1400247235-31434-23-git-send-email-prabhakar.csengg@gmail.com>

On 05/16/2014 03:33 PM, Lad, Prabhakar wrote:
> From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
> 
> this patch uses SIMPLE_DEV_PM_OPS, and drops unneeded members
> from io_usrs, usrs and makes use of vb2 helepers instead.
> 
> Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
> ---
>  drivers/media/platform/davinci/vpif_display.c |   64 ++++++++++++-------------
>  drivers/media/platform/davinci/vpif_display.h |    4 --
>  2 files changed, 30 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
> index 401d03a..81d955a 100644
> --- a/drivers/media/platform/davinci/vpif_display.c
> +++ b/drivers/media/platform/davinci/vpif_display.c
> @@ -1124,10 +1124,8 @@ static int vpif_probe_complete(void)
>  	for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
>  		ch = vpif_obj.dev[j];
>  		/* Initialize field of the channel objects */
> -		atomic_set(&ch->usrs, 0);
>  		for (k = 0; k < VPIF_NUMOBJECTS; k++) {
>  			common = &ch->common[k];
> -			common->io_usrs = 0;
>  			spin_lock_init(&common->irqlock);
>  			mutex_init(&common->lock);
>  			common->set_addr = NULL;
> @@ -1371,7 +1369,7 @@ static int vpif_remove(struct platform_device *device)
>  	return 0;
>  }
>  
> -#ifdef CONFIG_PM
> +#ifdef CONFIG_PM_SLEEP
>  static int vpif_suspend(struct device *dev)
>  {
>  	struct common_obj *common;
> @@ -1382,18 +1380,20 @@ static int vpif_suspend(struct device *dev)
>  		/* Get the pointer to the channel object */
>  		ch = vpif_obj.dev[i];
>  		common = &ch->common[VPIF_VIDEO_INDEX];
> +
> +		if (!vb2_is_streaming(&common->buffer_queue))
> +			continue;

The use of vb2_is_streaming here is not correct. It is possible to call STREAMON
without having any buffers queued. So vb2_is_streaming() can return true without
start_streaming() having been called. Only after at least one buffer has been
queued will start_streaming be called.

So this code will fail if you call STREAMON without any buffers queued and
then suspend and resume. The resume callback will start the DMA without having
proper DMA pointers set up. Probably not a good idea.

The fix is to check the vb2_queue->start_streaming_called flag. I think we
need a vb2_start_streaming_called() inline function as that's a bit cleaner
than checking that flag directly.

Regards,

	Hans

> +
>  		mutex_lock(&common->lock);
> -		if (atomic_read(&ch->usrs) && common->io_usrs) {
> -			/* Disable channel */
> -			if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
> -				enable_channel2(0);
> -				channel2_intr_enable(0);
> -			}
> -			if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
> -				ycmux_mode == 2) {
> -				enable_channel3(0);
> -				channel3_intr_enable(0);
> -			}
> +		/* Disable channel */
> +		if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
> +			enable_channel2(0);
> +			channel2_intr_enable(0);
> +		}
> +		if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
> +			ycmux_mode == 2) {
> +			enable_channel3(0);
> +			channel3_intr_enable(0);
>  		}
>  		mutex_unlock(&common->lock);
>  	}
> @@ -1412,18 +1412,20 @@ static int vpif_resume(struct device *dev)
>  		/* Get the pointer to the channel object */
>  		ch = vpif_obj.dev[i];
>  		common = &ch->common[VPIF_VIDEO_INDEX];
> +
> +		if (!vb2_is_streaming(&common->buffer_queue))
> +			continue;
> +
>  		mutex_lock(&common->lock);
> -		if (atomic_read(&ch->usrs) && common->io_usrs) {
> -			/* Enable channel */
> -			if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
> -				enable_channel2(1);
> -				channel2_intr_enable(1);
> -			}
> -			if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
> -					ycmux_mode == 2) {
> -				enable_channel3(1);
> -				channel3_intr_enable(1);
> -			}
> +		/* Enable channel */
> +		if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
> +			enable_channel2(1);
> +			channel2_intr_enable(1);
> +		}
> +		if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
> +				ycmux_mode == 2) {
> +			enable_channel3(1);
> +			channel3_intr_enable(1);
>  		}
>  		mutex_unlock(&common->lock);
>  	}
> @@ -1431,21 +1433,15 @@ static int vpif_resume(struct device *dev)
>  	return 0;
>  }
>  
> -static const struct dev_pm_ops vpif_pm = {
> -	.suspend        = vpif_suspend,
> -	.resume         = vpif_resume,
> -};
> -
> -#define vpif_pm_ops (&vpif_pm)
> -#else
> -#define vpif_pm_ops NULL
>  #endif
>  
> +static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
> +
>  static __refdata struct platform_driver vpif_driver = {
>  	.driver	= {
>  			.name	= VPIF_DRIVER_NAME,
>  			.owner	= THIS_MODULE,
> -			.pm	= vpif_pm_ops,
> +			.pm	= &vpif_pm_ops,
>  	},
>  	.probe	= vpif_probe,
>  	.remove	= vpif_remove,
> diff --git a/drivers/media/platform/davinci/vpif_display.h b/drivers/media/platform/davinci/vpif_display.h
> index 089e860..18cba9a 100644
> --- a/drivers/media/platform/davinci/vpif_display.h
> +++ b/drivers/media/platform/davinci/vpif_display.h
> @@ -83,8 +83,6 @@ struct common_obj {
>  	/* channel specific parameters */
>  	struct mutex lock;			/* lock used to access this
>  						 * structure */
> -	u32 io_usrs;				/* number of users performing
> -						 * IO */
>  	u32 ytop_off;				/* offset of Y top from the
>  						 * starting of the buffer */
>  	u32 ybtm_off;				/* offset of Y bottom from the
> @@ -104,8 +102,6 @@ struct channel_obj {
>  	/* V4l2 specific parameters */
>  	struct video_device *video_dev;	/* Identifies video device for
>  					 * this channel */
> -	atomic_t usrs;			/* number of open instances of
> -					 * the channel */
>  	u32 field_id;			/* Indicates id of the field
>  					 * which is being displayed */
>  	u8 initialized;			/* flag to indicate whether
> 


  reply	other threads:[~2014-05-23  8:48 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-16 13:33 [PATCH v5 00/49] DaVinci: vpif: upgrade with v4l helpers and v4l compliance fixes Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 01/49] media: davinci: vpif_display: initalize vb2 queue and DMA context during probe Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 01/49] media: davinci: vpif_display: initialize " Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 02/49] media: davinci: vpif_display: drop buf_init() callback Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 03/49] media: davinci: vpif_display: use vb2_ops_wait_prepare/finish helper functions Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 04/49] media: davinci: vpif_display: release buffers in case start_streaming() call back fails Lad, Prabhakar
2014-05-23  8:35   ` Hans Verkuil
2014-05-24  4:02     ` Prabhakar Lad
2014-05-16 13:33 ` [PATCH v5 05/49] media: davinci: vpif_display: drop buf_cleanup() callback Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 06/49] media: davinci: vpif_display: improve vpif_buffer_prepare() callback Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 07/49] media: davinci: vpif_display: improve vpif_buffer_queue_setup() function Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 08/49] media: davinci: vpif_display: improve start/stop_streaming callbacks Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 09/49] media: davinci: vpif_display: use vb2_fop_mmap/poll Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 10/49] media: davinci: vpif_display: use v4l2_fh_open and vb2_fop_release Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 11/49] media: davinci: vpif_display: use vb2_ioctl_* helpers Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 12/49] media: davinci: vpif_display: drop unused member fbuffers Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 13/49] media: davinci: vpif_display: drop reserving memory for device Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 14/49] media: davinci: vpif_display: drop unnecessary field memory Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 15/49] media: davinci: vpif_display: drop numbuffers field from common_obj Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 16/49] media: davinic: vpif_display: drop started member from struct common_obj Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 17/49] media: davinci: vpif_display: initialize the video device in single place Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 18/49] media: davinci: vpif_display: drop unneeded module params Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 19/49] media: davinci: vpif_display: drop cropcap Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 20/49] media: davinci: vpif_display: group v4l2_ioctl_ops Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 21/49] media: davinci: vpif_display: use SIMPLE_DEV_PM_OPS Lad, Prabhakar
2014-05-23  8:48   ` Hans Verkuil [this message]
2014-05-16 13:33 ` [PATCH v5 22/49] media: davinci: vpif_display: return -ENODATA for *dv_timings calls Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 23/49] media: davinci: vpif_display: return -ENODATA for *std calls Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 24/49] media: davinci; vpif_display: fix checkpatch error Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 25/49] media: davinci: vpif_display: fix v4l-complinace issues Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 26/49] media: davinci: vpif_capture: initalize vb2 queue and DMA context during probe Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 27/49] media: davinci: vpif_capture: drop buf_init() callback Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 28/49] media: davinci: vpif_capture: use vb2_ops_wait_prepare/finish helper functions Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 28/49] media: davinci: vpif_display: " Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 29/49] media: davinci: vpif_capture: release buffers in case start_streaming() call back fails Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 30/49] media: davinci: vpif_capture: drop buf_cleanup() callback Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 31/49] media: davinci: vpif_capture: improve vpif_buffer_prepare() callback Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 32/49] media: davinci: vpif_capture: improve vpif_buffer_queue_setup() function Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 33/49] media: davinci: vpif_capture: improve start/stop_streaming callbacks Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 34/49] media: davinci: vpif_capture: use vb2_fop_mmap/poll Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 35/49] media: davinci: vpif_capture: use v4l2_fh_open and vb2_fop_release Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 36/49] media: davinci: vpif_capture: use vb2_ioctl_* helpers Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 37/49] media: davinci: vpif_capture: drop reserving memory for device Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 38/49] media: davinci: vpif_capture: drop unnecessary field memory Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 39/49] media: davinic: vpif_capture: drop started member from struct common_obj Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 40/49] media: davinci: vpif_capture: initialize the video device in single place Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 41/49] media: davinci: vpif_capture: drop unneeded module params Lad, Prabhakar
2014-05-23 22:38   ` Mauro Carvalho Chehab
2014-05-24  4:27     ` Prabhakar Lad
2014-05-16 13:33 ` [PATCH v5 42/49] media: davinci: vpif_capture: drop cropcap Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 43/49] media: davinci: vpif_capture: group v4l2_ioctl_ops Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 44/49] media: davinci: vpif_capture: use SIMPLE_DEV_PM_OPS Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 45/49] media: davinci: vpif_capture: return -ENODATA for *dv_timings calls Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 46/49] media: davinci: vpif_capture: return -ENODATA for *std calls Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 47/49] media: davinci: vpif_capture: drop check __KERNEL__ Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 48/49] media: davinci: vpif_capture: fix v4l-complinace issues Lad, Prabhakar
2014-05-16 13:33 ` [PATCH v5 49/49] media: davinci: vpif: add Copyright message Lad, Prabhakar
2014-05-23  8:30 ` [PATCH v5 00/49] DaVinci: vpif: upgrade with v4l helpers and v4l compliance fixes Hans Verkuil
2014-05-24  4:09   ` Prabhakar Lad
2014-05-23  9:05 ` Hans Verkuil

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=537F0B4D.60700@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=davinci-linux-open-source@linux.davincidsp.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=prabhakar.csengg@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox