From patchwork Tue Aug 20 19:29:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 19820 X-Patchwork-Delegate: kamil@wypas.org Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1VBrfs-0004f7-4W; Tue, 20 Aug 2013 21:33:04 +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-8) with esmtp id 1VBrfp-0008Bk-lQ; Tue, 20 Aug 2013 21:33:04 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751689Ab3HTTc7 (ORCPT + 1 other); Tue, 20 Aug 2013 15:32:59 -0400 Received: from [207.46.163.27] ([207.46.163.27]:34256 "EHLO co9outboundpool.messaging.microsoft.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750841Ab3HTTc7 (ORCPT ); Tue, 20 Aug 2013 15:32:59 -0400 Received: from mail162-co9-R.bigfish.com (10.236.132.239) by CO9EHSOBE041.bigfish.com (10.236.130.104) with Microsoft SMTP Server id 14.1.225.22; Tue, 20 Aug 2013 19:31:48 +0000 Received: from mail162-co9 (localhost [127.0.0.1]) by mail162-co9-R.bigfish.com (Postfix) with ESMTP id 6933112015B; Tue, 20 Aug 2013 19:31:48 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzz1de098h8275bh1de097hz2dh2a8h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e23h1fe8h1ff5h1155h) Received: from mail162-co9 (localhost.localdomain [127.0.0.1]) by mail162-co9 (MessageSwitch) id 137702710773790_26219; Tue, 20 Aug 2013 19:31:47 +0000 (UTC) Received: from CO9EHSMHS030.bigfish.com (unknown [10.236.132.251]) by mail162-co9.bigfish.com (Postfix) with ESMTP id 04CD3E0031; Tue, 20 Aug 2013 19:31:47 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS030.bigfish.com (10.236.130.40) with Microsoft SMTP Server (TLS) id 14.16.227.3; Tue, 20 Aug 2013 19:31:46 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.3.146.2; Tue, 20 Aug 2013 19:31:44 +0000 Received: from fabio-OptiPlex-7010.am.freescale.net ([10.29.244.68]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r7KJVg0E006884; Tue, 20 Aug 2013 12:31:43 -0700 From: Fabio Estevam To: CC: , , Fabio Estevam Subject: [PATCH v6 1/3] [media] coda: Fix error paths Date: Tue, 20 Aug 2013 16:29:36 -0300 Message-ID: <1377026978-23322-1-git-send-email-fabio.estevam@freescale.com> X-Mailer: git-send-email 1.8.1.2 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% 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.8.20.192128 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, MSGID_ADDED_BY_MTA 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __CT 0, __CT_TEXT_PLAIN 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' 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 v5: - Rebased against latest Kamil's tree 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 66db0df..b5d48b7 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);