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: 2831661 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 D9980C0319 for ; Tue, 23 Jul 2013 01:38:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F133120220 for ; Tue, 23 Jul 2013 01:38:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EB0D020203 for ; Tue, 23 Jul 2013 01:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754140Ab3GWBif (ORCPT ); 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-Spam-Status: No, score=-8.2 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 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);