From patchwork Tue Jul 23 01:38:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 19356 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1V1RYp-0004QC-9l; Tue, 23 Jul 2013 03:38:43 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-5) with esmtp id 1V1RYm-0002cn-9A; Tue, 23 Jul 2013 03:38:43 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754140Ab3GWBif (ORCPT + 1 other); Mon, 22 Jul 2013 21:38:35 -0400 Received: from mail-yh0-f43.google.com ([209.85.213.43]:35485 "EHLO mail-yh0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754004Ab3GWBie (ORCPT ); Mon, 22 Jul 2013 21:38:34 -0400 Received: by mail-yh0-f43.google.com with SMTP id b12so2718726yha.30 for ; Mon, 22 Jul 2013 18:38:33 -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:x-mailer; bh=efYuGewtvhY5Q66+L1hPudLfLBS12B4D0bj2/1GK7cY=; b=ohvgMqt/A7dmffMY/j/91+C0CdOrzCELbQt6mXDLi2VFz8CivbXU0uq+39I9eay7Gt uWgww9KsGMRh1jozCXVXnMt1PWu+E7KXU/nQurUgMJgU5FGYjrDwHfJVuipGbJie7Oxi vURvyhC2td0cpLGvWb9aWY80YZYsWGjYukI4GC7EMqAgHAxKKPXGyH4SH2swoUgIUKjd LRBIZmHB4cCQQ/gjPBHU62NEx7wfqaXGHgZyxUalxBVi7Q+SjANpJFc2mGPGsC2vO4An 8uclu0gUfsRvnzOQ9B2TXLRNPiy0uqzB2NYbvCsaXGWqAz/hEENL5Hytr9elONjLpnE3 TqOQ== X-Received: by 10.236.202.45 with SMTP id c33mr14420951yho.186.1374543513160; Mon, 22 Jul 2013 18:38:33 -0700 (PDT) Received: from localhost.localdomain ([177.194.44.29]) by mx.google.com with ESMTPSA id z45sm42751976yhb.0.2013.07.22.18.38.30 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Jul 2013 18:38:32 -0700 (PDT) From: Fabio Estevam To: k.debski@samsung.com Cc: m.chehab@samsung.com, kernel@pengutronix.de, linux-media@vger.kernel.org, Fabio Estevam Subject: [PATCH v3 1/3] [media] coda: Fix error paths Date: Mon, 22 Jul 2013 22:38:20 -0300 Message-Id: <1374543502-22678-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-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2013.7.23.13022 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' FORGED_FROM_GMAIL 0.1, MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DKIM_SIGNATURE 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0, __FROM_GMAIL 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __PHISH_SPEAR_STRUCTURE_1 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' 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 v2: - Newly introduced in this series drivers/media/platform/coda.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c index df4ada88..ea16c20 100644 --- a/drivers/media/platform/coda.c +++ b/drivers/media/platform/coda.c @@ -1514,15 +1514,17 @@ static int coda_open(struct file *file) int ret = 0; 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); + v4l2_fh_init(&ctx->fh, video_devdata(file)); file->private_data = &ctx->fh; v4l2_fh_add(&ctx->fh); @@ -1537,12 +1539,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; @@ -1552,7 +1554,7 @@ static int coda_open(struct file *file) if (!ctx->parabuf.vaddr) { v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf"); ret = -ENOMEM; - goto err; + goto err_dma_alloc; } coda_lock(ctx); @@ -1567,9 +1569,15 @@ static int coda_open(struct file *file) return 0; -err: +err_dma_alloc: + v4l2_ctrl_handler_free(&ctx->ctrls); +err_ctrls_setup: + v4l2_m2m_ctx_release(ctx->m2m_ctx); +err_ctx_init: v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); + clear_bit(ctx->idx, &dev->instance_mask); +err_coda_max: kfree(ctx); return ret; } @@ -1582,16 +1590,16 @@ static int coda_release(struct file *file) v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n", ctx); + clk_disable_unprepare(dev->clk_ahb); + clk_disable_unprepare(dev->clk_per); coda_lock(ctx); list_del(&ctx->list); coda_unlock(ctx); dma_free_coherent(&dev->plat_dev->dev, CODA_PARA_BUF_SIZE, ctx->parabuf.vaddr, ctx->parabuf.paddr); - v4l2_m2m_ctx_release(ctx->m2m_ctx); v4l2_ctrl_handler_free(&ctx->ctrls); - clk_disable_unprepare(dev->clk_per); - clk_disable_unprepare(dev->clk_ahb); + v4l2_m2m_ctx_release(ctx->m2m_ctx); v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); clear_bit(ctx->idx, &dev->instance_mask);