From patchwork Tue Jul 14 07:36:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 51089 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 82446202B9 for ; Tue, 14 Jul 2015 07:39:58 +0000 (UTC) Received: by lbvb1 with SMTP id b1sf509234lbv.3 for ; Tue, 14 Jul 2015 00:39:57 -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=TnOH7GcKnCWIqwGkw7Sy0gB2KLoFDKEK5uuSQZs+13M=; b=MIU42cR8ofcAFKF6j+OqmF1ZcIYlTtcJNc8ivOkZDQMq+gActsZqdeowoqkztgq3zl OemqtKUawEUHo2nlZnE8Kj+duJlAM7ImCvUSkl6HDqXpVAZe9sALS/bd0HAME3OUZZg2 IBXCQOoweHngTGr6++FgQ96GHdW9VZwFf6l9I6A9D085s706JQQVV0UEglMCfI6c/Gz5 i1BGX1k9RlLcXn8BSwZLZeMCrpoNBlJNI078Ll0g830vRTd1YP1Klq4O/Us2ZNsVKHNS 7MDHDz615u0JCLCDaufiLm3ps8TS4f5X1fbBDh/buTe7ATsiHGYXxgeRKk5W34Mlh4hv bIDw== X-Gm-Message-State: ALoCoQlgEjLxEouE7J0dkLtom8w/yf2AHIa17ZHWuaAgEak5tUFC8tdddHR/ToKa0LYVoFzdVDms X-Received: by 10.112.98.42 with SMTP id ef10mr12860785lbb.18.1436859596752; Tue, 14 Jul 2015 00:39:56 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.198 with SMTP id ba6ls8507lab.40.gmail; Tue, 14 Jul 2015 00:39:56 -0700 (PDT) X-Received: by 10.152.87.97 with SMTP id w1mr36872842laz.124.1436859596568; Tue, 14 Jul 2015 00:39:56 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id oh3si166615lbb.45.2015.07.14.00.39.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Jul 2015 00:39:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by lagx9 with SMTP id x9so1059986lag.1 for ; Tue, 14 Jul 2015 00:39:56 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr36973588lbb.56.1436859596432; Tue, 14 Jul 2015 00:39:56 -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 hn6csp2195213lbb; Tue, 14 Jul 2015 00:39:55 -0700 (PDT) X-Received: by 10.66.147.68 with SMTP id ti4mr77396334pab.90.1436859590973; Tue, 14 Jul 2015 00:39:50 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id iw6si274272pbd.183.2015.07.14.00.39.50; Tue, 14 Jul 2015 00:39:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 S1753333AbbGNHji (ORCPT + 26 others); Tue, 14 Jul 2015 03:39:38 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:33808 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753273AbbGNHjd (ORCPT ); Tue, 14 Jul 2015 03:39:33 -0400 Received: by pdbep18 with SMTP id ep18so1463252pdb.1 for ; Tue, 14 Jul 2015 00:39:32 -0700 (PDT) X-Received: by 10.67.30.136 with SMTP id ke8mr76580910pad.79.1436859572779; Tue, 14 Jul 2015 00:39:32 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by smtp.gmail.com with ESMTPSA id pe3sm275937pdb.55.2015.07.14.00.39.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Jul 2015 00:39:32 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Cc: wsa@the-dreams.de, robh+dt@kernel.org, robert.jarzmik@free.fr, yizhang@marvell.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Vaibhav Hiremath Subject: [PATCH-v4 06/11] i2c:pxa: Use devm_ variants in probe function Date: Tue, 14 Jul 2015 13:06:45 +0530 Message-Id: <1436859410-28878-7-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436859410-28878-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1436859410-28878-1-git-send-email-vaibhav.hiremath@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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.47 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 Acked-by: Robert Jarzmik --- drivers/i2c/busses/i2c-pxa.c | 81 ++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index beeed7c..66cf437 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1158,10 +1158,23 @@ static int i2c_pxa_probe(struct platform_device *dev) struct resource *res = NULL; int ret, irq; - i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL); - if (!i2c) { - ret = -ENOMEM; - goto emalloc; + i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); + if (!i2c) + return -ENOMEM; + + res = platform_get_resource(dev, IORESOURCE_MEM, 0); + + 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); + } + + 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 +1184,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 +1194,10 @@ 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; - } - - i2c->reg_base = ioremap(res->start, resource_size(res)); - if (!i2c->reg_base) { - ret = -EIO; - goto eremap; + dev_err(&dev->dev, "failed to get the clk: %ld\n", PTR_ERR(i2c->clk)); + return PTR_ERR(i2c->clk); } i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; @@ -1244,11 +1239,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 +1258,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 +1282,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; }