Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751186AbbGLPOK (ORCPT ); Sun, 12 Jul 2015 11:14:10 -0400 Received: from mout.gmx.net ([212.227.17.20]:50042 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750770AbbGLPOI (ORCPT ); Sun, 12 Jul 2015 11:14:08 -0400 Date: Sun, 12 Jul 2015 17:13:50 +0200 (CEST) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Robert Jarzmik cc: Mauro Carvalho Chehab , Jiri Kosina , Linux Media Mailing List , linux-kernel@vger.kernel.org, Daniel Mack , Robert Jarzmik Subject: Re: [PATCH 1/4] media: pxa_camera: fix the buffer free path (fwd) Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Provags-ID: V03:K0:JdPpiy9uwRdqnEZ4eT7qk8syMdpDcD/h7KJjhHf14exI001NbUp K7fPiKYKZsPx5RzqMhwl+zM46lu2aABlR85lZNzrzGXwnHbusww38wg0d6SE6hqGwMMeNdl 3umewgDCKOmCr8yBvQ2E0QlThZ7eGrc65iHY9QVY4NrTfyYVTWkzPhLWEFtQ3GM4rl+pNeN d8V1ABZXXTeUadZoIJ9dQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:wZcQZT/y2Wc=:+Vr9BtQv1Dq/FnIlQEJI2s k+Hl0jBp68IvvxWcoSiAs+AaSS1dky2PLl+mE66+RIgFGFqEsvFkUqgSMcU35Sn4w3UQs3/wa 0BoUhTVzfA02/YMI6vemvbZ9cidcfjReVmAa6AyA4a5eaEZRPkja8VfYtA4yWYidtCmyuJKJU wMfjrnHtXQ0nQAVuIraBUHWWgxqWb8Tz0cT9mMCj76B/uNfE3eplNNtAKPXFZ4EFKGZIiQVhu 79HW3JKM393E7rSvToEJPrl16CVSK7ilWiznqNTWbmSHxajdQaa3aRNJeMU9oFwpqaH4ouJET xGbVZG4XkOpN8hKvi4XUfmx2Ny3RuHxXwh+uVomkqqRzF84GtJmaY2N8nY4I8V9p0YVYVJu33 drcXwO2IJDhh+DRdqanna+1XX8aeamEbN094i1kj107ECszkK64u6sSQoMdIdZO2Dl5tGruD/ JMI0+0CSuhBSN/q99/RyGVcriTdXhJ3UADt0sJerjlFfbDX2jEEB49/ipBg+W/JdRaju7yt0V nbHYq3jgU6eisOruH/ymh82XblsozSi7mTT9rrW2tPgW/WaIQYExuazItA+DKnFGnWWJez28T jIvY+U/Jkaj1ReuesQ5DEGIH3Q9lJJE8gJdP3OH6AKEyqGXaaWYovw3FoqgongCTkiy02y74N cyTCYHkbNxZp2hBkwH+WPV35m0gGF5K8eONbDBhQ5BI8rGj7GCOYo8MLhlrdlKIDuw30= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2923 Lines: 87 Hi Robert, No idea why this mail hasn't been delivered... Sorry, resending. Thanks Guennadi ---------- Forwarded message ---------- Date: Sun, 31 May 2015 21:34:50 +0200 (CEST) From: Guennadi Liakhovetski Subject: Re: [PATCH 1/4] media: pxa_camera: fix the buffer free path Hi Robert, Thanks for the patch. On Sun, 22 Mar 2015, Robert Jarzmik wrote: > From: Robert Jarzmik free_buffer() is called from two locations: from the .buf_release() callback and on the error path in .buf_prepare(). In the first case it does the complete freeing of the buffers and DMA channels, in the latter case the error path, including buffer freeing can _only_ be entered if buffer allocation has been attempted, i.e. buffer state is VIDEOBUF_NEEDS_INIT. Which is exactly the case you're catching below. Following your patch, in this case free_buffer() shouldn't be called at all, because videobuf_waiton() isn't needed either. That can be achieved easier: fail_u: dma_free_coherent(dev, buf->dmas[0].sg_size, buf->dmas[0].sg_cpu, buf->dmas[0].sg_dma); -fail: - free_buffer(vq, buf); out: buf->inwork = 0; return ret; But tbh I don't understand why videobuf_dma_free() and videobuf_dma_unmap() shouldn't be called if videobuf_iolock() was successful, are you sure about that? Thanks Guennadi > Fix the error path where the video buffer wasn't allocated nor > mapped. In this case, in the driver free path don't try to unmap memory > which was not mapped in the first place. > > Signed-off-by: Robert Jarzmik > --- > drivers/media/platform/soc_camera/pxa_camera.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c > index 8d6e343..3ca33f0 100644 > --- a/drivers/media/platform/soc_camera/pxa_camera.c > +++ b/drivers/media/platform/soc_camera/pxa_camera.c > @@ -272,8 +272,8 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf) > * longer in STATE_QUEUED or STATE_ACTIVE > */ > videobuf_waiton(vq, &buf->vb, 0, 0); > - videobuf_dma_unmap(vq->dev, dma); > - videobuf_dma_free(dma); > + if (buf->vb.state == VIDEOBUF_NEEDS_INIT) > + return; > > for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) { > if (buf->dmas[i].sg_cpu) > @@ -283,6 +283,8 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf) > buf->dmas[i].sg_dma); > buf->dmas[i].sg_cpu = NULL; > } > + videobuf_dma_unmap(vq->dev, dma); > + videobuf_dma_free(dma); > > buf->vb.state = VIDEOBUF_NEEDS_INIT; > } > -- > 2.1.4 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/