From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-kernel@vger.kernel.org
Cc: Andy Shevchenko <andy@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH v1 1/7] auxdisplay: arm-charlcd: convert to use device managed APIs
Date: Mon, 29 Dec 2025 14:52:34 +0100 [thread overview]
Message-ID: <20251229142349.1251843-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20251229142349.1251843-1-andriy.shevchenko@linux.intel.com>
The current probe function of the driver is implemented by using
plain old APIs. As Geert noted, one of the error paths has a mistake
that may lead to a wrong call. Instead of targeting that particular
issue, convert the driver to use device managed APIs altogether.
It's not needed per se (driver can never be removed once loaded),
but it simplifies coding and error handling.
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/r/CAMuHMdVquNEoxRQkcBEH0nC+CDuib6o0H6m3CBk3ZN2267LpQw@mail.gmail.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/auxdisplay/arm-charlcd.c | 49 ++++++--------------------------
1 file changed, 9 insertions(+), 40 deletions(-)
diff --git a/drivers/auxdisplay/arm-charlcd.c b/drivers/auxdisplay/arm-charlcd.c
index 4e22882f57c9..0dab69938352 100644
--- a/drivers/auxdisplay/arm-charlcd.c
+++ b/drivers/auxdisplay/arm-charlcd.c
@@ -14,7 +14,6 @@
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/io.h>
-#include <linux/slab.h>
#include <linux/workqueue.h>
#include <generated/utsrelease.h>
@@ -56,8 +55,6 @@
/**
* struct charlcd - Private data structure
* @dev: a pointer back to containing device
- * @phybase: the offset to the controller in physical memory
- * @physize: the size of the physical page
* @virtbase: the offset to the controller in virtual memory
* @irq: reserved interrupt number
* @complete: completion structure for the last LCD command
@@ -65,8 +62,6 @@
*/
struct charlcd {
struct device *dev;
- u32 phybase;
- u32 physize;
void __iomem *virtbase;
int irq;
struct completion complete;
@@ -266,44 +261,27 @@ static void charlcd_init_work(struct work_struct *work)
static int __init charlcd_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
int ret;
struct charlcd *lcd;
struct resource *res;
- lcd = kzalloc(sizeof(*lcd), GFP_KERNEL);
+ lcd = devm_kzalloc(dev, sizeof(*lcd), GFP_KERNEL);
if (!lcd)
return -ENOMEM;
lcd->dev = &pdev->dev;
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res) {
- ret = -ENOENT;
- goto out_no_resource;
- }
- lcd->phybase = res->start;
- lcd->physize = resource_size(res);
-
- if (request_mem_region(lcd->phybase, lcd->physize,
- DRIVERNAME) == NULL) {
- ret = -EBUSY;
- goto out_no_memregion;
- }
-
- lcd->virtbase = ioremap(lcd->phybase, lcd->physize);
- if (!lcd->virtbase) {
- ret = -ENOMEM;
- goto out_no_memregion;
- }
+ lcd->virtbase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+ if (IS_ERR(lcd->virtbase))
+ return PTR_ERR(lcd->virtbase);
lcd->irq = platform_get_irq(pdev, 0);
/* If no IRQ is supplied, we'll survive without it */
if (lcd->irq >= 0) {
- if (request_irq(lcd->irq, charlcd_interrupt, 0,
- DRIVERNAME, lcd)) {
- ret = -EIO;
- goto out_no_irq;
- }
+ ret = devm_request_irq(dev, lcd->irq, charlcd_interrupt, 0, DRIVERNAME, lcd);
+ if (ret)
+ return ret;
}
platform_set_drvdata(pdev, lcd);
@@ -315,18 +293,9 @@ static int __init charlcd_probe(struct platform_device *pdev)
INIT_DELAYED_WORK(&lcd->init_work, charlcd_init_work);
schedule_delayed_work(&lcd->init_work, 0);
- dev_info(&pdev->dev, "initialized ARM character LCD at %08x\n",
- lcd->phybase);
+ dev_info(dev, "initialized ARM character LCD at %pa\n", &res->start);
return 0;
-
-out_no_irq:
- iounmap(lcd->virtbase);
-out_no_memregion:
- release_mem_region(lcd->phybase, lcd->physize);
-out_no_resource:
- kfree(lcd);
- return ret;
}
static int charlcd_suspend(struct device *dev)
--
2.50.1
next prev parent reply other threads:[~2025-12-29 14:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-29 13:52 [PATCH v1 0/7] auxdisplay: arm-charlcd: refactor with modern APIs Andy Shevchenko
2025-12-29 13:52 ` Andy Shevchenko [this message]
2025-12-29 13:52 ` [PATCH v1 2/7] auxdisplay: arm-charlcd: Remove unneeded info message Andy Shevchenko
2025-12-29 13:52 ` [PATCH v1 3/7] auxdisplay: arm-charlcd: drop of_match_ptr() Andy Shevchenko
2025-12-29 13:52 ` [PATCH v1 4/7] auxdisplay: arm-charlcd: Don't use "proxy" headers Andy Shevchenko
2025-12-29 13:52 ` [PATCH v1 5/7] auxdisplay: arm-charlcd: Use readl_poll_timeout Andy Shevchenko
2025-12-29 13:52 ` [PATCH v1 6/7] auxdisplay: arm-charlcd: Join string literals back Andy Shevchenko
2025-12-29 13:52 ` [PATCH v1 7/7] auxdisplay: arm-charlcd: Remove redundant ternary operators Andy Shevchenko
2026-01-07 21:06 ` [PATCH v1 0/7] auxdisplay: arm-charlcd: refactor with modern APIs Andy Shevchenko
2026-01-07 21:08 ` Andy Shevchenko
2026-01-09 11:30 ` Andy Shevchenko
2026-01-09 14:29 ` Linus Walleij
2026-01-09 16:15 ` Andy Shevchenko
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=20251229142349.1251843-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.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
Powered by JetHome