Skip to contentSkip to conversation

Input: wm831x-ts - Remove unneeded clearing of driver data

PATCH In review Mark Brown 2 participants 8 messages Oct 11, 2012

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/3 Input: wm831x-ts - Remove unneeded clearing of driver data

This is unneeded, only a bound driver can use driver data and a driver relying on the state prior to probe() is buggy.

---
 drivers/input/touchscreen/wm831x-ts.c |    1 -
 1 file changed, 1 deletion(-)
drivers/input/touchscreen/wm831x-ts.c +0 -1
index 52abb98..bf0a4a6 100644
@@ -390,7 +390,6 @@ static __devexit int wm831x_ts_remove(struct platform_device *pdev)
 	input_unregister_device(wm831x_ts->input_dev);
 	kfree(wm831x_ts);
 
-	platform_set_drvdata(pdev, NULL);
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH 2/3 Input: wm831x-ts - Convert to devm_kzalloc()

Saves a little code and eliminates the possibility of introducing some leaks.

---
 drivers/input/touchscreen/wm831x-ts.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/touchscreen/wm831x-ts.c +2 -3
index bf0a4a6..c7eee56 100644
@@ -245,7 +245,8 @@ static __devinit int wm831x_ts_probe(struct platform_device *pdev)
 	if (core_pdata)
 		pdata = core_pdata->touch;
 
-	wm831x_ts = kzalloc(sizeof(struct wm831x_ts), GFP_KERNEL);
+	wm831x_ts = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ts),
+				 GFP_KERNEL);
 	input_dev = input_allocate_device();
 	if (!wm831x_ts || !input_dev) {
 		error = -ENOMEM;
@@ -376,7 +377,6 @@ err_data_irq:
 	free_irq(wm831x_ts->data_irq, wm831x_ts);
 err_alloc:
 	input_free_device(input_dev);
-	kfree(wm831x_ts);
 
 	return error;
 }
@@ -388,7 +388,6 @@ static __devexit int wm831x_ts_remove(struct platform_device *pdev)
 	free_irq(wm831x_ts->pd_irq, wm831x_ts);
 	free_irq(wm831x_ts->data_irq, wm831x_ts);
 	input_unregister_device(wm831x_ts->input_dev);
-	kfree(wm831x_ts);
 
 	return 0;
 }
Signature · 1 line
1.7.10.4
maintainer
#2 lore raw

Re: [PATCH 2/3] Input: wm831x-ts - Convert to devm_kzalloc()

Quoted 3 lines · Mark Brown

Saves a little code and eliminates the possibility of introducing some leaks.

*sigh* OK, I guess devm_* is here to stay and I have to get on with the program. I am still unhappy that half of the patches converting/using devm_* APIs are wrong (not these ones), but I will apply these 3.

Thanks.

Quoted 38 lines
---
 drivers/input/touchscreen/wm831x-ts.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/touchscreen/wm831x-ts.c +2 -3
index bf0a4a6..c7eee56 100644
@@ -245,7 +245,8 @@ static __devinit int wm831x_ts_probe(struct platform_device *pdev)
 	if (core_pdata)
 		pdata = core_pdata->touch;
 
-	wm831x_ts = kzalloc(sizeof(struct wm831x_ts), GFP_KERNEL);
+	wm831x_ts = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ts),
+				 GFP_KERNEL);
 	input_dev = input_allocate_device();
 	if (!wm831x_ts || !input_dev) {
 		error = -ENOMEM;
@@ -376,7 +377,6 @@ err_data_irq:
 	free_irq(wm831x_ts->data_irq, wm831x_ts);
 err_alloc:
 	input_free_device(input_dev);
-	kfree(wm831x_ts);
 
 	return error;
 }
@@ -388,7 +388,6 @@ static __devexit int wm831x_ts_remove(struct platform_device *pdev)
 	free_irq(wm831x_ts->pd_irq, wm831x_ts);
 	free_irq(wm831x_ts->data_irq, wm831x_ts);
 	input_unregister_device(wm831x_ts->input_dev);
-	kfree(wm831x_ts);
 
 	return 0;
 }
Signature · 1 line
1.7.10.4
Signature · 1 line
Dmitry
author
#3 lore raw

Re: [PATCH 2/3] Input: wm831x-ts - Convert to devm_kzalloc()

Quoted 7 lines · Dmitry Torokhov
Quoted 2 lines · Mark Brown

Saves a little code and eliminates the possibility of introducing some leaks.

