All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>, linux-kernel@vger.kernel.org
Subject: [PATCH 6/7] Input: cy8ctmg110_ts - switch to using managed resources
Date: Wed,  2 Jun 2021 21:37:25 -0700	[thread overview]
Message-ID: <20210603043726.3793876-6-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20210603043726.3793876-1-dmitry.torokhov@gmail.com>

This simplifies error handling paths and allows to get rid of
cy8ctmg110_remove() method.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/touchscreen/cy8ctmg110_ts.c | 74 +++++++++--------------
 1 file changed, 28 insertions(+), 46 deletions(-)

diff --git a/drivers/input/touchscreen/cy8ctmg110_ts.c b/drivers/input/touchscreen/cy8ctmg110_ts.c
index 33c1360a251c..33ccb31cad52 100644
--- a/drivers/input/touchscreen/cy8ctmg110_ts.c
+++ b/drivers/input/touchscreen/cy8ctmg110_ts.c
@@ -161,6 +161,14 @@ static irqreturn_t cy8ctmg110_irq_thread(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static void cy8ctmg110_shut_off(void *_ts)
+{
+	struct cy8ctmg110 *ts = _ts;
+
+	cy8ctmg110_set_sleepmode(ts, true);
+	cy8ctmg110_power(ts, false);
+}
+
 static int cy8ctmg110_probe(struct i2c_client *client,
 					const struct i2c_device_id *id)
 {
@@ -179,12 +187,13 @@ static int cy8ctmg110_probe(struct i2c_client *client,
 					I2C_FUNC_SMBUS_READ_WORD_DATA))
 		return -EIO;
 
-	ts = kzalloc(sizeof(struct cy8ctmg110), GFP_KERNEL);
-	input_dev = input_allocate_device();
-	if (!ts || !input_dev) {
-		err = -ENOMEM;
-		goto err_free_mem;
-	}
+	ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
+	if (!ts)
+		return -ENOMEM;
+
+	input_dev = devm_input_allocate_device(&client->dev);
+	if (!input_dev)
+		return -ENOMEM;
 
 	ts->client = client;
 	ts->input = input_dev;
@@ -196,56 +205,46 @@ static int cy8ctmg110_probe(struct i2c_client *client,
 	input_dev->name = CY8CTMG110_DRIVER_NAME " Touchscreen";
 	input_dev->phys = ts->phys;
 	input_dev->id.bustype = BUS_I2C;
-	input_dev->dev.parent = &client->dev;
-
-	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
-	input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
 
+	input_set_capability(input_dev, EV_KEY, BTN_TOUCH);
 	input_set_abs_params(input_dev, ABS_X,
 			CY8CTMG110_X_MIN, CY8CTMG110_X_MAX, 4, 0);
 	input_set_abs_params(input_dev, ABS_Y,
 			CY8CTMG110_Y_MIN, CY8CTMG110_Y_MAX, 4, 0);
 
 	if (ts->reset_pin) {
-		err = gpio_request(ts->reset_pin, NULL);
+		err = devm_gpio_request(&client->dev, ts->reset_pin, NULL);
 		if (err) {
 			dev_err(&client->dev,
 				"Unable to request GPIO pin %d.\n",
 				ts->reset_pin);
-			goto err_free_mem;
+			return err;
 		}
 	}
 
 	cy8ctmg110_power(ts, true);
 	cy8ctmg110_set_sleepmode(ts, false);
 
-	err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread,
-				   IRQF_ONESHOT, "touch_reset_key", ts);
-	if (err < 0) {
+	err = devm_add_action_or_reset(&client->dev, cy8ctmg110_shut_off, ts);
+	if (err)
+		return err;
+
+	err = devm_request_threaded_irq(&client->dev, client->irq,
+					NULL, cy8ctmg110_irq_thread,
+					IRQF_ONESHOT, "touch_reset_key", ts);
+	if (err) {
 		dev_err(&client->dev,
 			"irq %d busy? error %d\n", client->irq, err);
-		goto err_shutoff_device;
+		return err;
 	}
 
 	err = input_register_device(input_dev);
 	if (err)
-		goto err_free_irq;
+		return err;
 
 	i2c_set_clientdata(client, ts);
 
 	return 0;
-
-err_free_irq:
-	free_irq(client->irq, ts);
-err_shutoff_device:
-	cy8ctmg110_set_sleepmode(ts, true);
-	cy8ctmg110_power(ts, false);
-	if (ts->reset_pin)
-		gpio_free(ts->reset_pin);
-err_free_mem:
-	input_free_device(input_dev);
-	kfree(ts);
-	return err;
 }
 
 static int __maybe_unused cy8ctmg110_suspend(struct device *dev)
@@ -276,22 +275,6 @@ static int __maybe_unused cy8ctmg110_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(cy8ctmg110_pm, cy8ctmg110_suspend, cy8ctmg110_resume);
 
-static int cy8ctmg110_remove(struct i2c_client *client)
-{
-	struct cy8ctmg110 *ts = i2c_get_clientdata(client);
-
-	cy8ctmg110_set_sleepmode(ts, true);
-	cy8ctmg110_power(ts, false);
-
-	free_irq(client->irq, ts);
-	input_unregister_device(ts->input);
-	if (ts->reset_pin)
-		gpio_free(ts->reset_pin);
-	kfree(ts);
-
-	return 0;
-}
-
 static const struct i2c_device_id cy8ctmg110_idtable[] = {
 	{ CY8CTMG110_DRIVER_NAME, 1 },
 	{ }
@@ -306,7 +289,6 @@ static struct i2c_driver cy8ctmg110_driver = {
 	},
 	.id_table	= cy8ctmg110_idtable,
 	.probe		= cy8ctmg110_probe,
-	.remove		= cy8ctmg110_remove,
 };
 
 module_i2c_driver(cy8ctmg110_driver);
-- 
2.32.0.rc0.204.g9fa02ecfa5-goog


  parent reply	other threads:[~2021-06-03  4:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03  4:37 [PATCH 1/7] Input: cy8ctmg110_ts - rely on platform code to supply interrupt Dmitry Torokhov
2021-06-03  4:37 ` [PATCH 2/7] Input: cy8ctmg110_ts - do not hard code interrupt trigger Dmitry Torokhov
2021-06-04  7:31   ` Linus Walleij
2021-06-03  4:37 ` [PATCH 3/7] Input: cy8ctmg110_ts - do not hardcode as wakeup source Dmitry Torokhov
2021-06-04  7:31   ` Linus Walleij
2021-06-03  4:37 ` [PATCH 4/7] Input: cy8ctmg110_ts - let I2C core configure wake interrupt Dmitry Torokhov
2021-06-04  7:32   ` Linus Walleij
2021-06-06  4:10     ` Dmitry Torokhov
2021-06-03  4:37 ` [PATCH 5/7] Input: cy8ctmg110_ts - use endian helpers when converting data on wire Dmitry Torokhov
2021-06-04  7:34   ` Linus Walleij
2021-06-03  4:37 ` Dmitry Torokhov [this message]
2021-06-04  7:35   ` [PATCH 6/7] Input: cy8ctmg110_ts - switch to using managed resources Linus Walleij
2021-06-03  4:37 ` [PATCH 7/7] Input: cy8ctmg110_ts - switch to using gpiod API Dmitry Torokhov
2021-06-04  7:38   ` Linus Walleij
2021-06-06  4:08     ` Dmitry Torokhov
2021-06-04  7:30 ` [PATCH 1/7] Input: cy8ctmg110_ts - rely on platform code to supply interrupt Linus Walleij

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=20210603043726.3793876-6-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.