Skip to contentSkip to conversation

Input: touchscreen : Introduce the use of the managed version of kzalloc

PATCH In review Himangi Saraogi 3 participants 4 messages May 28, 2014 – May 29, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: touchscreen : Introduce the use of the managed version of kzalloc

This patch moves most data allocated in the probe function from unmanaged interfaces to managed interfaces. The kfrees and error handling code is done away with. Also, the unnecesary labels are removed and the function mrstouch_remove is removed as it becomes empty after removing the no longer required function calls. Also, linux/device.h include is added to make sure the devm_*() routine declarations are unambiguously available.

The following Coccinelle semantic patch was used for making a part of the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}

---
 drivers/input/touchscreen/intel-mid-touch.c | 39 ++++++++---------------------
 1 file changed, 11 insertions(+), 28 deletions(-)
drivers/input/touchscreen/intel-mid-touch.c +11 -28
index 4f6b156..b1b1e8b 100644
@@ -36,6 +36,7 @@
 #include <linux/irq.h>
 #include <linux/delay.h>
 #include <asm/intel_scu_ipc.h>
+#include <linux/device.h>
 
 /* PMIC Interrupt registers */
 #define PMIC_REG_ID1		0x00 /* PMIC ID1 register */
@@ -580,12 +581,12 @@ static int mrstouch_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL);
-	input = input_allocate_device();
+	tsdev = devm_kzalloc(&pdev->dev, sizeof(struct mrstouch_dev),
+			     GFP_KERNEL);
+	input = devm_input_allocate_device(&pdev->dev);
 	if (!tsdev || !input) {
 		dev_err(&pdev->dev, "unable to allocate memory\n");
-		err = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	tsdev->dev = &pdev->dev;
@@ -598,7 +599,7 @@ static int mrstouch_probe(struct platform_device *pdev)
 	err = mrstouch_adc_init(tsdev);
 	if (err) {
 		dev_err(&pdev->dev, "ADC initialization failed\n");
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	input->name = "mrst_touchscreen";
@@ -618,39 +619,22 @@ static int mrstouch_probe(struct platform_device *pdev)
 	input_set_abs_params(tsdev->input, ABS_PRESSURE,
 			     MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0);
 
-	err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
-				   IRQF_ONESHOT, "mrstouch", tsdev);
+	err = devm_request_threaded_irq(&pdev->dev, tsdev->irq, NULL,
+					mrstouch_pendet_irq, IRQF_ONESHOT,
+					"mrstouch", tsdev);
 	if (err) {
 		dev_err(tsdev->dev, "unable to allocate irq\n");
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	err = input_register_device(tsdev->input);
 	if (err) {
 		dev_err(tsdev->dev, "unable to register input device\n");
-		goto err_free_irq;
+		return -ENOMEM;
 	}
 
 	platform_set_drvdata(pdev, tsdev);
 	return 0;
-
-err_free_irq:
-	free_irq(tsdev->irq, tsdev);
-err_free_mem:
-	input_free_device(input);
-	kfree(tsdev);
-	return err;
-}
-
-static int mrstouch_remove(struct platform_device *pdev)
-{
-	struct mrstouch_dev *tsdev = platform_get_drvdata(pdev);
-
-	free_irq(tsdev->irq, tsdev);
-	input_unregister_device(tsdev->input);
-	kfree(tsdev);
-
-	return 0;
 }
 
 static struct platform_driver mrstouch_driver = {
@@ -659,7 +643,6 @@ static struct platform_driver mrstouch_driver = {
 		.owner	= THIS_MODULE,
 	},
 	.probe		= mrstouch_probe,
-	.remove		= mrstouch_remove,
 };
 module_platform_driver(mrstouch_driver);
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 89 lines · Himangi Saraogi

This patch moves most data allocated in the probe function from unmanaged interfaces to managed interfaces. The kfrees and error handling code is done away with. Also, the unnecesary labels are removed and the function mrstouch_remove is removed as it becomes empty after removing the no longer required function calls. Also, linux/device.h include is added to make sure the devm_*() routine declarations are unambiguously available.

The following Coccinelle semantic patch was used for making a part of the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}

---
 drivers/input/touchscreen/intel-mid-touch.c | 39 ++++++++---------------------
 1 file changed, 11 insertions(+), 28 deletions(-)
drivers/input/touchscreen/intel-mid-touch.c +6 -5
index 4f6b156..b1b1e8b 100644
@@ -36,6 +36,7 @@
 #include <linux/irq.h>
 #include <linux/delay.h>
 #include <asm/intel_scu_ipc.h>
+#include <linux/device.h>
 
 /* PMIC Interrupt registers */
 #define PMIC_REG_ID1		0x00 /* PMIC ID1 register */
