devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/2] mfd: stmpe: Use devm_*() routines
@ 2012-11-22  5:10 Viresh Kumar
       [not found] ` <f1d508c64a01dfd492a1ab1fda28af4b7647d8ab.1353560936.git.viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2012-11-23 11:03 ` Samuel Ortiz
  0 siblings, 2 replies; 23+ messages in thread
From: Viresh Kumar @ 2012-11-22  5:10 UTC (permalink / raw)
  To: sameo-VuQAYsv1563Yd54FQh9/CA
  Cc: Viresh Kumar, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	spear-devel-nkJGhpqTU55BDgjK7y7TUQ,
	lee.jones-QSEj5FYQhm4dnm+yROfE0A,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

This patch frees stmpe driver from tension of freeing resources :)
devm_* derivatives of multiple routines are used while allocating resources,
which would be freed automatically by kernel.

Signed-off-by: Viresh Kumar <viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---

V1->V2:
------
- Rebased over latest for-next from Samuel
- updated additional kzalloc with devm_kzalloc(), first one seen below.

 drivers/mfd/stmpe.c | 60 +++++++++++++++++++----------------------------------
 1 file changed, 21 insertions(+), 39 deletions(-)

diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index ba157d4..c0df4b9 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -1052,17 +1052,17 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
 	int ret;
 
 	if (!pdata) {
-		if (np) {
-			pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
-			if (!pdata)
-				return -ENOMEM;
-
-			stmpe_of_probe(pdata, np);
-		} else
+		if (!np)
 			return -EINVAL;
+
+		pdata = devm_kzalloc(ci->dev, sizeof(*pdata), GFP_KERNEL);
+		if (!pdata)
+			return -ENOMEM;
+
+		stmpe_of_probe(pdata, np);
 	}
 
-	stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL);
+	stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL);
 	if (!stmpe)
 		return -ENOMEM;
 
@@ -1084,11 +1084,12 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
 		ci->init(stmpe);
 
 	if (pdata->irq_over_gpio) {
-		ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
+		ret = devm_gpio_request_one(ci->dev, pdata->irq_gpio,
+				GPIOF_DIR_IN, "stmpe");
 		if (ret) {
 			dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
 					ret);
-			goto out_free;
+			return ret;
 		}
 
 		stmpe->irq = gpio_to_irq(pdata->irq_gpio);
@@ -1105,48 +1106,37 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
 			dev_err(stmpe->dev,
 				"%s does not support no-irq mode!\n",
 				stmpe->variant->name);
-			ret = -ENODEV;
-			goto free_gpio;
+			return -ENODEV;
 		}
 		stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum];
 	}
 
 	ret = stmpe_chip_init(stmpe);
 	if (ret)
-		goto free_gpio;
+		return ret;
 
 	if (stmpe->irq >= 0) {
 		ret = stmpe_irq_init(stmpe, np);
 		if (ret)
-			goto free_gpio;
+			return ret;
 
-		ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
-				pdata->irq_trigger | IRQF_ONESHOT,
+		ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL,
+				stmpe_irq, pdata->irq_trigger | IRQF_ONESHOT,
 				"stmpe", stmpe);
 		if (ret) {
 			dev_err(stmpe->dev, "failed to request IRQ: %d\n",
 					ret);
-			goto free_gpio;
+			return ret;
 		}
 	}
 
 	ret = stmpe_devices_init(stmpe);
-	if (ret) {
-		dev_err(stmpe->dev, "failed to add children\n");
-		goto out_removedevs;
-	}
-
-	return 0;
+	if (!ret)
+		return 0;
 
-out_removedevs:
+	dev_err(stmpe->dev, "failed to add children\n");
 	mfd_remove_devices(stmpe->dev);
-	if (stmpe->irq >= 0)
-		free_irq(stmpe->irq, stmpe);
-free_gpio:
-	if (pdata->irq_over_gpio)
-		gpio_free(pdata->irq_gpio);
-out_free:
-	kfree(stmpe);
+
 	return ret;
 }
 
@@ -1154,14 +1144,6 @@ int stmpe_remove(struct stmpe *stmpe)
 {
 	mfd_remove_devices(stmpe->dev);
 
-	if (stmpe->irq >= 0)
-		free_irq(stmpe->irq, stmpe);
-
-	if (stmpe->pdata->irq_over_gpio)
-		gpio_free(stmpe->pdata->irq_gpio);
-
-	kfree(stmpe);
-
 	return 0;
 }
 
-- 
1.7.12.rc2.18.g61b472e

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2012-11-23 15:45 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-22  5:10 [PATCH V2 1/2] mfd: stmpe: Use devm_*() routines Viresh Kumar
     [not found] ` <f1d508c64a01dfd492a1ab1fda28af4b7647d8ab.1353560936.git.viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-22  5:10   ` [PATCH V2 2/2] mfd: stmpe: Extend DT support in stmpe driver Viresh Kumar
     [not found]     ` <b81641051dad9660b72b0028d001e5620d901160.1353560936.git.viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-22 11:24       ` Lee Jones
     [not found]         ` <20121122112451.GE4328-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-11-22 13:54           ` Viresh Kumar
     [not found]             ` <CAKohpo=F91sZ7St3XVXqwAEgmSWXjAxxXwRs1RD5qPyW99P1vA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-11-22 15:46               ` Lee Jones
     [not found]                 ` <20121122154612.GC10986-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-11-22 17:01                   ` Viresh Kumar
2012-11-23  3:45                     ` Shiraz Hashim
     [not found]                       ` <20121123034557.GB5384-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-11-23  9:33                         ` Lee Jones
2012-11-23  9:23                     ` Lee Jones
2012-11-22 18:31           ` Viresh Kumar
2012-11-23  9:39             ` Lee Jones
2012-11-23  4:29           ` Viresh Kumar
2012-11-23  9:36             ` Lee Jones
2012-11-23 12:39               ` Viresh Kumar
2012-11-23 15:43                 ` Lee Jones
2012-11-23 15:45                   ` Viresh Kumar
2012-11-22 10:27   ` [PATCH V2 1/2] mfd: stmpe: Use devm_*() routines Lee Jones
     [not found]     ` <20121122102710.GD4328-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-11-22 10:30       ` Viresh Kumar
2012-11-22 17:10       ` Viresh Kumar
     [not found]         ` <CAKohpo=gctcd5+bZ8xeJn-Cx3=+=+uxaCzEoZhFmp+XaJSpf9Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-11-23  9:40           ` Lee Jones
2012-11-23  9:42             ` Lee Jones
2012-11-23  9:44             ` Viresh Kumar
2012-11-23 11:03 ` Samuel Ortiz

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).