From patchwork Mon May 14 09:31:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 8582 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id EA7E023EAB for ; Mon, 14 May 2012 09:41:28 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9BA03A184DE for ; Mon, 14 May 2012 09:41:28 +0000 (UTC) Received: by ggnf1 with SMTP id f1so3122873ggn.11 for ; Mon, 14 May 2012 02:41:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=a81HHC2vHqa+aAPomvXNSJ+XMcVCn6eeW6UTBcqcCkI=; b=Ml5+km18ZzIsUmJrAwTAVaTnqsnGz12Y7nDgCVBIv6aNDTBC3qx/t/rWMU/Koyh6Jk kFq76ZZHKrWPOEr09DrvdmFyndIErmMph7cmIS8PcK/u6mERtYEt+9ptjgDk7FrUw/mj saF4X+wKVFSZm1c+PeiUaWLg7x+ZzhfTJDxnw0XYg10CpDxM9DQZSSSve+JOmuaYiGQX D0d/KsXLJKrFCewFmTjEyzkFUTGP1dAvmY39q2YxKljW8a2ig7nmr3mnK2gigXRScXS0 88FiNueGG5RZBNPkShyxDSlFE6j3toxjAI/wWKUlMXKh5jnh1X0a6PiLcf/o5rFEEsbS RZJA== Received: by 10.50.85.163 with SMTP id i3mr3754200igz.57.1336988487836; Mon, 14 May 2012 02:41:27 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp330084ibd; Mon, 14 May 2012 02:41:26 -0700 (PDT) Received: by 10.68.236.129 with SMTP id uu1mr1301950pbc.77.1336988486578; Mon, 14 May 2012 02:41:26 -0700 (PDT) Received: from mail-pz0-f50.google.com (mail-pz0-f50.google.com [209.85.210.50]) by mx.google.com with ESMTPS id gt5si22175774pbc.182.2012.05.14.02.41.26 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 May 2012 02:41:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.210.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) smtp.mail=sachin.kamat@linaro.org Received: by danh15 with SMTP id h15so7072769dan.37 for ; Mon, 14 May 2012 02:41:26 -0700 (PDT) Received: by 10.68.196.138 with SMTP id im10mr937473pbc.47.1336988486247; Mon, 14 May 2012 02:41:26 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id kd6sm21779383pbc.24.2012.05.14.02.41.22 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 May 2012 02:41:25 -0700 (PDT) From: Sachin Kamat To: linux-media@vger.kernel.org Cc: mchehab@infradead.org, k.debski@samsung.com, sachin.kamat@linaro.org, patches@linaro.org Subject: [PATCH] s5p-g2d: Use devm_* functions in g2d.c file Date: Mon, 14 May 2012 15:01:24 +0530 Message-Id: <1336987884-23665-1-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-Gm-Message-State: ALoCoQk7DNscJpWwyq9eeq1LhIgZrux6fMM5fIUCqaKeyIxQv87+jEp4j6RvzBnJeCodR+uw0yib devm_* functions are device managed functions and make error handling and cleanup simpler. Signed-off-by: Sachin Kamat --- drivers/media/video/s5p-g2d/g2d.c | 47 ++++++++---------------------------- drivers/media/video/s5p-g2d/g2d.h | 1 - 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/drivers/media/video/s5p-g2d/g2d.c b/drivers/media/video/s5p-g2d/g2d.c index 789de74..5a11d37 100644 --- a/drivers/media/video/s5p-g2d/g2d.c +++ b/drivers/media/video/s5p-g2d/g2d.c @@ -674,42 +674,27 @@ static int g2d_probe(struct platform_device *pdev) struct resource *res; int ret = 0; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; + spin_lock_init(&dev->ctrl_lock); mutex_init(&dev->mutex); atomic_set(&dev->num_inst, 0); init_waitqueue_head(&dev->irq_queue); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(&pdev->dev, "failed to find registers\n"); - ret = -ENOENT; - goto free_dev; - } - dev->res_regs = request_mem_region(res->start, resource_size(res), - dev_name(&pdev->dev)); - - if (!dev->res_regs) { - dev_err(&pdev->dev, "failed to obtain register region\n"); - ret = -ENOENT; - goto free_dev; - } - - dev->regs = ioremap(res->start, resource_size(res)); - if (!dev->regs) { - dev_err(&pdev->dev, "failed to map registers\n"); - ret = -ENOENT; - goto rel_res_regs; + dev->regs = devm_request_and_ioremap(&pdev->dev, res); + if (dev->regs == NULL) { + dev_err(&pdev->dev, "Failed to obtain io memory\n"); + return -ENOENT; } dev->clk = clk_get(&pdev->dev, "sclk_fimg2d"); if (IS_ERR_OR_NULL(dev->clk)) { dev_err(&pdev->dev, "failed to get g2d clock\n"); - ret = -ENXIO; - goto unmap_regs; + return -ENXIO; } ret = clk_prepare(dev->clk); @@ -740,7 +725,8 @@ static int g2d_probe(struct platform_device *pdev) dev->irq = res->start; - ret = request_irq(dev->irq, g2d_isr, 0, pdev->name, dev); + ret = devm_request_irq(&pdev->dev, dev->irq, g2d_isr, + 0, pdev->name, dev); if (ret) { dev_err(&pdev->dev, "failed to install IRQ\n"); goto put_clk_gate; @@ -749,7 +735,7 @@ static int g2d_probe(struct platform_device *pdev) dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); if (IS_ERR(dev->alloc_ctx)) { ret = PTR_ERR(dev->alloc_ctx); - goto rel_irq; + goto unprep_clk_gate; } ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); @@ -793,8 +779,6 @@ unreg_v4l2_dev: v4l2_device_unregister(&dev->v4l2_dev); alloc_ctx_cleanup: vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); -rel_irq: - free_irq(dev->irq, dev); unprep_clk_gate: clk_unprepare(dev->gate); put_clk_gate: @@ -803,12 +787,7 @@ unprep_clk: clk_unprepare(dev->clk); put_clk: clk_put(dev->clk); -unmap_regs: - iounmap(dev->regs); -rel_res_regs: - release_resource(dev->res_regs); -free_dev: - kfree(dev); + return ret; } @@ -821,14 +800,10 @@ static int g2d_remove(struct platform_device *pdev) video_unregister_device(dev->vfd); v4l2_device_unregister(&dev->v4l2_dev); vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); - free_irq(dev->irq, dev); clk_unprepare(dev->gate); clk_put(dev->gate); clk_unprepare(dev->clk); clk_put(dev->clk); - iounmap(dev->regs); - release_resource(dev->res_regs); - kfree(dev); return 0; } diff --git a/drivers/media/video/s5p-g2d/g2d.h b/drivers/media/video/s5p-g2d/g2d.h index 1b82065..6b765b0 100644 --- a/drivers/media/video/s5p-g2d/g2d.h +++ b/drivers/media/video/s5p-g2d/g2d.h @@ -23,7 +23,6 @@ struct g2d_dev { spinlock_t ctrl_lock; atomic_t num_inst; struct vb2_alloc_ctx *alloc_ctx; - struct resource *res_regs; void __iomem *regs; struct clk *clk; struct clk *gate;