From patchwork Tue Feb 18 22:20:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 24916 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2F767203BE for ; Tue, 18 Feb 2014 22:20:30 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id rd3sf42515840pab.3 for ; Tue, 18 Feb 2014 14:20:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=QJbsrM9NPhJET9PW5EWUVVhlBs6VqFsjGyFZnDzTdqw=; b=XSAdK+DZ6pQCrOZnJSyRIOEdZws3nPZgciQV2k1xp8ILwRHCVZPuuH9ETdMQHkltx3 xAJ6BmggVo4KsCNJvhfx+T89icFnDHpLPWK7GtbXgM1VrPR49RDJ7J5wT9TjbS+tzVYa KxzB7mWuWDYUPB0+JbUz3Re6PKeRh3oGAKzmwQChNiej1kBsv31gBtuzNDJbtvRedIgZ Zf/hBj2kf8ldgNkU/stlqw9r//tU181VKtbRDT6ER8cVgmzdVmPZ5nmc99d+Uwo/uReU Q6cqcSciRV2Zzv/avM/2A+Y0ea/68/4/UP1YoqXOX+48ULfJjWzk7rn5p35UYVSjlmWC IPGQ== X-Gm-Message-State: ALoCoQnVALLxWWaEg0Oc+1PRMvyGuW/skEVljSTx6C5m1bH1AfkEyJXObjb0PNyX7Y+hFrLsv3Ra X-Received: by 10.66.253.9 with SMTP id zw9mr14780205pac.38.1392762029389; Tue, 18 Feb 2014 14:20:29 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.98 with SMTP id j89ls1495449qga.73.gmail; Tue, 18 Feb 2014 14:20:29 -0800 (PST) X-Received: by 10.220.95.139 with SMTP id d11mr18746141vcn.21.1392762029179; Tue, 18 Feb 2014 14:20:29 -0800 (PST) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id v7si5959679vet.28.2014.02.18.14.20.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 14:20:29 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id la4so13520650vcb.21 for ; Tue, 18 Feb 2014 14:20:29 -0800 (PST) X-Received: by 10.52.171.39 with SMTP id ar7mr19157454vdc.5.1392762029060; Tue, 18 Feb 2014 14:20:29 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp251020vcz; Tue, 18 Feb 2014 14:20:28 -0800 (PST) X-Received: by 10.152.6.132 with SMTP id b4mr309057laa.64.1392762027749; Tue, 18 Feb 2014 14:20:27 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by mx.google.com with ESMTPS id l9si34009173lbd.164.2014.02.18.14.20.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 14:20:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.217.179 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id l4so12881348lbv.10 for ; Tue, 18 Feb 2014 14:20:26 -0800 (PST) X-Received: by 10.112.45.108 with SMTP id l12mr22295108lbm.21.1392762026568; Tue, 18 Feb 2014 14:20:26 -0800 (PST) Received: from linaro-ulf.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id ri4sm25146694lbb.6.2014.02.18.14.20.24 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 14:20:25 -0800 (PST) From: Ulf Hansson To: Alessandro Rubini , Linus Walleij , Wolfram Sang , linux-i2c@vger.kernel.org Cc: Russell King , linux-arm-kernel@lists.infradead.org, Mark Brown , Ulf Hansson Subject: [PATCH V4 11/17] i2c: nomadik: Convert to devm functions Date: Tue, 18 Feb 2014 23:20:22 +0100 Message-Id: <1392762022-10871-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Use devm_* functions to simplify code and error handling. Cc: Alessandro Rubini Cc: Linus Walleij Cc: Wolfram Sang Signed-off-by: Ulf Hansson --- Changes in v4: Rebased on top of Linus Walleij's v2 patch: "i2c: nomadik: factor platform data into state container" Note, only this patch needed to be rebased in the patchset. --- drivers/i2c/busses/i2c-nomadik.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index b0b9390..cd15c03 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -976,7 +976,12 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) struct i2c_vendor_data *vendor = id->data; u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1; - dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); + if (!np) { + dev_err(&adev->dev, "no device node\n"); + return -ENODEV; + } + + dev = devm_kzalloc(&adev->dev, sizeof(struct nmk_i2c_dev), GFP_KERNEL); if (!dev) { dev_err(&adev->dev, "cannot allocate memory\n"); ret = -ENOMEM; @@ -1006,27 +1011,28 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) /* If possible, let's go to idle until the first transfer */ pinctrl_pm_select_idle_state(&adev->dev); - dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); - if (!dev->virtbase) { + dev->virtbase = devm_ioremap(&adev->dev, adev->res.start, + resource_size(&adev->res)); + if (IS_ERR(dev->virtbase)) { ret = -ENOMEM; - goto err_no_ioremap; + goto err_no_mem; } dev->irq = adev->irq[0]; - ret = request_irq(dev->irq, i2c_irq_handler, 0, + ret = devm_request_irq(&adev->dev, dev->irq, i2c_irq_handler, 0, DRIVER_NAME, dev); if (ret) { dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq); - goto err_irq; + goto err_no_mem; } pm_suspend_ignore_children(&adev->dev, true); - dev->clk = clk_get(&adev->dev, NULL); + dev->clk = devm_clk_get(&adev->dev, NULL); if (IS_ERR(dev->clk)) { dev_err(&adev->dev, "could not get i2c clock\n"); ret = PTR_ERR(dev->clk); - goto err_no_clk; + goto err_no_mem; } adap = &dev->adap; @@ -1048,21 +1054,13 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) ret = i2c_add_adapter(adap); if (ret) { dev_err(&adev->dev, "failed to add adapter\n"); - goto err_add_adap; + goto err_no_mem; } pm_runtime_put(&adev->dev); return 0; - err_add_adap: - clk_put(dev->clk); - err_no_clk: - free_irq(dev->irq, dev); - err_irq: - iounmap(dev->virtbase); - err_no_ioremap: - kfree(dev); err_no_mem: return ret; @@ -1079,13 +1077,9 @@ static int nmk_i2c_remove(struct amba_device *adev) clear_all_interrupts(dev); /* disable the controller */ i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE); - free_irq(dev->irq, dev); - iounmap(dev->virtbase); if (res) release_mem_region(res->start, resource_size(res)); - clk_put(dev->clk); pm_runtime_disable(&adev->dev); - kfree(dev); return 0; }