From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Bill Pemberton <wfp5p@virginia.edu>,
Mark Brown <broonie@opensource.wolfsonmicro.com>,
Denis Carikli <denis@eukrea.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] Input: tsc2007 - convert to use devres-managed resources
Date: Wed, 20 Nov 2013 21:14:43 -0800 [thread overview]
Message-ID: <20131121051438.GA6180@core.coreip.homeip.net> (raw)
This simplifies error handling path and allows us get rid of
tsc2007_remove().
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/touchscreen/tsc2007.c | 79 +++++++++++++++++++------------------
1 file changed, 40 insertions(+), 39 deletions(-)
diff --git a/drivers/input/touchscreen/tsc2007.c b/drivers/input/touchscreen/tsc2007.c
index 48a165a..bd51eee 100644
--- a/drivers/input/touchscreen/tsc2007.c
+++ b/drivers/input/touchscreen/tsc2007.c
@@ -366,6 +366,14 @@ static int tsc2007_probe_pdev(struct i2c_client *client, struct tsc2007 *ts,
return 0;
}
+static void tsc2007_call_exit_platform_hw(void *data)
+{
+ struct device *dev = data;
+ const struct tsc2007_platform_data *pdata = dev_get_platdata(dev);
+
+ pdata->exit_platform_hw();
+}
+
static int tsc2007_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -389,11 +397,9 @@ static int tsc2007_probe(struct i2c_client *client,
if (err)
return err;
- input_dev = input_allocate_device();
- if (!input_dev) {
- err = -ENOMEM;
- goto err_free_input;
- };
+ input_dev = devm_input_allocate_device(&client->dev);
+ if (!input_dev)
+ return -ENOMEM;
i2c_set_clientdata(client, ts);
@@ -422,45 +428,41 @@ static int tsc2007_probe(struct i2c_client *client,
input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_12BIT,
ts->fuzzz, 0);
- if (pdata && pdata->init_platform_hw)
- pdata->init_platform_hw();
+ if (pdata) {
+ if (pdata->exit_platform_hw) {
+ err = devm_add_action(&client->dev,
+ tsc2007_call_exit_platform_hw,
+ &client->dev);
+ if (err) {
+ dev_err(&client->dev,
+ "Failed to register exit_platform_hw action, %d\n",
+ err);
+ return err;
+ }
+ }
+
+ if (pdata->init_platform_hw)
+ pdata->init_platform_hw();
+ }
- err = request_threaded_irq(ts->irq, tsc2007_hard_irq, tsc2007_soft_irq,
- IRQF_ONESHOT, client->dev.driver->name, ts);
- if (err < 0) {
- dev_err(&client->dev, "irq %d busy?\n", ts->irq);
- goto err_free_input;
+ err = devm_request_threaded_irq(&client->dev, ts->irq,
+ tsc2007_hard_irq, tsc2007_soft_irq,
+ IRQF_ONESHOT,
+ client->dev.driver->name, ts);
+ if (err) {
+ dev_err(&client->dev, "Failed to request irq %d: %d\n",
+ ts->irq, err);
+ return err;
}
tsc2007_stop(ts);
err = input_register_device(input_dev);
- if (err)
- goto err_free_irq;
-
- return 0;
-
- err_free_irq:
- free_irq(ts->irq, ts);
- if (pdata && pdata->exit_platform_hw)
- pdata->exit_platform_hw();
- err_free_input:
- input_free_device(input_dev);
- return err;
-}
-
-static int tsc2007_remove(struct i2c_client *client)
-{
- const struct tsc2007_platform_data *pdata = dev_get_platdata(&client->dev);
- struct tsc2007 *ts = i2c_get_clientdata(client);
-
- free_irq(ts->irq, ts);
-
- if (pdata && pdata->exit_platform_hw)
- pdata->exit_platform_hw();
-
- input_unregister_device(ts->input);
- kfree(ts);
+ if (err) {
+ dev_err(&client->dev,
+ "Failed to register input device: %d\n", err);
+ return err;
+ }
return 0;
}
@@ -488,7 +490,6 @@ static struct i2c_driver tsc2007_driver = {
},
.id_table = tsc2007_idtable,
.probe = tsc2007_probe,
- .remove = tsc2007_remove,
};
module_i2c_driver(tsc2007_driver);
--
1.8.3.1
--
Dmitry
next reply other threads:[~2013-11-21 5:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 5:14 Dmitry Torokhov [this message]
2013-11-25 8:40 ` [PATCH] Input: tsc2007 - convert to use devres-managed resources Denis Carikli
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=20131121051438.GA6180@core.coreip.homeip.net \
--to=dmitry.torokhov@gmail.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=denis@eukrea.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wfp5p@virginia.edu \
/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 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).