@@ -580,12 +581,12 @@ static int mrstouch_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL);
-	input = input_allocate_device();
+	tsdev = devm_kzalloc(&pdev->dev, sizeof(struct mrstouch_dev),
+			     GFP_KERNEL);
+	input = devm_input_allocate_device(&pdev->dev);
 	if (!tsdev || !input) {
 		dev_err(&pdev->dev, "unable to allocate memory\n");
-		err = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	tsdev->dev = &pdev->dev;
@@ -598,7 +599,7 @@ static int mrstouch_probe(struct platform_device *pdev)
 	err = mrstouch_adc_init(tsdev);
 	if (err) {
 		dev_err(&pdev->dev, "ADC initialization failed\n");
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	input->name = "mrst_touchscreen";
@@ -618,39 +619,22 @@ static int mrstouch_probe(struct platform_device *pdev)
 	input_set_abs_params(tsdev->input, ABS_PRESSURE,
 			     MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0);

drivers/input/touchscreen/intel-mid-touch.c static int mrstouch_probe(struct platform_device *pdev) · line 627

Quoted 10 lines
drivers/input/touchscreen/intel-mid-touch.c +4 -3
 
-	err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
-				   IRQF_ONESHOT, "mrstouch", tsdev);
+	err = devm_request_threaded_irq(&pdev->dev, tsdev->irq, NULL,
+					mrstouch_pendet_irq, IRQF_ONESHOT,
+					"mrstouch", tsdev);
 	if (err) {
 		dev_err(tsdev->dev, "unable to allocate irq\n");
-		goto err_free_mem;
+		return -ENOMEM;

This is bad conversion. We used to report 'err' returned by request_threaded_irq, but now we always report -ENOMEM. I fixed it up here and in other places and applied.

Quoted 43 lines
drivers/input/touchscreen/intel-mid-touch.c +1 -20
 	}
 
 	err = input_register_device(tsdev->input);
 	if (err) {
 		dev_err(tsdev->dev, "unable to register input device\n");
-		goto err_free_irq;
+		return -ENOMEM;
 	}
 
 	platform_set_drvdata(pdev, tsdev);
 	return 0;
-
-err_free_irq:
-	free_irq(tsdev->irq, tsdev);
-err_free_mem:
-	input_free_device(input);
-	kfree(tsdev);
-	return err;
-}
-
-static int mrstouch_remove(struct platform_device *pdev)
-{
-	struct mrstouch_dev *tsdev = platform_get_drvdata(pdev);
-
-	free_irq(tsdev->irq, tsdev);
-	input_unregister_device(tsdev->input);
-	kfree(tsdev);
-
-	return 0;
 }
 
 static struct platform_driver mrstouch_driver = {
@@ -659,7 +643,6 @@ static struct platform_driver mrstouch_driver = {
 		.owner	= THIS_MODULE,
 	},
 	.probe		= mrstouch_probe,
-	.remove		= mrstouch_remove,
 };
 module_platform_driver(mrstouch_driver);
 
Signature · 1 line
1.9.1
Signature · 1 line
Dmitry
#2 lore raw
Quoted 4 lines
Quoted 4 lines
drivers/input/touchscreen/intel-mid-touch.c +0 -0
@@ -618,39 +619,22 @@ static int mrstouch_probe(struct platform_device *pdev)
 	input_set_abs_params(tsdev->input, ABS_PRESSURE,
 			     MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0);
 
Quoted 13 lines

drivers/input/touchscreen/intel-mid-touch.c static int mrstouch_probe(struct platform_device *pdev) · line 627

Quoted 9 lines
drivers/input/touchscreen/intel-mid-touch.c +4 -3
-	err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
-				   IRQF_ONESHOT, "mrstouch", tsdev);
+	err = devm_request_threaded_irq(&pdev->dev, tsdev->irq, NULL,
+					mrstouch_pendet_irq, IRQF_ONESHOT,
+					"mrstouch", tsdev);
 	if (err) {
 		dev_err(tsdev->dev, "unable to allocate irq\n");
-		goto err_free_mem;
+		return -ENOMEM;

This is bad conversion. We used to report 'err' returned by request_threaded_irq, but now we always report -ENOMEM. I fixed it up here and in other places and applied.

Sorry to have missed that. I guess you got the one on the call to mrstouch_adc_init as well?

thanks,
julia

maintainer
#3 lore raw
Quoted 18 lines · Julia Lawall
Quoted 4 lines
Quoted 4 lines
drivers/input/touchscreen/intel-mid-touch.c +0 -0
@@ -618,39 +619,22 @@ static int mrstouch_probe(struct platform_device *pdev)
 	input_set_abs_params(tsdev->input, ABS_PRESSURE,
 			     MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0);
 
Quoted 13 lines

drivers/input/touchscreen/intel-mid-touch.c static int mrstouch_probe(struct platform_device *pdev) · line 627

Quoted 9 lines
drivers/input/touchscreen/intel-mid-touch.c +4 -3
-	err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
-				   IRQF_ONESHOT, "mrstouch", tsdev);
+	err = devm_request_threaded_irq(&pdev->dev, tsdev->irq, NULL,
+					mrstouch_pendet_irq, IRQF_ONESHOT,
+					"mrstouch", tsdev);
 	if (err) {
 		dev_err(tsdev->dev, "unable to allocate irq\n");
-		goto err_free_mem;
+		return -ENOMEM;

This is bad conversion. We used to report 'err' returned by request_threaded_irq, but now we always report -ENOMEM. I fixed it up here and in other places and applied.

Quoted 2 lines

Sorry to have missed that. I guess you got the one on the call to mrstouch_adc_init as well?

Yeah, I fixed them all up.

Thanks.

Signature · 1 line
Dmitry