From patchwork Mon Jul 6 19:24:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 6727451 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 653F89F2F0 for ; Mon, 6 Jul 2015 19:30:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 600FC205F2 for ; Mon, 6 Jul 2015 19:30:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6A729205EB for ; Mon, 6 Jul 2015 19:30:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZCC4G-0007cs-TY; Mon, 06 Jul 2015 19:28:40 +0000 Received: from mail-pa0-f54.google.com ([209.85.220.54]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZCC40-0007HH-1I for linux-arm-kernel@lists.infradead.org; Mon, 06 Jul 2015 19:28:24 +0000 Received: by pacws9 with SMTP id ws9so101322039pac.0 for ; Mon, 06 Jul 2015 12:28:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NTGxKVHAc1RV5lwD2dK2/uWbRGcgZDTm83E+a7hDzJc=; b=fAOYMSG5lLWtUTSsxoEx5aveUwpxHV1NXx/ZVqEfknoV/K3zyIxVepUPKDOTURXm61 JbzgSxxiH3f9caLHFmTR9/5QekJYuxPaiRKucOLvTJx4xse8OfMs5mfSNtf3qGelqvaE Vr3/YvVGET2fYrwywBmXML0aIHQxy3ViD0QdPuIUX2IEAct/Beqv/wUp18tc6t+GCneP 8g8M3qbs7fyMnDaw+aZaGZumJnTf4hsjUmTO632sPzp8EjcdY2LgqASQdIW/m3un7YsF xfqjTvPu28mG9h3k+MIKL1pzLYbYJcf5DfSIe1oSqmoZPqjbP5W8SbGBdZEGFJ8kQbrM Xz0Q== X-Gm-Message-State: ALoCoQlVVUH3EuHHcluH2xV8gxwi4EdbM/9IvBUNrw0QPBIPYOt7hYWmjiUU1W6YKgh+pVmr2nrA X-Received: by 10.67.11.9 with SMTP id ee9mr787535pad.83.1436210883313; Mon, 06 Jul 2015 12:28:03 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by mx.google.com with ESMTPSA id x7sm19293964pas.28.2015.07.06.12.27.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Jul 2015 12:28:02 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Subject: [PATCH-v3 06/11] i2c:pxa: Use devm_ variants in probe function Date: Tue, 7 Jul 2015 00:54:50 +0530 Message-Id: <1436210695-19159-7-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436210695-19159-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1436210695-19159-1-git-send-email-vaibhav.hiremath@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150706_122824_108777_972C9194 X-CRM114-Status: GOOD ( 15.86 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, wsa@the-dreams.de, linux-kernel@vger.kernel.org, Vaibhav Hiremath , robh+dt@kernel.org, robert.jarzmik@free.fr, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Robert Jarzmik --- drivers/i2c/busses/i2c-pxa.c | 82 ++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 040effa..2de9300 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1158,10 +1158,22 @@ 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); + if (!res) { + dev_err(&dev->dev, "no mem resource\n"); + return -ENODEV; + } + + irq = platform_get_irq(dev, 0); + if (irq < 0) { + dev_err(&dev->dev, "no irq resource: %d\n", irq); + return irq; } /* Default adapter num to device id; i2c_pxa_probe_dt can override. */ @@ -1171,19 +1183,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; @@ -1193,16 +1193,18 @@ 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: %ld\n", + PTR_ERR(i2c->clk)); + return PTR_ERR(i2c->clk); } - i2c->reg_base = ioremap(res->start, resource_size(res)); - if (!i2c->reg_base) { - ret = -EIO; - goto eremap; + i2c->reg_base = devm_ioremap_resource(&dev->dev, res); + if (IS_ERR(i2c->reg_base)) { + dev_err(&dev->dev, "failed to map resource: %ld\n", + PTR_ERR(i2c->reg_base)); + return PTR_ERR(i2c->reg_base); } i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; @@ -1244,11 +1246,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: %d\n", ret); goto ereqirq; + } } i2c_pxa_reset(i2c); @@ -1261,33 +1265,22 @@ 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: %d\n", ret); + goto ereqirq; } platform_set_drvdata(dev, i2c); #ifdef CONFIG_I2C_PXA_SLAVE - printk(KERN_INFO "I2C: %s: PXA I2C adapter, slave address %d\n", - dev_name(&i2c->adap.dev), i2c->slave_addr); + dev_info(&i2c->adap.dev, " PXA I2C adapter, slave address %d\n", + i2c->slave_addr); #else - printk(KERN_INFO "I2C: %s: PXA I2C adapter\n", - dev_name(&i2c->adap.dev)); + dev_info(&i2c->adap.dev, " PXA I2C adapter\n"); #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; } @@ -1296,15 +1289,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; }