* [PATCH v2 0/2] Use devm_* functions for Melfas touch device. @ 2014-05-26 13:29 Beomho Seo 2014-05-26 13:29 ` [PATCH v2 1/2] Input: mcs_touchkey: use devm_* functions Beomho Seo 2014-05-26 13:29 ` [PATCH v2 2/2] Input: mcs5000_ts: " Beomho Seo 0 siblings, 2 replies; 4+ messages in thread From: Beomho Seo @ 2014-05-26 13:29 UTC (permalink / raw) To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo This patch set devm_* functions in Melfas touche device driver. As a result, error path and remove() function is simplified. Changes in v2: - Additionally use devm_kzalloc mcs_[touchkey/ts]_data struct. Beomho Seo (2): Input: mcs_touchkey: use devm_* functions Input: mcs5000_ts: use devm_* functions. drivers/input/keyboard/mcs_touchkey.c | 53 +++++++++----------------------- drivers/input/touchscreen/mcs5000_ts.c | 42 ++++++++----------------- 2 files changed, 26 insertions(+), 69 deletions(-) -- 1.7.9.5 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] Input: mcs_touchkey: use devm_* functions 2014-05-26 13:29 [PATCH v2 0/2] Use devm_* functions for Melfas touch device Beomho Seo @ 2014-05-26 13:29 ` Beomho Seo 2014-05-26 20:36 ` Dmitry Torokhov 2014-05-26 13:29 ` [PATCH v2 2/2] Input: mcs5000_ts: " Beomho Seo 1 sibling, 1 reply; 4+ messages in thread From: Beomho Seo @ 2014-05-26 13:29 UTC (permalink / raw) To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo 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 v2: - Additionally use devm_kzalloc for mcs_touchkey_data struct. --- drivers/input/keyboard/mcs_touchkey.c | 53 +++++++++------------------------ 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c index 1da8e0b..455bd62 100644 --- a/drivers/input/keyboard/mcs_touchkey.c +++ b/drivers/input/keyboard/mcs_touchkey.c @@ -103,7 +103,6 @@ static int mcs_touchkey_probe(struct i2c_client *client, struct mcs_touchkey_data *data; struct input_dev *input_dev; unsigned int fw_reg; - int fw_ver; int error; int i; @@ -113,14 +112,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; @@ -139,13 +135,12 @@ static int mcs_touchkey_probe(struct i2c_client *client, fw_reg = MCS5080_TOUCHKEY_FW; } - fw_ver = i2c_smbus_read_byte_data(client, fw_reg); - if (fw_ver < 0) { - error = fw_ver; + error = i2c_smbus_read_byte_data(client, fw_reg); + if (error < 0) { dev_err(&client->dev, "i2c read error[%d]\n", error); - goto err_free_mem; - } - dev_info(&client->dev, "Firmware version: %d\n", fw_ver); + return error; + } else + dev_info(&client->dev, "Firmware version: %d\n", error); input_dev->name = "MELPAS MCS Touchkey"; input_dev->id.bustype = BUS_I2C; @@ -176,40 +171,21 @@ static int mcs_touchkey_probe(struct i2c_client *client, 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, + dev_name(&client->dev), 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; + 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 +245,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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] Input: mcs_touchkey: use devm_* functions 2014-05-26 13:29 ` [PATCH v2 1/2] Input: mcs_touchkey: use devm_* functions Beomho Seo @ 2014-05-26 20:36 ` Dmitry Torokhov 0 siblings, 0 replies; 4+ messages in thread From: Dmitry Torokhov @ 2014-05-26 20:36 UTC (permalink / raw) To: Beomho Seo Cc: linux-input, jy0922.shim, sachin.kamat, myungjoo.ham, jh80.chung, cw00.choi Hi Beomho, On Mon, May 26, 2014 at 10:29:11PM +0900, Beomho Seo wrote: > 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 v2: > - Additionally use devm_kzalloc for mcs_touchkey_data struct. > --- > drivers/input/keyboard/mcs_touchkey.c | 53 +++++++++------------------------ > 1 file changed, 14 insertions(+), 39 deletions(-) > > diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c > index 1da8e0b..455bd62 100644 > --- a/drivers/input/keyboard/mcs_touchkey.c > +++ b/drivers/input/keyboard/mcs_touchkey.c > @@ -103,7 +103,6 @@ static int mcs_touchkey_probe(struct i2c_client *client, > struct mcs_touchkey_data *data; > struct input_dev *input_dev; > unsigned int fw_reg; > - int fw_ver; > int error; > int i; > > @@ -113,14 +112,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; > @@ -139,13 +135,12 @@ static int mcs_touchkey_probe(struct i2c_client *client, > fw_reg = MCS5080_TOUCHKEY_FW; > } > > - fw_ver = i2c_smbus_read_byte_data(client, fw_reg); > - if (fw_ver < 0) { > - error = fw_ver; > + error = i2c_smbus_read_byte_data(client, fw_reg); You are not reading error code, you are reading firmware version. I am not sure why you are changing this code. > + if (error < 0) { > dev_err(&client->dev, "i2c read error[%d]\n", error); > - goto err_free_mem; > - } > - dev_info(&client->dev, "Firmware version: %d\n", fw_ver); > + return error; > + } else > + dev_info(&client->dev, "Firmware version: %d\n", error); > > input_dev->name = "MELPAS MCS Touchkey"; > input_dev->id.bustype = BUS_I2C; > @@ -176,40 +171,21 @@ static int mcs_touchkey_probe(struct i2c_client *client, > 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, > + dev_name(&client->dev), data); The original code was attaching driver name to the IRQ, now you are attaching device name. Why? I am not against it per se, but it needs to be a separate patch with its own justification. > 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; > + 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); Why aren't you powering down the chip anymore? > - input_unregister_device(data->input_dev); > - kfree(data); > - > - return 0; > } > > static void mcs_touchkey_shutdown(struct i2c_client *client) > @@ -269,7 +245,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 > Thanks. -- Dmitry ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] Input: mcs5000_ts: use devm_* functions. 2014-05-26 13:29 [PATCH v2 0/2] Use devm_* functions for Melfas touch device Beomho Seo 2014-05-26 13:29 ` [PATCH v2 1/2] Input: mcs_touchkey: use devm_* functions Beomho Seo @ 2014-05-26 13:29 ` Beomho Seo 1 sibling, 0 replies; 4+ messages in thread From: Beomho Seo @ 2014-05-26 13:29 UTC (permalink / raw) To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo This patch use devm_* functions in mcs5000_ts driver. As, a result, error patch and remove() function is simplified. Signed-off-by: Beomho Seo <beomho.seo@samsung.com> --- Changes in v2: - Additionally use devm_kzalloc for mcs_ts_data struct. --- drivers/input/touchscreen/mcs5000_ts.c | 42 +++++++++----------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/drivers/input/touchscreen/mcs5000_ts.c b/drivers/input/touchscreen/mcs5000_ts.c index 647e36f..6b57e28 100644 --- a/drivers/input/touchscreen/mcs5000_ts.c +++ b/drivers/input/touchscreen/mcs5000_ts.c @@ -196,12 +196,11 @@ static int mcs5000_ts_probe(struct i2c_client *client, if (!dev_get_platdata(&client->dev)) return -EINVAL; - data = kzalloc(sizeof(struct mcs5000_ts_data), 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"); - ret = -ENOMEM; - goto err_free_mem; + return -ENOMEM; } data->client = client; @@ -223,40 +222,24 @@ static int mcs5000_ts_probe(struct i2c_client *client, if (data->platform_data->cfg_pin) data->platform_data->cfg_pin(); - ret = request_threaded_irq(client->irq, NULL, mcs5000_ts_interrupt, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, "mcs5000_ts", data); - - if (ret < 0) { + ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, + mcs5000_ts_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "mcs5000_ts", data); + if (ret) { dev_err(&client->dev, "Failed to register interrupt\n"); - goto err_free_mem; + return ret; } ret = input_register_device(data->input_dev); - if (ret < 0) - goto err_free_irq; + if (ret < 0) { + dev_err(&client->dev, "Failed to register input device\n"); + return ret; + } mcs5000_ts_phys_init(data); 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 ret; -} - -static int mcs5000_ts_remove(struct i2c_client *client) -{ - struct mcs5000_ts_data *data = i2c_get_clientdata(client); - - free_irq(client->irq, data); - input_unregister_device(data->input_dev); - kfree(data); - - return 0; } #ifdef CONFIG_PM @@ -291,7 +274,6 @@ MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id); static struct i2c_driver mcs5000_ts_driver = { .probe = mcs5000_ts_probe, - .remove = mcs5000_ts_remove, .driver = { .name = "mcs5000_ts", #ifdef CONFIG_PM -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-26 20:36 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-05-26 13:29 [PATCH v2 0/2] Use devm_* functions for Melfas touch device Beomho Seo 2014-05-26 13:29 ` [PATCH v2 1/2] Input: mcs_touchkey: use devm_* functions Beomho Seo 2014-05-26 20:36 ` Dmitry Torokhov 2014-05-26 13:29 ` [PATCH v2 2/2] Input: mcs5000_ts: " Beomho Seo
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).