From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Peng Fan <peng.fan@nxp.com>
Subject: [PATCH 4/4] input: touchscreen: ti_am335x_tsc: Use resource managed API to simplify code
Date: Wed, 05 Feb 2025 08:45:17 +0800 [thread overview]
Message-ID: <20250205-input-cleanup-v1-4-9758898ff8cb@nxp.com> (raw)
In-Reply-To: <20250205-input-cleanup-v1-0-9758898ff8cb@nxp.com>
From: Peng Fan <peng.fan@nxp.com>
Use devm_input_allocate_device/devm_kzalloc/devm_request_irq to simplify
code
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/input/touchscreen/ti_am335x_tsc.c | 43 ++++++++++---------------------
1 file changed, 14 insertions(+), 29 deletions(-)
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
index 93d659ff90aa94ecbd7000fe05e0eef8ab3546ba..aef38b2e4e464e3b76395de5991a0f41b4f852f4 100644
--- a/drivers/input/touchscreen/ti_am335x_tsc.c
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -418,12 +418,11 @@ static int titsc_probe(struct platform_device *pdev)
int err;
/* Allocate memory for device */
- ts_dev = kzalloc(sizeof(*ts_dev), GFP_KERNEL);
- input_dev = input_allocate_device();
+ ts_dev = devm_kzalloc(&pdev->dev, sizeof(*ts_dev), GFP_KERNEL);
+ input_dev = devm_input_allocate_device(&pdev->dev);
if (!ts_dev || !input_dev) {
dev_err(&pdev->dev, "failed to allocate memory.\n");
- err = -ENOMEM;
- goto err_free_mem;
+ return -ENOMEM;
}
tscadc_dev->tsc = ts_dev;
@@ -435,18 +434,21 @@ static int titsc_probe(struct platform_device *pdev)
err = titsc_parse_dt(pdev, ts_dev);
if (err) {
dev_err(&pdev->dev, "Could not find valid DT data.\n");
- goto err_free_mem;
+ return err;
}
- err = request_irq(ts_dev->irq, titsc_irq,
- IRQF_SHARED, pdev->dev.driver->name, ts_dev);
+ err = devm_request_irq(&pdev->dev, ts_dev->irq, titsc_irq, IRQF_SHARED,
+ pdev->dev.driver->name, ts_dev);
if (err) {
dev_err(&pdev->dev, "failed to allocate irq.\n");
- goto err_free_mem;
+ return err;
}
- device_init_wakeup(&pdev->dev, true);
- err = dev_pm_set_wake_irq(&pdev->dev, ts_dev->irq);
+ err = devm_device_init_wakeup(&pdev->dev);
+ if (err)
+ dev_err(&pdev->dev, "device init wakeup failed.\n");
+
+ err = devm_pm_set_wake_irq(&pdev->dev, ts_dev->irq);
if (err)
dev_err(&pdev->dev, "irq wake enable failed.\n");
@@ -456,7 +458,7 @@ static int titsc_probe(struct platform_device *pdev)
err = titsc_config_wires(ts_dev);
if (err) {
dev_err(&pdev->dev, "wrong i/p wire configuration\n");
- goto err_free_irq;
+ return err;
}
titsc_step_config(ts_dev);
titsc_writel(ts_dev, REG_FIFO0THR,
@@ -475,19 +477,10 @@ static int titsc_probe(struct platform_device *pdev)
/* register to the input system */
err = input_register_device(input_dev);
if (err)
- goto err_free_irq;
+ return err;
platform_set_drvdata(pdev, ts_dev);
return 0;
-
-err_free_irq:
- dev_pm_clear_wake_irq(&pdev->dev);
- device_init_wakeup(&pdev->dev, false);
- free_irq(ts_dev->irq, ts_dev);
-err_free_mem:
- input_free_device(input_dev);
- kfree(ts_dev);
- return err;
}
static void titsc_remove(struct platform_device *pdev)
@@ -495,18 +488,10 @@ static void titsc_remove(struct platform_device *pdev)
struct titsc *ts_dev = platform_get_drvdata(pdev);
u32 steps;
- dev_pm_clear_wake_irq(&pdev->dev);
- device_init_wakeup(&pdev->dev, false);
- free_irq(ts_dev->irq, ts_dev);
-
/* total steps followed by the enable mask */
steps = 2 * ts_dev->coordinate_readouts + 2;
steps = (1 << steps) - 1;
am335x_tsc_se_clr(ts_dev->mfd_tscadc, steps);
-
- input_unregister_device(ts_dev->input);
-
- kfree(ts_dev);
}
static int titsc_suspend(struct device *dev)
--
2.37.1
next prev parent reply other threads:[~2025-02-05 0:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 0:45 [PATCH 0/4] input: use devm_pm_set_wake_irq Peng Fan (OSS)
2025-02-05 0:45 ` [PATCH 1/4] input: keyboard: ep93xx_keypad: Use devm_pm_set_wake_irq Peng Fan (OSS)
2025-02-05 0:45 ` [PATCH 2/4] input: keyboard: omap4_keypad: " Peng Fan (OSS)
2025-02-05 0:45 ` [PATCH 3/4] input: misc: nxp-bbnsm-pwrkey: Use resource managed API to simplify code Peng Fan (OSS)
2025-02-05 0:45 ` Peng Fan (OSS) [this message]
2025-03-04 1:51 ` [PATCH 0/4] input: use devm_pm_set_wake_irq Peng Fan
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=20250205-input-cleanup-v1-4-9758898ff8cb@nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peng.fan@nxp.com \
/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).