From patchwork Sat Nov 10 11:34:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaik Ameer Basha X-Patchwork-Id: 1723591 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 3225EDFE7E for ; Sat, 10 Nov 2012 11:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751210Ab2KJLNZ (ORCPT ); Sat, 10 Nov 2012 06:13:25 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:38944 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751267Ab2KJLNY (ORCPT ); Sat, 10 Nov 2012 06:13:24 -0500 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MD900J6HR69VJ90@mailout2.samsung.com> for linux-fbdev@vger.kernel.org; Sat, 10 Nov 2012 20:13:22 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.126]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 4C.96.01231.2D63E905; Sat, 10 Nov 2012 20:13:22 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-a0-509e36d24782 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id CB.96.01231.2D63E905; Sat, 10 Nov 2012 20:13:22 +0900 (KST) Received: from localhost.localdomain ([107.108.73.106]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MD90003RR60HY40@mmp2.samsung.com> for linux-fbdev@vger.kernel.org; Sat, 10 Nov 2012 20:13:22 +0900 (KST) From: Shaik Ameer Basha To: linux-fbdev@vger.kernel.org Cc: inki.dae@samsung.com, dh09.lee@samsung.com, FlorianSchandinat@gmx.de, s.nawrocki@samsung.com, kgene.kim@samsung.com Subject: [PATCH 1/2] exynos-mipi-dsi: using devm_ functions for automatic cleanup Date: Sat, 10 Nov 2012 17:04:44 +0530 Message-id: <1352547285-12302-2-git-send-email-shaik.ameer@samsung.com> X-Mailer: git-send-email 1.7.0.4 In-reply-to: <1352547285-12302-1-git-send-email-shaik.ameer@samsung.com> References: <1352547285-12302-1-git-send-email-shaik.ameer@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFLMWRmVeSWpSXmKPExsWyRsSkTveS2bwAg9aD5hYn+j6wOjB6fN4k F8AYxWWTkpqTWZZapG+XwJWx61A3W8EkrYoNPz4zNzDeVOpi5OSQEDCReN/bywphi0lcuLee rYuRi0NIYCmjxOOpfUAJDrCi4zuMIeLTGSWu3tvDBOEsZ5LY++AUC0g3m4ChxPZ7V8AmiQjI S+zpb2cCsZkFKiXuL/jEBmILCwRLdD+/ChZnEVCVeLqqlxHE5hVwl1h6+yczxBUKEq3LDrGD 2JwCHhJfZm1jBzlCCKjm0wV7iFYBiW+TD7FA3CYrsekAM8g5EgLX2SRe730HNUZS4uCKGywT GIUXMDKsYhRNLUguKE5KzzXUK07MLS7NS9dLzs/dxAgMwNP/nkntYFzZYHGIUYCDUYmHlyN0 boAQa2JZcWXuIUYJDmYlEd4w7XkBQrwpiZVVqUX58UWlOanFhxh9gC6ZyCwlmpwPjI68knhD YxNzU2NTSyMjM1NTHMJK4rzNHikBQgLpiSWp2ampBalFMOOYODilGhgnWt/yucVzS9lX2WfK kU/BN5o6/9UwLCnQs0h1yV3zz0W67OyPJ6+4udeLtGY8qPvUGXfgpeKu9Vtby9Yu8lDim7j4 QZl/QEdNHv+OkrVSs3dyqzLlrL56yUdOdNvzs2c4nt9NSZC7++iC8+rImiDxJh0LLb7tE6pX TNd5UBzyfIWMQq2eroASS3FGoqEWc1FxIgBQDMiJbQIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkkeLIzCtJLcpLzFFi42I5/e+xoO4ls3kBBh8+q1ic6PvA6sDo8XmT XABjVAOjTUZqYkpqkUJqXnJ+SmZeuq2Sd3C8c7ypmYGhrqGlhbmSQl5ibqqtkotPgK5bZg7Q VCWFssScUqBQQGJxsZK+HaYJoSFuuhYwjRG6viFBcD1GBmggYQ1jxq5D3WwFk7QqNvz4zNzA eFOpi5GDQ0LAROL4DuMuRk4gU0ziwr31bF2MXBxCAtMZJa7e28ME4Sxnktj74BQLSBWbgKHE 9ntXWEFsEQF5iT397UwgNrNApcT9BZ/YQGxhgWCJ7udXweIsAqoST1f1MoLYvALuEktv/2SG 2KYg0brsEDuIzSngIfFl1jZ2kIOEgGo+XbCfwMi7gJFhFaNoakFyQXFSeq6hXnFibnFpXrpe cn7uJkZweD+T2sG4ssHiEKMAB6MSDy9H6NwAIdbEsuLK3EOMEhzMSiK8YdrzAoR4UxIrq1KL 8uOLSnNSiw8x+gAdNZFZSjQ5Hxh7eSXxhsYm5qbGppYmFiZmljiElcR5mz1SAoQE0hNLUrNT UwtSi2DGMXFwSjUwsr4z3i38IrWv49c57roXb+Nn3WfbIiI76WDyYaHPRQ4KNx9Ns+582NHL +Mc1JuqqVSDjRcc5b/b4rqvizn53xFQt79tHQd3Sz+te/HygH7p6850LByL3JOT9/Gz6fsEk hsimn6937XeY2rNS4Pn3U75ZU/13317Fk1ufwRTrv+6H0usXrY4C+5RYijMSDbWYi4oTAbY3 uAacAgAA X-CFilter-Loop: Reflected Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Using devm_ functions will take care of cleaning the allocated resources when the device is removed. Change-Id: Ia904a65ebdfe15a69c7c16501b3d94dd41f69bf4 Signed-off-by: Shaik Ameer Basha --- drivers/video/exynos/exynos_mipi_dsi.c | 76 ++++++++----------------------- 1 files changed, 20 insertions(+), 56 deletions(-) diff --git a/drivers/video/exynos/exynos_mipi_dsi.c b/drivers/video/exynos/exynos_mipi_dsi.c index 1f5de89..ae20bc3 100755 --- a/drivers/video/exynos/exynos_mipi_dsi.c +++ b/drivers/video/exynos/exynos_mipi_dsi.c @@ -338,7 +338,8 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev) struct mipi_dsim_ddi *dsim_ddi; int ret = -EINVAL; - dsim = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL); + dsim = devm_kzalloc(&pdev->dev, + sizeof(struct mipi_dsim_device), GFP_KERNEL); if (!dsim) { dev_err(&pdev->dev, "failed to allocate dsim object.\n"); return -ENOMEM; @@ -352,13 +353,13 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev) dsim_pd = (struct mipi_dsim_platform_data *)dsim->pd; if (dsim_pd == NULL) { dev_err(&pdev->dev, "failed to get platform data for dsim.\n"); - goto err_clock_get; + return -EFAULT; } /* get mipi_dsim_config. */ dsim_config = dsim_pd->dsim_config; if (dsim_config == NULL) { dev_err(&pdev->dev, "failed to get dsim config data.\n"); - goto err_clock_get; + return -EFAULT; } dsim->dsim_config = dsim_config; @@ -366,41 +367,28 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev) mutex_init(&dsim->lock); - ret = regulator_bulk_get(&pdev->dev, ARRAY_SIZE(supplies), supplies); + ret = devm_regulator_bulk_get(&pdev->dev, + ARRAY_SIZE(supplies), supplies); if (ret) { dev_err(&pdev->dev, "Failed to get regulators: %d\n", ret); - goto err_clock_get; + return ret; } - dsim->clock = clk_get(&pdev->dev, "dsim0"); + dsim->clock = devm_clk_get(&pdev->dev, "dsim0"); if (IS_ERR(dsim->clock)) { dev_err(&pdev->dev, "failed to get dsim clock source\n"); - ret = -ENODEV; - goto err_clock_get; + return PTR_ERR(dsim->clock); } clk_enable(dsim->clock); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(&pdev->dev, "failed to get io memory region\n"); - ret = -ENODEV; - goto err_platform_get; - } - - dsim->res = request_mem_region(res->start, resource_size(res), - dev_name(&pdev->dev)); - if (!dsim->res) { - dev_err(&pdev->dev, "failed to request io memory region\n"); - ret = -ENOMEM; - goto err_mem_region; - } - dsim->reg_base = ioremap(res->start, resource_size(res)); + dsim->reg_base = devm_request_and_ioremap(&pdev->dev, res); if (!dsim->reg_base) { - dev_err(&pdev->dev, "failed to remap io region\n"); - ret = -ENOMEM; - goto err_ioremap; + dev_err(&pdev->dev, "failed to map registers\n"); + ret = -ENXIO; + goto cleanup_clk; } mutex_init(&dsim->lock); @@ -409,27 +397,28 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev) dsim_ddi = exynos_mipi_dsi_bind_lcd_ddi(dsim, dsim_pd->lcd_panel_name); if (!dsim_ddi) { dev_err(&pdev->dev, "mipi_dsim_ddi object not found.\n"); - ret = -EINVAL; - goto err_bind; + ret = -ENXIO; + goto cleanup_clk; } dsim->irq = platform_get_irq(pdev, 0); if (dsim->irq < 0) { dev_err(&pdev->dev, "failed to request dsim irq resource\n"); ret = -EINVAL; - goto err_platform_get_irq; + goto cleanup_clk; } init_completion(&dsim_wr_comp); init_completion(&dsim_rd_comp); platform_set_drvdata(pdev, dsim); - ret = request_irq(dsim->irq, exynos_mipi_dsi_interrupt_handler, + ret = devm_request_irq(&pdev->dev, dsim->irq, + exynos_mipi_dsi_interrupt_handler, IRQF_SHARED, dev_name(&pdev->dev), dsim); if (ret != 0) { dev_err(&pdev->dev, "failed to request dsim irq\n"); ret = -EINVAL; - goto err_bind; + goto cleanup_clk; } /* enable interrupts */ @@ -464,29 +453,13 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev) dsim->suspended = false; done: - platform_set_drvdata(pdev, dsim); - dev_dbg(&pdev->dev, "%s() completed sucessfuly (%s mode)\n", __func__, dsim_config->e_interface == DSIM_COMMAND ? "CPU" : "RGB"); return 0; -err_bind: - iounmap(dsim->reg_base); - -err_ioremap: - release_mem_region(dsim->res->start, resource_size(dsim->res)); - -err_mem_region: - release_resource(dsim->res); - -err_platform_get: +cleanup_clk: clk_disable(dsim->clock); - clk_put(dsim->clock); -err_clock_get: - kfree(dsim); - -err_platform_get_irq: return ret; } @@ -496,13 +469,7 @@ static int __devexit exynos_mipi_dsi_remove(struct platform_device *pdev) struct mipi_dsim_ddi *dsim_ddi, *next; struct mipi_dsim_lcd_driver *dsim_lcd_drv; - iounmap(dsim->reg_base); - clk_disable(dsim->clock); - clk_put(dsim->clock); - - release_resource(dsim->res); - release_mem_region(dsim->res->start, resource_size(dsim->res)); list_for_each_entry_safe(dsim_ddi, next, &dsim_ddi_list, list) { if (dsim_ddi) { @@ -518,9 +485,6 @@ static int __devexit exynos_mipi_dsi_remove(struct platform_device *pdev) } } - regulator_bulk_free(ARRAY_SIZE(supplies), supplies); - kfree(dsim); - return 0; }