From patchwork Wed May 9 14:19:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannu Heikkinen X-Patchwork-Id: 157971 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-we0-f184.google.com (mail-we0-f184.google.com [74.125.82.184]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 0826BB6FAF for ; Thu, 10 May 2012 00:19:19 +1000 (EST) Received: by werb14 with SMTP id b14sf213339wer.11 for ; Wed, 09 May 2012 07:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=ajuew804bFQHKJsrs9iRO53KcIlVmEAEyFzKwN8SMqs=; b=Q04YJa+zkPHIfIkwyarDnfoNEUP2aVO38Agbj2zaRgbYYXfZ7wvLMuaU8wm/eFKLQE XwkmPnDohcks1xqfRV9Je/fh3Kd/lGXmw2R91n1MRxi8fPqaQgIaLhcR2RgZ4VPZI8uL VGnd7UjgOw9uJ93QKOcERWHmdeZBs9DT3j5y8= Received: by 10.204.145.68 with SMTP id c4mr14955bkv.27.1336573155770; Wed, 09 May 2012 07:19:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.204.130.152 with SMTP id t24ls4069337bks.1.gmail; Wed, 09 May 2012 07:19:15 -0700 (PDT) Received: by 10.205.122.65 with SMTP id gf1mr49768bkc.2.1336573154915; Wed, 09 May 2012 07:19:14 -0700 (PDT) Received: by 10.205.122.65 with SMTP id gf1mr49767bkc.2.1336573154721; Wed, 09 May 2012 07:19:14 -0700 (PDT) Received: from relay.sigmatic.fi (relay.sigmatic.fi. [80.69.161.51]) by gmr-mx.google.com with ESMTPS id p5si3302881bks.1.2012.05.09.07.19.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 May 2012 07:19:14 -0700 (PDT) Received-SPF: pass (google.com: domain of hannuxx@iki.fi designates 80.69.161.51 as permitted sender) client-ip=80.69.161.51; Received: (qmail 15109 invoked from network); 9 May 2012 14:19:13 -0000 Received: from unknown (HELO localhost) (hannu@apokalypsis.fi@88.115.119.222) by mail1.sigmatic.fi with ESMTPA; 9 May 2012 14:19:13 -0000 From: Hannu Heikkinen To: linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com Cc: a.zummo@towertech.it, swarren@wwwdotorg.org Subject: [rtc-linux] [PATCH RESEND] rtc: tegra: cleanup probe/remove routines Date: Wed, 9 May 2012 17:19:11 +0300 Message-Id: <1336573151-8984-1-git-send-email-hannuxx@iki.fi> X-Mailer: git-send-email 1.7.10 X-Original-Sender: hannuxx@iki.fi X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of hannuxx@iki.fi designates 80.69.161.51 as permitted sender) smtp.mail=hannuxx@iki.fi Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , From: Hannu Heikkinen Use the devres managed resource functions in the probe routine. Affects also in remove routine where previously used free and release functions are not needed. The devm_* functions eliminate the need for manual resource releasing and simplify error handling. Resources allocated by devm_* are freed automatically on driver detach. Acked-by: Stephen Warren Signed-off-by: Hannu Heikkinen --- drivers/rtc/rtc-tegra.c | 50 ++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c index 75259fe..c006025 100644 --- a/drivers/rtc/rtc-tegra.c +++ b/drivers/rtc/rtc-tegra.c @@ -309,7 +309,8 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) struct resource *res; int ret; - info = kzalloc(sizeof(struct tegra_rtc_info), GFP_KERNEL); + info = devm_kzalloc(&pdev->dev, sizeof(struct tegra_rtc_info), + GFP_KERNEL); if (!info) return -ENOMEM; @@ -317,29 +318,18 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) if (!res) { dev_err(&pdev->dev, "Unable to allocate resources for device.\n"); - ret = -EBUSY; - goto err_free_info; + return -EBUSY; } - if (!request_mem_region(res->start, resource_size(res), pdev->name)) { - dev_err(&pdev->dev, - "Unable to request mem region for device.\n"); - ret = -EBUSY; - goto err_free_info; + info->rtc_base = devm_request_and_ioremap(&pdev->dev, res); + if (!info->rtc_base) { + dev_err(&pdev->dev, "Unable to request mem region and grab IOs for device.\n"); + return -EBUSY; } info->tegra_rtc_irq = platform_get_irq(pdev, 0); - if (info->tegra_rtc_irq <= 0) { - ret = -EBUSY; - goto err_release_mem_region; - } - - info->rtc_base = ioremap_nocache(res->start, resource_size(res)); - if (!info->rtc_base) { - dev_err(&pdev->dev, "Unable to grab IOs for device.\n"); - ret = -EBUSY; - goto err_release_mem_region; - } + if (info->tegra_rtc_irq <= 0) + return -EBUSY; /* set context info. */ info->pdev = pdev; @@ -362,11 +352,12 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Unable to register device (err=%d).\n", ret); - goto err_iounmap; + return ret; } - ret = request_irq(info->tegra_rtc_irq, tegra_rtc_irq_handler, - IRQF_TRIGGER_HIGH, "rtc alarm", &pdev->dev); + ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq, + tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH, + "rtc alarm", &pdev->dev); if (ret) { dev_err(&pdev->dev, "Unable to request interrupt for device (err=%d).\n", @@ -380,12 +371,6 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) err_dev_unreg: rtc_device_unregister(info->rtc_dev); -err_iounmap: - iounmap(info->rtc_base); -err_release_mem_region: - release_mem_region(res->start, resource_size(res)); -err_free_info: - kfree(info); return ret; } @@ -393,17 +378,8 @@ err_free_info: static int __devexit tegra_rtc_remove(struct platform_device *pdev) { struct tegra_rtc_info *info = platform_get_drvdata(pdev); - struct resource *res; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -EBUSY; - free_irq(info->tegra_rtc_irq, &pdev->dev); rtc_device_unregister(info->rtc_dev); - iounmap(info->rtc_base); - release_mem_region(res->start, resource_size(res)); - kfree(info); platform_set_drvdata(pdev, NULL);