Commit e4cf92ba authored by Oreste Salerno's avatar Oreste Salerno Committed by Dmitry Torokhov

Input: cyttsp - use devres managed resource allocations

Use devm_() functions for allocating memory, input device and IRQ.
Signed-off-by: default avatarOreste Salerno <oreste.salerno@tomtom.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 809d9516
...@@ -528,6 +528,14 @@ static void cyttsp_close(struct input_dev *dev) ...@@ -528,6 +528,14 @@ static void cyttsp_close(struct input_dev *dev)
cyttsp_disable(ts); cyttsp_disable(ts);
} }
static void cyttsp_platform_exit(void *data)
{
struct cyttsp *ts = data;
if (ts->pdata->exit)
ts->pdata->exit();
}
struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
struct device *dev, int irq, size_t xfer_buf_size) struct device *dev, int irq, size_t xfer_buf_size)
{ {
...@@ -536,17 +544,16 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, ...@@ -536,17 +544,16 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
struct input_dev *input_dev; struct input_dev *input_dev;
int error; int error;
if (!pdata || !pdata->name || irq <= 0) { if (!pdata || !pdata->name || irq <= 0)
error = -EINVAL; return ERR_PTR(-EINVAL);
goto err_out;
}
ts = kzalloc(sizeof(*ts) + xfer_buf_size, GFP_KERNEL); ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL);
input_dev = input_allocate_device(); if (!ts)
if (!ts || !input_dev) { return ERR_PTR(-ENOMEM);
error = -ENOMEM;
goto err_free_mem; input_dev = devm_input_allocate_device(dev);
} if (!input_dev)
return ERR_PTR(-ENOMEM);
ts->dev = dev; ts->dev = dev;
ts->input = input_dev; ts->input = input_dev;
...@@ -557,12 +564,18 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, ...@@ -557,12 +564,18 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
init_completion(&ts->bl_ready); init_completion(&ts->bl_ready);
snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev));
error = devm_add_action(dev, cyttsp_platform_exit, ts);
if (error) {
dev_err(dev, "failed to install exit action: %d\n", error);
return ERR_PTR(error);
}
if (pdata->init) { if (pdata->init) {
error = pdata->init(); error = pdata->init();
if (error) { if (error) {
dev_err(ts->dev, "platform init failed, err: %d\n", dev_err(ts->dev, "platform init failed, err: %d\n",
error); error);
goto err_free_mem; return ERR_PTR(error);
} }
} }
...@@ -586,53 +599,32 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, ...@@ -586,53 +599,32 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
input_mt_init_slots(input_dev, CY_MAX_ID, 0); input_mt_init_slots(input_dev, CY_MAX_ID, 0);
error = request_threaded_irq(ts->irq, NULL, cyttsp_irq, error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
pdata->name, ts); pdata->name, ts);
if (error) { if (error) {
dev_err(ts->dev, "failed to request IRQ %d, err: %d\n", dev_err(ts->dev, "failed to request IRQ %d, err: %d\n",
ts->irq, error); ts->irq, error);
goto err_platform_exit; return ERR_PTR(error);
} }
disable_irq(ts->irq); disable_irq(ts->irq);
error = cyttsp_power_on(ts); error = cyttsp_power_on(ts);
if (error) if (error)
goto err_free_irq; return ERR_PTR(error);
error = input_register_device(input_dev); error = input_register_device(input_dev);
if (error) { if (error) {
dev_err(ts->dev, "failed to register input device: %d\n", dev_err(ts->dev, "failed to register input device: %d\n",
error); error);
goto err_free_irq; return ERR_PTR(error);
} }
return ts; return ts;
err_free_irq:
free_irq(ts->irq, ts);
err_platform_exit:
if (pdata->exit)
pdata->exit();
err_free_mem:
input_free_device(input_dev);
kfree(ts);
err_out:
return ERR_PTR(error);
} }
EXPORT_SYMBOL_GPL(cyttsp_probe); EXPORT_SYMBOL_GPL(cyttsp_probe);
void cyttsp_remove(struct cyttsp *ts)
{
free_irq(ts->irq, ts);
input_unregister_device(ts->input);
if (ts->pdata->exit)
ts->pdata->exit();
kfree(ts);
}
EXPORT_SYMBOL_GPL(cyttsp_remove);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen driver core"); MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen driver core");
MODULE_AUTHOR("Cypress"); MODULE_AUTHOR("Cypress");
...@@ -143,7 +143,6 @@ struct cyttsp { ...@@ -143,7 +143,6 @@ struct cyttsp {
struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
struct device *dev, int irq, size_t xfer_buf_size); struct device *dev, int irq, size_t xfer_buf_size);
void cyttsp_remove(struct cyttsp *ts);
int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr, int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
u8 length, const void *values); u8 length, const void *values);
......
...@@ -56,15 +56,6 @@ static int cyttsp_i2c_probe(struct i2c_client *client, ...@@ -56,15 +56,6 @@ static int cyttsp_i2c_probe(struct i2c_client *client,
return 0; return 0;
} }
static int cyttsp_i2c_remove(struct i2c_client *client)
{
struct cyttsp *ts = i2c_get_clientdata(client);
cyttsp_remove(ts);
return 0;
}
static const struct i2c_device_id cyttsp_i2c_id[] = { static const struct i2c_device_id cyttsp_i2c_id[] = {
{ CY_I2C_NAME, 0 }, { CY_I2C_NAME, 0 },
{ } { }
...@@ -77,7 +68,6 @@ static struct i2c_driver cyttsp_i2c_driver = { ...@@ -77,7 +68,6 @@ static struct i2c_driver cyttsp_i2c_driver = {
.pm = &cyttsp_pm_ops, .pm = &cyttsp_pm_ops,
}, },
.probe = cyttsp_i2c_probe, .probe = cyttsp_i2c_probe,
.remove = cyttsp_i2c_remove,
.id_table = cyttsp_i2c_id, .id_table = cyttsp_i2c_id,
}; };
......
...@@ -170,22 +170,12 @@ static int cyttsp_spi_probe(struct spi_device *spi) ...@@ -170,22 +170,12 @@ static int cyttsp_spi_probe(struct spi_device *spi)
return 0; return 0;
} }
static int cyttsp_spi_remove(struct spi_device *spi)
{
struct cyttsp *ts = spi_get_drvdata(spi);
cyttsp_remove(ts);
return 0;
}
static struct spi_driver cyttsp_spi_driver = { static struct spi_driver cyttsp_spi_driver = {
.driver = { .driver = {
.name = CY_SPI_NAME, .name = CY_SPI_NAME,
.pm = &cyttsp_pm_ops, .pm = &cyttsp_pm_ops,
}, },
.probe = cyttsp_spi_probe, .probe = cyttsp_spi_probe,
.remove = cyttsp_spi_remove,
}; };
module_spi_driver(cyttsp_spi_driver); module_spi_driver(cyttsp_spi_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment