From: Beomho Seo <beomho.seo@samsung.com>
To: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com,
jy0922.shim@samsung.com, sachin.kamat@linaro.org
Cc: myungjoo.ham@samsung.com, jh80.chung@samsung.com,
cw00.choi@samsung.com, Beomho Seo <beomho.seo@samsung.com>
Subject: [PATCH V5 1/1] Input: mcs_touchkey: use devm_* functions
Date: Thu, 29 May 2014 23:15:48 +0900 [thread overview]
Message-ID: <1401372948-13900-2-git-send-email-beomho.seo@samsung.com> (raw)
In-Reply-To: <1401372948-13900-1-git-send-email-beomho.seo@samsung.com>
This patch use devm_* funtions in mcs_touchkey driver.
As a result, error path and remove() funtion is simplified.
Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
---
Changes in v5:
- Remove mcs_touchkey_remove function again.
- Add devm_add_action for use action touchkey power off.
Changes in v4:
- free_irq are back again for equivalent transformation.
Changes in v3:
- Some codes are back again. use fw_version, driver name and poweron.
Changes in v2:
- Additionally use devm_kzalloc for mcs_touchkey_data struct.
drivers/input/keyboard/mcs_touchkey.c | 60 ++++++++++++++-------------------
1 file changed, 26 insertions(+), 34 deletions(-)
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index 1da8e0b..be7fe3d 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -96,6 +96,13 @@ static irqreturn_t mcs_touchkey_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
}
+static void mcs_touchkey_power_off(void *mcs_data)
+{
+ struct mcs_touchkey_data *data = mcs_data;
+
+ data->poweron(false);
+}
+
static int mcs_touchkey_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -113,14 +120,11 @@ static int mcs_touchkey_probe(struct i2c_client *client,
return -EINVAL;
}
- data = kzalloc(sizeof(struct mcs_touchkey_data) +
- sizeof(data->keycodes[0]) * (pdata->key_maxval + 1),
- GFP_KERNEL);
- input_dev = input_allocate_device();
+ data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+ input_dev = devm_input_allocate_device(&client->dev);
if (!data || !input_dev) {
dev_err(&client->dev, "Failed to allocate memory\n");
- error = -ENOMEM;
- goto err_free_mem;
+ return -ENOMEM;
}
data->client = client;
@@ -143,7 +147,7 @@ static int mcs_touchkey_probe(struct i2c_client *client,
if (fw_ver < 0) {
error = fw_ver;
dev_err(&client->dev, "i2c read error[%d]\n", error);
- goto err_free_mem;
+ return error;
}
dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
@@ -173,43 +177,32 @@ static int mcs_touchkey_probe(struct i2c_client *client,
if (pdata->poweron) {
data->poweron = pdata->poweron;
+ error = devm_add_action(&client->dev,
+ mcs_touchkey_power_off, data);
+ if (error) {
+ dev_err(&client->dev,
+ "Failed to register action, %d\n", error);
+ return error;
+ }
data->poweron(true);
}
- error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
- client->dev.driver->name, data);
+ error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+ mcs_touchkey_interrupt, IRQF_TRIGGER_FALLING |
+ IRQF_ONESHOT, client->dev.driver->name, data);
if (error) {
dev_err(&client->dev, "Failed to register interrupt\n");
- goto err_free_mem;
+ return error;
}
error = input_register_device(input_dev);
- if (error)
- goto err_free_irq;
+ if (error) {
+ dev_err(&client->dev, "Failed to register input device\n");
+ return error;
+ }
i2c_set_clientdata(client, data);
return 0;
-
-err_free_irq:
- free_irq(client->irq, data);
-err_free_mem:
- input_free_device(input_dev);
- kfree(data);
- return error;
-}
-
-static int mcs_touchkey_remove(struct i2c_client *client)
-{
- struct mcs_touchkey_data *data = i2c_get_clientdata(client);
-
- free_irq(client->irq, data);
- if (data->poweron)
- data->poweron(false);
- input_unregister_device(data->input_dev);
- kfree(data);
-
- return 0;
}
static void mcs_touchkey_shutdown(struct i2c_client *client)
@@ -269,7 +262,6 @@ static struct i2c_driver mcs_touchkey_driver = {
.pm = &mcs_touchkey_pm_ops,
},
.probe = mcs_touchkey_probe,
- .remove = mcs_touchkey_remove,
.shutdown = mcs_touchkey_shutdown,
.id_table = mcs_touchkey_id,
};
--
1.7.9.5
prev parent reply other threads:[~2014-05-29 14:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-29 14:15 [PATCH v5 0/1] Use devm_* functions for Melfas touch device Beomho Seo
2014-05-29 14:15 ` Beomho Seo [this message]
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=1401372948-13900-2-git-send-email-beomho.seo@samsung.com \
--to=beomho.seo@samsung.com \
--cc=cw00.choi@samsung.com \
--cc=dmitry.torokhov@gmail.com \
--cc=jh80.chung@samsung.com \
--cc=jy0922.shim@samsung.com \
--cc=linux-input@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=sachin.kamat@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox