From: Marco Felsch <m.felsch@pengutronix.de>
To: dmitry.torokhov@gmail.com, robh+dt@kernel.org
Cc: kernel@pengutronix.de, linux-input@vger.kernel.org,
devicetree@vger.kernel.org
Subject: [PATCH 1/4] Input: ads7846 - convert to devm_ alloc functions
Date: Wed, 27 Mar 2019 14:39:24 +0100 [thread overview]
Message-ID: <20190327133927.1340-2-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20190327133927.1340-1-m.felsch@pengutronix.de>
Convert to devm function to drop the 'no-mem' error handling path and
strip down the remove funciton a bit.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/input/touchscreen/ads7846.c | 37 ++++++++++++-----------------
1 file changed, 15 insertions(+), 22 deletions(-)
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index a2f45aefce08..5a7a8425d619 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -1283,13 +1283,17 @@ static int ads7846_probe(struct spi_device *spi)
if (err < 0)
return err;
- ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
- packet = kzalloc(sizeof(struct ads7846_packet), GFP_KERNEL);
- input_dev = input_allocate_device();
- if (!ts || !packet || !input_dev) {
- err = -ENOMEM;
- goto err_free_mem;
- }
+ ts = devm_kzalloc(&spi->dev, sizeof(*ts), GFP_KERNEL);
+ if (!ts)
+ return -ENOMEM;
+
+ packet = devm_kzalloc(&spi->dev, sizeof(*packet), GFP_KERNEL);
+ if (!packet)
+ return -ENOMEM;
+
+ input_dev = devm_input_allocate_device(&spi->dev);
+ if (!input_dev)
+ return -ENOMEM;
spi_set_drvdata(spi, ts);
@@ -1303,10 +1307,8 @@ static int ads7846_probe(struct spi_device *spi)
pdata = dev_get_platdata(&spi->dev);
if (!pdata) {
pdata = ads7846_probe_dt(&spi->dev);
- if (IS_ERR(pdata)) {
- err = PTR_ERR(pdata);
- goto err_free_mem;
- }
+ if (IS_ERR(pdata))
+ return PTR_ERR(pdata);
}
ts->model = pdata->model ? : 7846;
@@ -1321,7 +1323,7 @@ static int ads7846_probe(struct spi_device *spi)
if (pdata->filter_init != NULL) {
err = pdata->filter_init(pdata, &ts->filter_data);
if (err < 0)
- goto err_free_mem;
+ return err;
}
ts->filter = pdata->filter;
ts->filter_cleanup = pdata->filter_cleanup;
@@ -1352,7 +1354,6 @@ static int ads7846_probe(struct spi_device *spi)
input_dev->name = ts->name;
input_dev->phys = ts->phys;
- input_dev->dev.parent = &spi->dev;
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
@@ -1451,10 +1452,7 @@ static int ads7846_probe(struct spi_device *spi)
err_cleanup_filter:
if (ts->filter_cleanup)
ts->filter_cleanup(ts->filter_data);
- err_free_mem:
- input_free_device(input_dev);
- kfree(packet);
- kfree(ts);
+
return err;
}
@@ -1467,8 +1465,6 @@ static int ads7846_remove(struct spi_device *spi)
ads7846_disable(ts);
free_irq(ts->spi->irq, ts);
- input_unregister_device(ts->input);
-
ads784x_hwmon_unregister(spi, ts);
regulator_put(ts->reg);
@@ -1484,9 +1480,6 @@ static int ads7846_remove(struct spi_device *spi)
if (ts->filter_cleanup)
ts->filter_cleanup(ts->filter_data);
- kfree(ts->packet);
- kfree(ts);
-
dev_dbg(&spi->dev, "unregistered touchscreen\n");
return 0;
--
2.20.1
next prev parent reply other threads:[~2019-03-27 13:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-27 13:39 [PATCH 0/4] ADS7846 add general touchscreen features Marco Felsch
2019-03-27 13:39 ` Marco Felsch [this message]
2019-08-09 16:44 ` [PATCH 1/4] Input: ads7846 - convert to devm_ alloc functions Dmitry Torokhov
2019-03-27 13:39 ` [PATCH 2/4] dt-bindings: input: ads7846: fix property description Marco Felsch
[not found] ` <5ca06164.1c69fb81.39fb3.79f9@mx.google.com>
2019-08-09 16:42 ` Dmitry Torokhov
2019-03-27 13:39 ` [PATCH 3/4] dt-bindings: input: ads7846: replace vendor-bindings by general ones Marco Felsch
[not found] ` <5ca06167.1c69fb81.6e121.c248@mx.google.com>
2019-08-21 7:36 ` Marco Felsch
2019-08-22 17:44 ` Dmitry Torokhov
2019-03-27 13:39 ` [PATCH 4/4] Input: ads7846 - add support for general touchscreen bindings Marco Felsch
2019-08-09 16:42 ` Dmitry Torokhov
2019-08-09 9:30 ` [PATCH 0/4] ADS7846 add general touchscreen features Marco Felsch
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=20190327133927.1340-2-m.felsch@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-input@vger.kernel.org \
--cc=robh+dt@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 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).