From patchwork Tue Jul 23 18:04:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 19369 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 1V1gxx-0000rb-8Y; Tue, 23 Jul 2013 20:05:41 +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-7) with esmtp id 1V1gxv-00041b-00; Tue, 23 Jul 2013 20:05:41 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934229Ab3GWSFJ (ORCPT + 1 other); Tue, 23 Jul 2013 14:05:09 -0400 Received: from mail-db8lp0184.outbound.messaging.microsoft.com ([213.199.154.184]:28279 "EHLO db8outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934159Ab3GWSFF (ORCPT ); Tue, 23 Jul 2013 14:05:05 -0400 Received: from mail214-db8-R.bigfish.com (10.174.8.233) by DB8EHSOBE040.bigfish.com (10.174.4.103) with Microsoft SMTP Server id 14.1.225.22; Tue, 23 Jul 2013 18:05:04 +0000 Received: from mail214-db8 (localhost [127.0.0.1]) by mail214-db8-R.bigfish.com (Postfix) with ESMTP id 0262714028A; Tue, 23 Jul 2013 18:05:04 +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(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzz1de098h1de097h8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e23h1155h) Received: from mail214-db8 (localhost.localdomain [127.0.0.1]) by mail214-db8 (MessageSwitch) id 1374602702254792_16844; Tue, 23 Jul 2013 18:05:02 +0000 (UTC) Received: from DB8EHSMHS021.bigfish.com (unknown [10.174.8.254]) by mail214-db8.bigfish.com (Postfix) with ESMTP id 96685240049; Tue, 23 Jul 2013 18:05:01 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB8EHSMHS021.bigfish.com (10.174.4.31) with Microsoft SMTP Server (TLS) id 14.16.227.3; Tue, 23 Jul 2013 18:05:00 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.3.136.1; Tue, 23 Jul 2013 18:04:59 +0000 Received: from fabio-Latitude-E6410.am.freescale.net ([10.29.244.77]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r6NI4u0a027315; Tue, 23 Jul 2013 11:04:57 -0700 From: Fabio Estevam To: CC: , , , Fabio Estevam Subject: [PATCH v4 1/3] [media] coda: Fix error paths Date: Tue, 23 Jul 2013 15:04:48 -0300 Message-ID: <1374602690-12842-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.7.23.175420 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 v3: - Only disable the clocks after v4l2_m2m_ctx_release() Changes since v2: - Newly introduced in this series drivers/media/platform/coda.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c index df4ada88..9384f02 100644 --- a/drivers/media/platform/coda.c +++ b/drivers/media/platform/coda.c @@ -1514,21 +1514,26 @@ 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); ctx->dev = dev; ctx->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); @@ -1537,12 +1542,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,24 +1557,29 @@ 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); 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_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; } @@ -1588,10 +1598,10 @@ static int coda_release(struct file *file) 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); + v4l2_m2m_ctx_release(ctx->m2m_ctx); 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);