diff mbox series

[V4,06/10] input: touchscreen: ili210x: Convert to devm IRQ

Message ID 20190130064835.8418-7-marex@denx.de (mailing list archive)
State Accepted
Commit 1bdec5d9818c47e080c19784dfd25d1d9c20807e
Headers show
Series input: touchscreen: ili210x: Add ILI2511 support | expand

Commit Message

Marek Vasut Jan. 30, 2019, 6:48 a.m. UTC
Convert the driver to devm_request_irq(), drop the related unmanaged
deregistration code and add ili210x_irq_teardown() to tear the IRQ
down and cancel possible touchscreen pending work.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Henrik Rydberg <rydberg@bitmath.org>
Cc: Olivier Sobrie <olivier@sobrie.be>
Cc: Philipp Puschmann <pp@emlix.com>
To: linux-input@vger.kernel.org
---
V2: Retain workqueue
V3: Reword the commit message
V4: Use devm_request_irq() instead of the threaded variant, add
    custom devm action to tear the IRQ down.
---
 drivers/input/touchscreen/ili210x.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

Comments

Dmitry Torokhov Feb. 7, 2019, 6:31 a.m. UTC | #1
Hi Marek,

On Wed, Jan 30, 2019 at 07:48:31AM +0100, Marek Vasut wrote:
> +	error = devm_request_irq(dev, client->irq, ili210x_irq, 0,
> +				 client->name, priv);
>  	if (error) {
>  		dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
>  			error);
> -		goto err_free_mem;
> +		return error;
>  	}
>  
> +	error = devm_add_action(dev, ili210x_irq_teardown, priv);
> +	if (error)
> +		return error;

Because you want the work be canceled after interrupt is freed, you want
to register the action before requesting irq (devm is unwound on the
order opposite of initialization).

I changed it to ili210x_cancel_work and moved before call to
devm_request_irq().

Thanks.
Marek Vasut Feb. 7, 2019, 7:49 a.m. UTC | #2
On 2/7/19 7:31 AM, Dmitry Torokhov wrote:
> Hi Marek,
> 
> On Wed, Jan 30, 2019 at 07:48:31AM +0100, Marek Vasut wrote:
>> +	error = devm_request_irq(dev, client->irq, ili210x_irq, 0,
>> +				 client->name, priv);
>>  	if (error) {
>>  		dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
>>  			error);
>> -		goto err_free_mem;
>> +		return error;
>>  	}
>>  
>> +	error = devm_add_action(dev, ili210x_irq_teardown, priv);
>> +	if (error)
>> +		return error;
> 
> Because you want the work be canceled after interrupt is freed, you want
> to register the action before requesting irq (devm is unwound on the
> order opposite of initialization).
> 
> I changed it to ili210x_cancel_work and moved before call to
> devm_request_irq().

Ah, thanks.
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index f8b20d302384..cd4ce0bef948 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -177,6 +177,13 @@  static void ili210x_power_down(void *data)
 	gpiod_set_value_cansleep(reset_gpio, 1);
 }
 
+static void ili210x_irq_teardown(void *data)
+{
+	struct ili210x *priv = data;
+
+	cancel_delayed_work_sync(&priv->dwork);
+}
+
 static int ili210x_i2c_probe(struct i2c_client *client,
 				       const struct i2c_device_id *id)
 {
@@ -266,19 +273,23 @@  static int ili210x_i2c_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, priv);
 
-	error = request_irq(client->irq, ili210x_irq, 0,
-			    client->name, priv);
+	error = devm_request_irq(dev, client->irq, ili210x_irq, 0,
+				 client->name, priv);
 	if (error) {
 		dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
 			error);
-		goto err_free_mem;
+		return error;
 	}
 
+	error = devm_add_action(dev, ili210x_irq_teardown, priv);
+	if (error)
+		return error;
+
 	error = sysfs_create_group(&dev->kobj, &ili210x_attr_group);
 	if (error) {
 		dev_err(dev, "Unable to create sysfs attributes, err: %d\n",
 			error);
-		goto err_free_irq;
+		return error;
 	}
 
 	error = input_register_device(priv->input);
@@ -297,19 +308,12 @@  static int ili210x_i2c_probe(struct i2c_client *client,
 
 err_remove_sysfs:
 	sysfs_remove_group(&dev->kobj, &ili210x_attr_group);
-err_free_irq:
-	free_irq(client->irq, priv);
-err_free_mem:
 	return error;
 }
 
 static int ili210x_i2c_remove(struct i2c_client *client)
 {
-	struct ili210x *priv = i2c_get_clientdata(client);
-
 	sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group);
-	free_irq(priv->client->irq, priv);
-	cancel_delayed_work_sync(&priv->dwork);
 
 	return 0;
 }