From patchwork Wed Aug 21 15:14:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 2847825 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AC099BF546 for ; Wed, 21 Aug 2013 15:14:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 728BC20495 for ; Wed, 21 Aug 2013 15:14:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC7E520454 for ; Wed, 21 Aug 2013 15:14:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751728Ab3HUPO1 (ORCPT ); Wed, 21 Aug 2013 11:14:27 -0400 Received: from mail-ye0-f171.google.com ([209.85.213.171]:64830 "EHLO mail-ye0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751588Ab3HUPO0 (ORCPT ); Wed, 21 Aug 2013 11:14:26 -0400 Received: by mail-ye0-f171.google.com with SMTP id m3so112174yen.16 for ; Wed, 21 Aug 2013 08:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4WLT4d+QJR9jbTDg9J/rVLA4FaMVD1xKthxd6e9dyzE=; b=WZLj7038YoUMQ89ZPL7rjF3U8Bv9KL/R9RWvJys1Jx/aXqhD7R7jkWN0KfbgRnC3Ny kgU1yzztCdEeGZWa0g+QAha1wOuicb2ZnwbyTtxQeBhLFWl2DaDwcMMZsbCFA13LfGNt IPUYLhTRhf1uc2GfLTxW8MCsdSRm4eA0ymcdkjLtWggMjBAnWhKoSrdpBnEp6dnCBrh0 Am+2sHCOHjPTkfaqdhmMBkN5aNrKWAKbOJlduB4Nv08JDmamFI3FqyIrYdAyjipJBrSp 2Uv/Sf9toNiSMNYnhdYG/SBbb7owDqp01e17TQ2TmO9XlwhGeribCZMwwcFYryHu6MBd IPaA== X-Received: by 10.236.113.102 with SMTP id z66mr6359485yhg.48.1377098065894; Wed, 21 Aug 2013 08:14:25 -0700 (PDT) Received: from localhost.localdomain ([177.194.45.238]) by mx.google.com with ESMTPSA id v22sm8284836yhn.12.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 Aug 2013 08:14:25 -0700 (PDT) From: Fabio Estevam To: k.debski@samsung.com Cc: p.zabel@pengutronix.de, linux-media@vger.kernel.org, Fabio Estevam Subject: [PATCH v7 1/3] [media] coda: Fix error paths Date: Wed, 21 Aug 2013 12:14:16 -0300 Message-Id: <1377098058-12566-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 1.8.1.2 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 From: Fabio Estevam Some resources were not being released in the error path and some were released in the incorrect order. Signed-off-by: Fabio Estevam --- Changes since v6: - Rebased against correct branch drivers/media/platform/coda.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c index 73460de..0894d80 100644 --- a/drivers/media/platform/coda.c +++ b/drivers/media/platform/coda.c @@ -2381,15 +2381,17 @@ static int coda_open(struct file *file) int ret; int idx; - idx = coda_next_free_instance(dev); - if (idx >= CODA_MAX_INSTANCES) - return -EBUSY; - set_bit(idx, &dev->instance_mask); - ctx = kzalloc(sizeof *ctx, GFP_KERNEL); if (!ctx) return -ENOMEM; + idx = coda_next_free_instance(dev); + if (idx >= CODA_MAX_INSTANCES) { + ret = -EBUSY; + goto err_coda_max; + } + set_bit(idx, &dev->instance_mask); + INIT_WORK(&ctx->skip_run, coda_skip_run); v4l2_fh_init(&ctx->fh, video_devdata(file)); file->private_data = &ctx->fh; @@ -2403,6 +2405,9 @@ static int coda_open(struct file *file) default: ctx->reg_idx = idx; } + + clk_prepare_enable(dev->clk_per); + clk_prepare_enable(dev->clk_ahb); set_default_params(ctx); ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &coda_queue_init); @@ -2411,12 +2416,12 @@ static int coda_open(struct file *file) v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n", __func__, ret); - goto err; + goto err_ctx_init; } ret = coda_ctrls_setup(ctx); if (ret) { v4l2_err(&dev->v4l2_dev, "failed to setup coda controls\n"); - goto err; + goto err_ctrls_setup; } ctx->fh.ctrl_handler = &ctx->ctrls; @@ -2424,7 +2429,7 @@ static int coda_open(struct file *file) ret = coda_alloc_context_buf(ctx, &ctx->parabuf, CODA_PARA_BUF_SIZE); if (ret < 0) { v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf"); - goto err; + goto err_dma_alloc; } ctx->bitstream.size = CODA_MAX_FRAME_SIZE; @@ -2433,7 +2438,7 @@ static int coda_open(struct file *file) if (!ctx->bitstream.vaddr) { v4l2_err(&dev->v4l2_dev, "failed to allocate bitstream ringbuffer"); ret = -ENOMEM; - goto err; + goto err_dma_writecombine; } kfifo_init(&ctx->bitstream_fifo, ctx->bitstream.vaddr, ctx->bitstream.size); @@ -2444,17 +2449,27 @@ static int coda_open(struct file *file) list_add(&ctx->list, &dev->instances); coda_unlock(ctx); - clk_prepare_enable(dev->clk_per); - clk_prepare_enable(dev->clk_ahb); - v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n", ctx->idx, ctx); return 0; -err: +err_dma_writecombine: + coda_free_context_buffers(ctx); + if (ctx->dev->devtype->product == CODA_DX6) + coda_free_aux_buf(dev, &ctx->workbuf); + coda_free_aux_buf(dev, &ctx->parabuf); +err_dma_alloc: + v4l2_ctrl_handler_free(&ctx->ctrls); +err_ctrls_setup: + v4l2_m2m_ctx_release(ctx->m2m_ctx); +err_ctx_init: + clk_disable_unprepare(dev->clk_ahb); + clk_disable_unprepare(dev->clk_per); v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); + clear_bit(ctx->idx, &dev->instance_mask); +err_coda_max: kfree(ctx); return ret; } @@ -2496,8 +2511,8 @@ static int coda_release(struct file *file) coda_free_aux_buf(dev, &ctx->parabuf); v4l2_ctrl_handler_free(&ctx->ctrls); - clk_disable_unprepare(dev->clk_per); clk_disable_unprepare(dev->clk_ahb); + clk_disable_unprepare(dev->clk_per); v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); clear_bit(ctx->idx, &dev->instance_mask);