*sigh* OK, I guess devm_* is here to stay and I have to get on with the program. I am still unhappy that half of the patches converting/using devm_* APIs are wrong (not these ones), but I will apply these 3.

What's the error pattern you're seeing? I've not noticed much of an issue here, but if there is one perhaps we can do something to make the error more obvious or harder to introduce.

maintainer
#4 lore raw

Re: [PATCH 2/3] Input: wm831x-ts - Convert to devm_kzalloc()

Quoted 5 lines · Mark Brown
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Mark Brown

Saves a little code and eliminates the possibility of introducing some leaks.

Quoted 7 lines
Quoted 3 lines

*sigh* OK, I guess devm_* is here to stay and I have to get on with the program. I am still unhappy that half of the patches converting/using devm_* APIs are wrong (not these ones), but I will apply these 3.

What's the error pattern you're seeing? I've not noticed much of an issue here, but if there is one perhaps we can do something to make the error more obvious or harder to introduce.

int driver_probe()

{
	devm_kzalloc();
	input_allocate_device();
	...
	devm_request_irq();
	...
	input_register_device();

....
}

void driver_remove()

{
	input_unregister_device();
	/* rely on deves for cleanup */
}

The problem is that input device is freed but interrupts are still fully functional.

Signature · 1 line
Dmitry
author
#5 lore raw

Re: [PATCH 2/3] Input: wm831x-ts - Convert to devm_kzalloc()

Quoted 11 lines · Dmitry Torokhov
Quoted 4 lines · Mark Brown

What's the error pattern you're seeing? I've not noticed much of an issue here, but if there is one perhaps we can do something to make the error more obvious or harder to introduce.

	devm_request_irq();

The problem is that input device is freed but interrupts are still fully functional.

Ah, yes - that one I do spot all the time. I agree that devm_request_irq() is a menace, that error is far too easy to introduce and it always seems more work to work out if it's safe than the benefit in the cases where it can be used.

The other devm APIs are less problematic, though.

maintainer
#6 lore raw

Re: [PATCH 2/3] Input: wm831x-ts - Convert to devm_kzalloc()

Quoted 10 lines · Mark Brown
Quoted 8 lines · Dmitry Torokhov
Quoted 4 lines · Mark Brown

What's the error pattern you're seeing? I've not noticed much of an issue here, but if there is one perhaps we can do something to make the error more obvious or harder to introduce.

	devm_request_irq();
Quoted 7 lines
Quoted 2 lines

The problem is that input device is freed but interrupts are still fully functional.

Ah, yes - that one I do spot all the time. I agree that devm_request_irq() is a menace, that error is far too easy to introduce and it always seems more work to work out if it's safe than the benefit in the cases where it can be used.

Right. Another one (the IRQ again): have IRQ schedule [delayed] work and then use cancel_delayed_work() in ->remove() but rely on devres to free IRQ which is the wrong order.

Quoted 2 lines

The other devm APIs are less problematic, though.

I agree, they are indeed safer. I guess if I add devm_input* the some of the devm_request_*irq() will be safe as well, but we are not there yet.

Signature · 1 line
Dmitry
author
#7 lore raw

PATCH 3/3 Input: wm831x-on - Convert to devm_kzalloc()

In reply to Mark Brown

Saves a small amount of code and reduces the potential for leaks.

---
 drivers/input/misc/wm831x-on.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/misc/wm831x-on.c +2 -3
index 6790a81..fa8b390 100644
@@ -76,7 +76,8 @@ static int __devinit wm831x_on_probe(struct platform_device *pdev)
 	int irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0));
 	int ret;
 
-	wm831x_on = kzalloc(sizeof(struct wm831x_on), GFP_KERNEL);
+	wm831x_on = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_on),
+				 GFP_KERNEL);
 	if (!wm831x_on) {
 		dev_err(&pdev->dev, "Can't allocate data\n");
 		return -ENOMEM;
@@ -120,7 +121,6 @@ err_irq:
 err_input_dev:
 	input_free_device(wm831x_on->dev);
 err:
-	kfree(wm831x_on);
 	return ret;
 }
 
@@ -132,7 +132,6 @@ static int __devexit wm831x_on_remove(struct platform_device *pdev)
 	free_irq(irq, wm831x_on);
 	cancel_delayed_work_sync(&wm831x_on->work);
 	input_unregister_device(wm831x_on->dev);
-	kfree(wm831x_on);
 
 	return 0;
 }
Signature · 1 line
1.7.10.4