From patchwork Fri May 18 09:03:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 8802 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 8779E23E37 for ; Fri, 18 May 2012 09:13:59 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3A345A180D0 for ; Fri, 18 May 2012 09:13:59 +0000 (UTC) Received: by yhpp61 with SMTP id p61so3179763yhp.11 for ; Fri, 18 May 2012 02:13:58 -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=YkwatyaTLmou6DLXy8qJ+nr5QV+rVjuvQEkuH/KPdx4=; b=NPEslUXTLoSBqhJzHS7dSF7I9q7HQ8AmJuhjkaSySdUGcgrqKkphoeI9NE3ytm0khz Vd3c/kliFOBmvcIC3zIpQ8sNKw6a1Dryy2Sp7hYdF6XY1M/bg1TuB6dp1E/QG/++Pgb+ 4og7UXsOrpI+F1Zuu5DaRIR0ln0324/L2sYErjwgWCStKP/Mm/RHCvG4DiVwa3ZfElQ2 5S3WQG9teKlB2r6YEwQpAvPMVCcF11/u0Yq0UcQ97sAo9WPYtruE8rAvh03sgXjL861b mdZEYMqqY4O+ETyLUjZXXRRB+4KQnJjirrf5xCDTzLRe6N0Lk79vn5yhpC7quWpWTuPn JZaw== Received: by 10.50.85.163 with SMTP id i3mr7751965igz.57.1337332438539; Fri, 18 May 2012 02:13:58 -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 o8csp88416ibd; Fri, 18 May 2012 02:13:58 -0700 (PDT) Received: by 10.68.192.74 with SMTP id he10mr1600277pbc.69.1337332437851; Fri, 18 May 2012 02:13:57 -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 vn7si14983873pbc.281.2012.05.18.02.13.57 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 02:13:57 -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 h15so4323463dan.37 for ; Fri, 18 May 2012 02:13:57 -0700 (PDT) Received: by 10.68.138.161 with SMTP id qr1mr8272372pbb.37.1337332437019; Fri, 18 May 2012 02:13:57 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id rf3sm11276910pbc.33.2012.05.18.02.13.53 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 02:13:56 -0700 (PDT) From: Sachin Kamat To: linux-usb@vger.kernel.org Cc: ben@simtec.co.uk, balbi@ti.com, gregkh@linuxfoundation.org, sachin.kamat@linaro.org, patches@linaro.org Subject: [PATCH 1/1] usb: s3c-hsotg: Use devm_* functions in s3c-hsotg.c file Date: Fri, 18 May 2012 14:33:46 +0530 Message-Id: <1337331826-19552-1-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-Gm-Message-State: ALoCoQmrkgW4YlatVV7WZCY4T8xB4h+3AWQ4BQ1mvBbB9Mpjeko1HQtxLXW6dARa1Cm0MYwaQ5+h devm_* functions are used to replace kzalloc, request_mem_region, ioremap and request_irq functions in probe call. With the usage of devm_* functions explicit freeing and unmapping is not required. Signed-off-by: Sachin Kamat --- drivers/usb/gadget/s3c-hsotg.c | 51 ++++++++------------------------------- 1 files changed, 11 insertions(+), 40 deletions(-) diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index f4abb0e..d375851 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c @@ -136,7 +136,6 @@ struct s3c_hsotg_ep { * @driver: USB gadget driver * @plat: The platform specific configuration data. * @regs: The memory area mapped for accessing registers. - * @regs_res: The resource that was allocated when claiming register space. * @irq: The IRQ number we are using * @supplies: Definition of USB power supplies * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. @@ -158,7 +157,6 @@ struct s3c_hsotg { struct s3c_hsotg_plat *plat; void __iomem *regs; - struct resource *regs_res; int irq; struct clk *clk; @@ -3477,7 +3475,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) return -EINVAL; } - hsotg = kzalloc(sizeof(struct s3c_hsotg), GFP_KERNEL); + hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL); if (!hsotg) { dev_err(dev, "cannot get memory\n"); return -ENOMEM; @@ -3489,46 +3487,33 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) hsotg->clk = clk_get(&pdev->dev, "otg"); if (IS_ERR(hsotg->clk)) { dev_err(dev, "cannot get otg clock\n"); - ret = PTR_ERR(hsotg->clk); - goto err_mem; + return PTR_ERR(hsotg->clk); } platform_set_drvdata(pdev, hsotg); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(dev, "cannot find register resource 0\n"); - ret = -EINVAL; - goto err_clk; - } - - hsotg->regs_res = request_mem_region(res->start, resource_size(res), - dev_name(dev)); - if (!hsotg->regs_res) { - dev_err(dev, "cannot reserve registers\n"); - ret = -ENOENT; - goto err_clk; - } - hsotg->regs = ioremap(res->start, resource_size(res)); + hsotg->regs = devm_request_and_ioremap(&pdev->dev, res); if (!hsotg->regs) { dev_err(dev, "cannot map registers\n"); ret = -ENXIO; - goto err_regs_res; + goto err_clk; } ret = platform_get_irq(pdev, 0); if (ret < 0) { dev_err(dev, "cannot find IRQ\n"); - goto err_regs; + goto err_clk; } hsotg->irq = ret; - ret = request_irq(ret, s3c_hsotg_irq, 0, dev_name(dev), hsotg); + ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0, + dev_name(dev), hsotg); if (ret < 0) { dev_err(dev, "cannot claim IRQ\n"); - goto err_regs; + goto err_clk; } dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); @@ -3558,7 +3543,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) hsotg->supplies); if (ret) { dev_err(dev, "failed to request supplies: %d\n", ret); - goto err_irq; + goto err_clk; } ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), @@ -3642,19 +3627,11 @@ err_ep_mem: err_supplies: s3c_hsotg_phy_disable(hsotg); regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); -err_irq: - free_irq(hsotg->irq, hsotg); -err_regs: - iounmap(hsotg->regs); - -err_regs_res: - release_resource(hsotg->regs_res); - kfree(hsotg->regs_res); + err_clk: clk_disable_unprepare(hsotg->clk); clk_put(hsotg->clk); -err_mem: - kfree(hsotg); + return ret; } @@ -3675,12 +3652,6 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev) usb_gadget_unregister_driver(hsotg->driver); } - free_irq(hsotg->irq, hsotg); - iounmap(hsotg->regs); - - release_resource(hsotg->regs_res); - kfree(hsotg->regs_res); - s3c_hsotg_phy_disable(hsotg); regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);