From patchwork Thu May 28 13:03:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 49112 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B4405202A3 for ; Thu, 28 May 2015 13:07:16 +0000 (UTC) Received: by wifx6 with SMTP id x6sf13739396wif.1 for ; Thu, 28 May 2015 06:07:16 -0700 (PDT) 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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=3vdlR+DFkxGdYsTwscpPveg9vGmsYg01oTlcGxkeCuY=; b=ZD3GWEbI85jpJbrmANf+BjUhY9ZBYcluxEppNU9p1aVqNhRxhaIbCLuxxLRi+N8TlQ QMgp/9GJAEHm9fHjA/k1nw3J2bErnYTgDZanuJzoztLGspCqGq4nWMMlfRADvf7yZSXB z7rQNgXMoQrHcS4k7slWrJ6i0JvhhNzoZbQt2Q8qZLdVLYdWxjgNPkjBynvzWFRMoZFg KtR3l44rmIvHVL4uWo3X6b2Qci45dhGG1a0EggLRTI5yusG4DhgRa1O8wKRLNTokxwy4 rnZaCoW9HvNfXKxDaYis1r0nlCZOp367vLOc9dsn0GUvP3E5bMOuX2FRsknI4gLXeq2I 8K5g== X-Gm-Message-State: ALoCoQnE9NwNsj9Gl7HBpDBRXrHA34TEaco0imP2qsPA/n06mZpjYyUggPQ6kCUgrX3L7pgmpEB8 X-Received: by 10.112.29.39 with SMTP id g7mr2657610lbh.1.1432818436038; Thu, 28 May 2015 06:07:16 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.101 with SMTP id r5ls170652lar.78.gmail; Thu, 28 May 2015 06:07:15 -0700 (PDT) X-Received: by 10.152.1.227 with SMTP id 3mr2674680lap.61.1432818435885; Thu, 28 May 2015 06:07:15 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id o2si1919931lbl.51.2015.05.28.06.07.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2015 06:07:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labpy14 with SMTP id py14so19450298lab.0 for ; Thu, 28 May 2015 06:07:15 -0700 (PDT) X-Received: by 10.112.150.100 with SMTP id uh4mr2661657lbb.112.1432818435776; Thu, 28 May 2015 06:07:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1144741lbb; Thu, 28 May 2015 06:07:14 -0700 (PDT) X-Received: by 10.66.216.70 with SMTP id oo6mr5396662pac.24.1432818433917; Thu, 28 May 2015 06:07:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gc5si3585834pac.51.2015.05.28.06.07.13; Thu, 28 May 2015 06:07:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753857AbbE1NHL (ORCPT + 1 other); Thu, 28 May 2015 09:07:11 -0400 Received: from mail-pd0-f178.google.com ([209.85.192.178]:34722 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753357AbbE1NHG (ORCPT ); Thu, 28 May 2015 09:07:06 -0400 Received: by pdbki1 with SMTP id ki1so41553074pdb.1 for ; Thu, 28 May 2015 06:07:06 -0700 (PDT) X-Received: by 10.68.218.103 with SMTP id pf7mr5435030pbc.32.1432818425995; Thu, 28 May 2015 06:07:05 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by mx.google.com with ESMTPSA id dc5sm2392557pbc.53.2015.05.28.06.07.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 May 2015 06:07:04 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , linux-arm-kernel@lists.infradead.org, Vaibhav Hiremath Subject: [PATCH 11/12] i2c:pxa: Use devm_ variants in probe function Date: Thu, 28 May 2015 18:33:43 +0530 Message-Id: <1432818224-17070-12-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432818224-17070-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1432818224-17070-1-git-send-email-vaibhav.hiremath@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-i2c@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: vaibhav.hiremath@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch cleans up i2c_pxa_probe() function, - Use devm_ variants wherever This will clean both probe exit and i2c_pxa_remove() functions - Check platform resource before parsing any other data from DT/platform - Use dev_err on failure from i2c_add_numbered_adapter() - Use pr_info instead of printk for KERN_INFO Signed-off-by: Vaibhav Hiremath --- drivers/i2c/busses/i2c-pxa.c | 71 ++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 065e647..844e1fc 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1270,10 +1270,17 @@ static int i2c_pxa_probe(struct platform_device *dev) struct resource *res = NULL; int ret, irq; - i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL); + i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); if (!i2c) { - ret = -ENOMEM; - goto emalloc; + dev_err(&dev->dev, "memory allocation failed\n"); + return -ENOMEM; + } + + res = platform_get_resource(dev, IORESOURCE_MEM, 0); + irq = platform_get_irq(dev, 0); + if (res == NULL || irq < 0) { + dev_err(&dev->dev, "no mem/irq resource\n"); + return -ENODEV; } /* Default adapter num to device id; i2c_pxa_probe_dt can override. */ @@ -1283,19 +1290,7 @@ static int i2c_pxa_probe(struct platform_device *dev) if (ret > 0) ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); if (ret < 0) - goto eclk; - - res = platform_get_resource(dev, IORESOURCE_MEM, 0); - irq = platform_get_irq(dev, 0); - if (res == NULL || irq < 0) { - ret = -ENODEV; - goto eclk; - } - - if (!request_mem_region(res->start, resource_size(res), res->name)) { - ret = -ENOMEM; - goto eclk; - } + return ret; i2c->adap.owner = THIS_MODULE; i2c->adap.retries = 5; @@ -1305,16 +1300,16 @@ static int i2c_pxa_probe(struct platform_device *dev) strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name)); - i2c->clk = clk_get(&dev->dev, NULL); + i2c->clk = devm_clk_get(&dev->dev, NULL); if (IS_ERR(i2c->clk)) { - ret = PTR_ERR(i2c->clk); - goto eclk; + dev_err(&dev->dev, "failed to get the clk\n"); + return PTR_ERR(i2c->clk); } - i2c->reg_base = ioremap(res->start, resource_size(res)); + i2c->reg_base = devm_ioremap_resource(&dev->dev, res); if (!i2c->reg_base) { - ret = -EIO; - goto eremap; + dev_err(&dev->dev, "failed to map resource\n"); + return -EIO; } i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; @@ -1361,11 +1356,13 @@ static int i2c_pxa_probe(struct platform_device *dev) i2c->adap.algo = &i2c_pxa_pio_algorithm; } else { i2c->adap.algo = &i2c_pxa_algorithm; - ret = request_irq(irq, i2c_pxa_handler, + ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler, IRQF_SHARED | IRQF_NO_SUSPEND, dev_name(&dev->dev), i2c); - if (ret) + if (ret) { + dev_err(&dev->dev, "failed to request irq\n"); goto ereqirq; + } } i2c_pxa_reset(i2c); @@ -1380,8 +1377,8 @@ static int i2c_pxa_probe(struct platform_device *dev) ret = i2c_add_numbered_adapter(&i2c->adap); if (ret < 0) { - printk(KERN_INFO "I2C: Failed to add bus\n"); - goto eadapt; + dev_err(&dev->dev, "failed to add bus\n"); + goto ereqirq; } platform_set_drvdata(dev, i2c); @@ -1411,26 +1408,15 @@ static int i2c_pxa_probe(struct platform_device *dev) } } #ifdef CONFIG_I2C_PXA_SLAVE - printk(KERN_INFO "I2C: %s: PXA I2C adapter, slave address %d\n", + pr_info("I2C: %s: PXA I2C adapter, slave address %d\n", dev_name(&i2c->adap.dev), i2c->slave_addr); #else - printk(KERN_INFO "I2C: %s: PXA I2C adapter\n", - dev_name(&i2c->adap.dev)); + pr_info("I2C: %s: PXA I2C adapter\n", dev_name(&i2c->adap.dev)); #endif return 0; -eadapt: - if (!i2c->use_pio) - free_irq(irq, i2c); ereqirq: clk_disable_unprepare(i2c->clk); - iounmap(i2c->reg_base); -eremap: - clk_put(i2c->clk); -eclk: - kfree(i2c); -emalloc: - release_mem_region(res->start, resource_size(res)); return ret; } @@ -1439,15 +1425,8 @@ static int i2c_pxa_remove(struct platform_device *dev) struct pxa_i2c *i2c = platform_get_drvdata(dev); i2c_del_adapter(&i2c->adap); - if (!i2c->use_pio) - free_irq(i2c->irq, i2c); clk_disable_unprepare(i2c->clk); - clk_put(i2c->clk); - - iounmap(i2c->reg_base); - release_mem_region(i2c->iobase, i2c->iosize); - kfree(i2c); return 0; }