From patchwork Sun Sep 6 11:42:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Jarzmik X-Patchwork-Id: 7131571 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 552619F380 for ; Sun, 6 Sep 2015 11:47:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 81F1A205F7 for ; Sun, 6 Sep 2015 11:47:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A1CB7206F4 for ; Sun, 6 Sep 2015 11:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752346AbbIFLrI (ORCPT ); Sun, 6 Sep 2015 07:47:08 -0400 Received: from smtp07.smtpout.orange.fr ([80.12.242.129]:27314 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbbIFLrE (ORCPT ); Sun, 6 Sep 2015 07:47:04 -0400 Received: from belgarion.home ([109.222.247.56]) by mwinf5d65 with ME id Dnn01r00B1DkrDp03nn02s; Sun, 06 Sep 2015 13:47:02 +0200 X-ME-Helo: belgarion.home X-ME-Date: Sun, 06 Sep 2015 13:47:02 +0200 X-ME-IP: 109.222.247.56 From: Robert Jarzmik To: Guennadi Liakhovetski , Mauro Carvalho Chehab , Jiri Kosina Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Robert Jarzmik Subject: [PATCH v5 1/4] media: pxa_camera: fix the buffer free path Date: Sun, 6 Sep 2015 13:42:10 +0200 Message-Id: <1441539733-19201-1-git-send-email-robert.jarzmik@free.fr> X-Mailer: git-send-email 2.1.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Since v3: take into account the 2 paths possibilities to free_buffer() --- drivers/media/platform/soc_camera/pxa_camera.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c index fcb942de0c7f..d4e887841372 100644 --- a/drivers/media/platform/soc_camera/pxa_camera.c +++ b/drivers/media/platform/soc_camera/pxa_camera.c @@ -272,8 +272,6 @@ 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); for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) { if (buf->dmas[i].sg_cpu) @@ -283,6 +281,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; } @@ -479,7 +479,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq, ret = videobuf_iolock(vq, vb, NULL); if (ret) - goto fail; + goto out; if (pcdev->channels == 3) { size_y = size / 2; @@ -504,7 +504,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq, size_u, &sg, &next_ofs); if (ret) { dev_err(dev, "DMA initialization for U failed\n"); - goto fail_u; + goto fail; } /* init DMA for V channel */ @@ -513,7 +513,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq, size_v, &sg, &next_ofs); if (ret) { dev_err(dev, "DMA initialization for V failed\n"); - goto fail_v; + goto fail; } vb->state = VIDEOBUF_PREPARED; @@ -524,12 +524,6 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq, return 0; -fail_v: - dma_free_coherent(dev, buf->dmas[1].sg_size, - buf->dmas[1].sg_cpu, buf->dmas[1].sg_dma); -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: