devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Haojian Zhuang <haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	arnd-r2nGTMty4D4@public.gmane.org,
	linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
Subject: [PATCH 05/10] i2c: pxa: use devm_kzalloc
Date: Thu, 18 Oct 2012 17:06:59 +0800	[thread overview]
Message-ID: <1350551224-12857-5-git-send-email-haojian.zhuang@gmail.com> (raw)
In-Reply-To: <1350551224-12857-1-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Use devm_kzalloc & add checking in probe() function.

Signed-off-by: Haojian Zhuang <haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/i2c/busses/i2c-pxa.c |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index cd66ec2..5f96310 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1083,6 +1083,8 @@ static int i2c_pxa_probe_pdata(struct platform_device *pdev,
 	struct i2c_pxa_platform_data *plat = pdev->dev.platform_data;
 	const struct platform_device_id *id = platform_get_device_id(pdev);
 
+	if (!id)
+		return -EINVAL;
 	*i2c_types = id->driver_data;
 	if (plat) {
 		i2c->use_pio = plat->use_pio;
@@ -1099,29 +1101,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;
 
 	ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type);
 	if (ret > 0)
 		ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
 	if (ret < 0)
-		goto eclk;
+		return ret;
 
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 	irq = platform_get_irq(dev, 0);
-	if (res == NULL || irq < 0) {
-		ret = -ENODEV;
-		goto eclk;
-	}
+	if (res == NULL || irq < 0)
+		return -ENODEV;
 
-	if (!request_mem_region(res->start, resource_size(res), res->name)) {
-		ret = -ENOMEM;
-		goto eclk;
-	}
+	if (!request_mem_region(res->start, resource_size(res), res->name))
+		return -ENOMEM;
 
 	i2c->adap.owner   = THIS_MODULE;
 	i2c->adap.retries = 5;
@@ -1214,8 +1210,6 @@ ereqirq:
 eremap:
 	clk_put(i2c->clk);
 eclk:
-	kfree(i2c);
-emalloc:
 	release_mem_region(res->start, resource_size(res));
 	return ret;
 }
-- 
1.7.0.4

  parent reply	other threads:[~2012-10-18  9:06 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18  9:06 [PATCH 01/10] pinctrl: use postcore_initcall Haojian Zhuang
     [not found] ` <1350551224-12857-1-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-18  9:06   ` [PATCH 02/10] ARM: mmp: select pinctrl driver Haojian Zhuang
2012-10-18  9:06   ` [PATCH 03/10] tty: pxa: configure pin Haojian Zhuang
     [not found]     ` <1350551224-12857-3-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-18 18:21       ` Linus Walleij
2012-10-18 22:20       ` Stephen Warren
     [not found]         ` <508080CB.5010904-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-10-22  8:45           ` Linus Walleij
     [not found]             ` <CACRpkdb5Jiw71jBLDXpf2VTJQx7_gABqs03_20CeCLbVT=JkaA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-22 20:26               ` Stephen Warren
     [not found]                 ` <5085AC06.8070508-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-10-23  9:26                   ` Linus Walleij
     [not found]                     ` <CACRpkdY-XyagxGU_ya_FZirzbqStTirOC5nuBBwwFY3f4bBTYA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-23  9:37                       ` Mark Brown
     [not found]                         ` <20121023093711.GS4477-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-10-23  9:59                           ` Linus Walleij
     [not found]                             ` <CACRpkdb+DkZbTDZamGMN+9t07kPktuA_3QtHQJFv+Vu859r7KA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-23 11:58                               ` Mark Brown
     [not found]                                 ` <20121023115806.GX4477-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-10-24  5:43                                   ` Linus Walleij
2012-10-18  9:06   ` [PATCH 04/10] i2c: pxa: configure pins Haojian Zhuang
     [not found]     ` <1350551224-12857-4-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-18 18:22       ` Linus Walleij
2012-10-18  9:06   ` Haojian Zhuang [this message]
     [not found]     ` <1350551224-12857-5-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-18 22:27       ` [PATCH 05/10] i2c: pxa: use devm_kzalloc Stephen Warren
     [not found]         ` <5080826D.6040108-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-10-19  1:16           ` Haojian Zhuang
2012-10-18  9:07   ` [PATCH 06/10] pinctrl: single: support gpio request and free Haojian Zhuang
     [not found]     ` <1350551224-12857-6-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-19 22:37       ` Tony Lindgren
2012-10-18  9:07   ` [PATCH 07/10] pinctrl: remove mutex lock in groups show Haojian Zhuang
     [not found]     ` <1350551224-12857-7-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-18 18:29       ` Linus Walleij
2012-10-18 22:26       ` Stephen Warren
     [not found]         ` <50808200.3080207-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-10-22  8:53           ` Linus Walleij
2012-10-18  9:07   ` [PATCH 08/10] pinctrl: single: support pinconf generic Haojian Zhuang
     [not found]     ` <1350551224-12857-8-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-18 18:30       ` Linus Walleij
     [not found]         ` <CACRpkda0QLkdKns3CXNOijYBjaDtW1QyhNYjTqDvRH-in8pvZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-18 22:29           ` Tony Lindgren
     [not found]             ` <20121018222907.GH30550-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-10-19  2:23               ` Haojian Zhuang
     [not found]                 ` <CAN1soZzsruhWt7VFgf5Fi79npcjLiMSUEVwnE3hR5iWEh+9GRw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19  2:40                   ` Tony Lindgren
     [not found]                     ` <20121019024012.GP30550-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-10-19 18:44                       ` Tony Lindgren
2012-10-19 18:53                   ` Tony Lindgren
2012-10-19 19:13       ` Tony Lindgren
     [not found]         ` <20121019191333.GT4730-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-10-22 10:09           ` Haojian Zhuang
     [not found]             ` <CAN1soZzE_tTkmPBechvUcdAbWKSScwcaqe_cb0TTmnRJi9gtRg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-22 17:09               ` Tony Lindgren
     [not found]                 ` <20121022170917.GB4730-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-10-25 23:43                   ` Tony Lindgren
     [not found]                     ` <20121025234328.GF11928-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-10-26  1:47                       ` Haojian Zhuang
     [not found]                         ` <CAN1soZyosQJYZAT61tUig6PGVrfXzwDeiC1R0hnKWoFLVP4Ayw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-26 17:29                           ` Tony Lindgren
2012-10-31 22:37                       ` Haojian Zhuang
2012-10-18  9:07   ` [PATCH 09/10] ARM: dts: support pinctrl single in pxa910 Haojian Zhuang
2012-10-18  9:07   ` [PATCH 10/10] document: devicetree: bind pinconf in pinctrl single Haojian Zhuang
     [not found]     ` <1350551224-12857-10-git-send-email-haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-10-19 22:40       ` Tony Lindgren
2012-10-18 18:20   ` [PATCH 01/10] pinctrl: use postcore_initcall Linus Walleij
2012-10-18 22:18   ` Stephen Warren
     [not found]     ` <5080802B.3000209-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-10-18 22:28       ` Tony Lindgren
     [not found]         ` <20121018222802.GG30550-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-10-19  2:16           ` Haojian Zhuang
     [not found]             ` <CAN1soZy17wO2s7WoRSRod8k5Zh7fuUc1gxhQiHEb0=zwLhyj6A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19  2:38               ` Tony Lindgren
     [not found]                 ` <20121019023818.GO30550-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-10-19  2:53                   ` Haojian Zhuang
     [not found]                     ` <CAN1soZw+EzFjEcxDJfi50BEhuQqDUwsB4DMGEXg+oyU-6gO_Jw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 17:41                       ` Tony Lindgren
2012-10-19  2:24   ` Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350551224-12857-5-git-send-email-haojian.zhuang@gmail.com \
    --to=haojian.zhuang-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).