diff mbox series

[05/13] media: am437x-vpfe: Streamlined vb2 buffer cleanup

Message ID 20190909162743.30114-6-bparrot@ti.com (mailing list archive)
State New, archived
Headers show
Series media: am437x-vpfe: overdue maintenance | expand

Commit Message

Benoit Parrot Sept. 9, 2019, 4:27 p.m. UTC
Returning queued vb2 buffers back to user space is a common
task best handled by a helper function.

Signed-off-by: Benoit Parrot <bparrot@ti.com>
---
 drivers/media/platform/am437x/am437x-vpfe.c | 54 ++++++++++-----------
 1 file changed, 26 insertions(+), 28 deletions(-)

Comments

Lad, Prabhakar Sept. 16, 2019, 8 a.m. UTC | #1
Hi Benoit,

Thank you for the patch.

On Mon, Sep 9, 2019 at 5:26 PM Benoit Parrot <bparrot@ti.com> wrote:
>
> Returning queued vb2 buffers back to user space is a common
> task best handled by a helper function.
>
> Signed-off-by: Benoit Parrot <bparrot@ti.com>
> ---
>  drivers/media/platform/am437x/am437x-vpfe.c | 54 ++++++++++-----------
>  1 file changed, 26 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
> index 3a8ad9bdf283..52f7fc6e11dd 100644
> --- a/drivers/media/platform/am437x/am437x-vpfe.c
> +++ b/drivers/media/platform/am437x/am437x-vpfe.c
> @@ -1949,6 +1949,29 @@ static void vpfe_buffer_queue(struct vb2_buffer *vb)
>         spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
>  }
>
> +static void vpfe_return_all_buffers(struct vpfe_device *vpfe,
> +                                   enum vb2_buffer_state state)
> +{
> +       struct vpfe_cap_buffer *buf, *node;
> +       unsigned long flags;
> +
> +       spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
> +       list_for_each_entry_safe(buf, node, &vpfe->dma_queue, list) {
> +               vb2_buffer_done(&buf->vb.vb2_buf, state);
> +               list_del(&buf->list);
> +       }
> +
> +       if (vpfe->cur_frm)
> +               vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf, state);
> +
> +       if (vpfe->next_frm && vpfe->next_frm != vpfe->cur_frm)
> +               vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf, state);
> +
> +       vpfe->cur_frm = NULL;
> +       vpfe->next_frm = NULL;
> +       spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
> +}
> +
>  /*
>   * vpfe_start_streaming : Starts the DMA engine for streaming
>   * @vb: ptr to vb2_buffer
> @@ -1957,7 +1980,6 @@ static void vpfe_buffer_queue(struct vb2_buffer *vb)
>  static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
>  {
>         struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
> -       struct vpfe_cap_buffer *buf, *tmp;
>         struct vpfe_subdev_info *sdinfo;
>         unsigned long flags;
>         unsigned long addr;
> @@ -2003,11 +2025,8 @@ static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
>         return 0;
>
>  err:
> -       list_for_each_entry_safe(buf, tmp, &vpfe->dma_queue, list) {
> -               list_del(&buf->list);
> -               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
> -       }
> -
> +       vpfe_return_all_buffers(vpfe, VB2_BUF_STATE_QUEUED);
> +       vpfe_pcr_enable(&vpfe->ccdc, 0);

please create a seperate patch for the above change.

Cheers,
--Prabhakar Lad

>         return ret;
>  }
>
> @@ -2022,7 +2041,6 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
>  {
>         struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
>         struct vpfe_subdev_info *sdinfo;
> -       unsigned long flags;
>         int ret;
>
>         vpfe_pcr_enable(&vpfe->ccdc, 0);
> @@ -2040,27 +2058,7 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
>                 vpfe_dbg(1, vpfe, "stream off failed in subdev\n");
>
>         /* release all active buffers */
> -       spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
> -       if (vpfe->cur_frm == vpfe->next_frm) {
> -               vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf,
> -                               VB2_BUF_STATE_ERROR);
> -       } else {
> -               if (vpfe->cur_frm != NULL)
> -                       vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf,
> -                                       VB2_BUF_STATE_ERROR);
> -               if (vpfe->next_frm != NULL)
> -                       vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf,
> -                                       VB2_BUF_STATE_ERROR);
> -       }
> -
> -       while (!list_empty(&vpfe->dma_queue)) {
> -               vpfe->next_frm = list_entry(vpfe->dma_queue.next,
> -                                               struct vpfe_cap_buffer, list);
> -               list_del(&vpfe->next_frm->list);
> -               vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf,
> -                               VB2_BUF_STATE_ERROR);
> -       }
> -       spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
> +       vpfe_return_all_buffers(vpfe, VB2_BUF_STATE_ERROR);
>  }
>
>  static int vpfe_g_pixelaspect(struct file *file, void *priv,
> --
> 2.17.1
>
Benoit Parrot Sept. 16, 2019, 2:53 p.m. UTC | #2
Lad, Prabhakar <prabhakar.csengg@gmail.com> wrote on Mon [2019-Sep-16 09:00:03 +0100]:
> Hi Benoit,
> 
> Thank you for the patch.
> 
> On Mon, Sep 9, 2019 at 5:26 PM Benoit Parrot <bparrot@ti.com> wrote:
> >
> > Returning queued vb2 buffers back to user space is a common
> > task best handled by a helper function.
> >
> > Signed-off-by: Benoit Parrot <bparrot@ti.com>
> > ---
> >  drivers/media/platform/am437x/am437x-vpfe.c | 54 ++++++++++-----------
> >  1 file changed, 26 insertions(+), 28 deletions(-)
> >
> > diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
> > index 3a8ad9bdf283..52f7fc6e11dd 100644
> > --- a/drivers/media/platform/am437x/am437x-vpfe.c
> > +++ b/drivers/media/platform/am437x/am437x-vpfe.c
> > @@ -1949,6 +1949,29 @@ static void vpfe_buffer_queue(struct vb2_buffer *vb)
> >         spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
> >  }
> >
> > +static void vpfe_return_all_buffers(struct vpfe_device *vpfe,
> > +                                   enum vb2_buffer_state state)
> > +{
> > +       struct vpfe_cap_buffer *buf, *node;
> > +       unsigned long flags;
> > +
> > +       spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
> > +       list_for_each_entry_safe(buf, node, &vpfe->dma_queue, list) {
> > +               vb2_buffer_done(&buf->vb.vb2_buf, state);
> > +               list_del(&buf->list);
> > +       }
> > +
> > +       if (vpfe->cur_frm)
> > +               vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf, state);
> > +
> > +       if (vpfe->next_frm && vpfe->next_frm != vpfe->cur_frm)
> > +               vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf, state);
> > +
> > +       vpfe->cur_frm = NULL;
> > +       vpfe->next_frm = NULL;
> > +       spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
> > +}
> > +
> >  /*
> >   * vpfe_start_streaming : Starts the DMA engine for streaming
> >   * @vb: ptr to vb2_buffer
> > @@ -1957,7 +1980,6 @@ static void vpfe_buffer_queue(struct vb2_buffer *vb)
> >  static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
> >  {
> >         struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
> > -       struct vpfe_cap_buffer *buf, *tmp;
> >         struct vpfe_subdev_info *sdinfo;
> >         unsigned long flags;
> >         unsigned long addr;
> > @@ -2003,11 +2025,8 @@ static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
> >         return 0;
> >
> >  err:
> > -       list_for_each_entry_safe(buf, tmp, &vpfe->dma_queue, list) {
> > -               list_del(&buf->list);
> > -               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
> > -       }
> > -
> > +       vpfe_return_all_buffers(vpfe, VB2_BUF_STATE_QUEUED);
> > +       vpfe_pcr_enable(&vpfe->ccdc, 0);
> 
> please create a seperate patch for the above change.

You mean a separate patch just for the vpfe_pcr_enable() call?

Benoit

> 
> Cheers,
> --Prabhakar Lad
> 
> >         return ret;
> >  }
> >
> > @@ -2022,7 +2041,6 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
> >  {
> >         struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
> >         struct vpfe_subdev_info *sdinfo;
> > -       unsigned long flags;
> >         int ret;
> >
> >         vpfe_pcr_enable(&vpfe->ccdc, 0);
> > @@ -2040,27 +2058,7 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
> >                 vpfe_dbg(1, vpfe, "stream off failed in subdev\n");
> >
> >         /* release all active buffers */
> > -       spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
> > -       if (vpfe->cur_frm == vpfe->next_frm) {
> > -               vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf,
> > -                               VB2_BUF_STATE_ERROR);
> > -       } else {
> > -               if (vpfe->cur_frm != NULL)
> > -                       vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf,
> > -                                       VB2_BUF_STATE_ERROR);
> > -               if (vpfe->next_frm != NULL)
> > -                       vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf,
> > -                                       VB2_BUF_STATE_ERROR);
> > -       }
> > -
> > -       while (!list_empty(&vpfe->dma_queue)) {
> > -               vpfe->next_frm = list_entry(vpfe->dma_queue.next,
> > -                                               struct vpfe_cap_buffer, list);
> > -               list_del(&vpfe->next_frm->list);
> > -               vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf,
> > -                               VB2_BUF_STATE_ERROR);
> > -       }
> > -       spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
> > +       vpfe_return_all_buffers(vpfe, VB2_BUF_STATE_ERROR);
> >  }
> >
> >  static int vpfe_g_pixelaspect(struct file *file, void *priv,
> > --
> > 2.17.1
> >
Lad, Prabhakar Sept. 16, 2019, 4:02 p.m. UTC | #3
On Mon, Sep 16, 2019 at 3:51 PM Benoit Parrot <bparrot@ti.com> wrote:
>
> Lad, Prabhakar <prabhakar.csengg@gmail.com> wrote on Mon [2019-Sep-16 09:00:03 +0100]:
> > Hi Benoit,
> >
> > Thank you for the patch.
> >
> > On Mon, Sep 9, 2019 at 5:26 PM Benoit Parrot <bparrot@ti.com> wrote:
> > >
> > > Returning queued vb2 buffers back to user space is a common
> > > task best handled by a helper function.
> > >
> > > Signed-off-by: Benoit Parrot <bparrot@ti.com>
> > > ---
> > >  drivers/media/platform/am437x/am437x-vpfe.c | 54 ++++++++++-----------
> > >  1 file changed, 26 insertions(+), 28 deletions(-)
> > >
> > > diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
> > > index 3a8ad9bdf283..52f7fc6e11dd 100644
> > > --- a/drivers/media/platform/am437x/am437x-vpfe.c
> > > +++ b/drivers/media/platform/am437x/am437x-vpfe.c
> > > @@ -1949,6 +1949,29 @@ static void vpfe_buffer_queue(struct vb2_buffer *vb)
> > >         spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
> > >  }
> > >
> > > +static void vpfe_return_all_buffers(struct vpfe_device *vpfe,
> > > +                                   enum vb2_buffer_state state)
> > > +{
> > > +       struct vpfe_cap_buffer *buf, *node;
> > > +       unsigned long flags;
> > > +
> > > +       spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
> > > +       list_for_each_entry_safe(buf, node, &vpfe->dma_queue, list) {
> > > +               vb2_buffer_done(&buf->vb.vb2_buf, state);
> > > +               list_del(&buf->list);
> > > +       }
> > > +
> > > +       if (vpfe->cur_frm)
> > > +               vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf, state);
> > > +
> > > +       if (vpfe->next_frm && vpfe->next_frm != vpfe->cur_frm)
> > > +               vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf, state);
> > > +
> > > +       vpfe->cur_frm = NULL;
> > > +       vpfe->next_frm = NULL;
> > > +       spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
> > > +}
> > > +
> > >  /*
> > >   * vpfe_start_streaming : Starts the DMA engine for streaming
> > >   * @vb: ptr to vb2_buffer
> > > @@ -1957,7 +1980,6 @@ static void vpfe_buffer_queue(struct vb2_buffer *vb)
> > >  static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
> > >  {
> > >         struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
> > > -       struct vpfe_cap_buffer *buf, *tmp;
> > >         struct vpfe_subdev_info *sdinfo;
> > >         unsigned long flags;
> > >         unsigned long addr;
> > > @@ -2003,11 +2025,8 @@ static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
> > >         return 0;
> > >
> > >  err:
> > > -       list_for_each_entry_safe(buf, tmp, &vpfe->dma_queue, list) {
> > > -               list_del(&buf->list);
> > > -               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
> > > -       }
> > > -
> > > +       vpfe_return_all_buffers(vpfe, VB2_BUF_STATE_QUEUED);
> > > +       vpfe_pcr_enable(&vpfe->ccdc, 0);
> >
> > please create a seperate patch for the above change.
>
> You mean a separate patch just for the vpfe_pcr_enable() call?
>
yes, as the call to vpfe_pcr_enable() is to disable the CCDC and it
doesn't match the patch
description.

Cheers,
--Prabhakar Lad
diff mbox series

Patch

diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
index 3a8ad9bdf283..52f7fc6e11dd 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -1949,6 +1949,29 @@  static void vpfe_buffer_queue(struct vb2_buffer *vb)
 	spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
 }
 
+static void vpfe_return_all_buffers(struct vpfe_device *vpfe,
+				    enum vb2_buffer_state state)
+{
+	struct vpfe_cap_buffer *buf, *node;
+	unsigned long flags;
+
+	spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
+	list_for_each_entry_safe(buf, node, &vpfe->dma_queue, list) {
+		vb2_buffer_done(&buf->vb.vb2_buf, state);
+		list_del(&buf->list);
+	}
+
+	if (vpfe->cur_frm)
+		vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf, state);
+
+	if (vpfe->next_frm && vpfe->next_frm != vpfe->cur_frm)
+		vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf, state);
+
+	vpfe->cur_frm = NULL;
+	vpfe->next_frm = NULL;
+	spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
+}
+
 /*
  * vpfe_start_streaming : Starts the DMA engine for streaming
  * @vb: ptr to vb2_buffer
@@ -1957,7 +1980,6 @@  static void vpfe_buffer_queue(struct vb2_buffer *vb)
 static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
 	struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
-	struct vpfe_cap_buffer *buf, *tmp;
 	struct vpfe_subdev_info *sdinfo;
 	unsigned long flags;
 	unsigned long addr;
@@ -2003,11 +2025,8 @@  static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
 	return 0;
 
 err:
-	list_for_each_entry_safe(buf, tmp, &vpfe->dma_queue, list) {
-		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
-	}
-
+	vpfe_return_all_buffers(vpfe, VB2_BUF_STATE_QUEUED);
+	vpfe_pcr_enable(&vpfe->ccdc, 0);
 	return ret;
 }
 
@@ -2022,7 +2041,6 @@  static void vpfe_stop_streaming(struct vb2_queue *vq)
 {
 	struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
 	struct vpfe_subdev_info *sdinfo;
-	unsigned long flags;
 	int ret;
 
 	vpfe_pcr_enable(&vpfe->ccdc, 0);
@@ -2040,27 +2058,7 @@  static void vpfe_stop_streaming(struct vb2_queue *vq)
 		vpfe_dbg(1, vpfe, "stream off failed in subdev\n");
 
 	/* release all active buffers */
-	spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
-	if (vpfe->cur_frm == vpfe->next_frm) {
-		vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf,
-				VB2_BUF_STATE_ERROR);
-	} else {
-		if (vpfe->cur_frm != NULL)
-			vb2_buffer_done(&vpfe->cur_frm->vb.vb2_buf,
-					VB2_BUF_STATE_ERROR);
-		if (vpfe->next_frm != NULL)
-			vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf,
-					VB2_BUF_STATE_ERROR);
-	}
-
-	while (!list_empty(&vpfe->dma_queue)) {
-		vpfe->next_frm = list_entry(vpfe->dma_queue.next,
-						struct vpfe_cap_buffer, list);
-		list_del(&vpfe->next_frm->list);
-		vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf,
-				VB2_BUF_STATE_ERROR);
-	}
-	spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
+	vpfe_return_all_buffers(vpfe, VB2_BUF_STATE_ERROR);
 }
 
 static int vpfe_g_pixelaspect(struct file *file, void *priv,