* [PATCH] auxdisplay: cfag12864bfb: Fix init cleanup and simplify error paths
@ 2026-11-17 10:27 Haoxiang Li
2026-11-17 10:33 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2026-11-17 10:27 UTC (permalink / raw)
To: ojeda, andy, geert, pmarques, akpm, maxextreme; +Cc: linux-kernel, Haoxiang Li
If initialization fails after cfag12864b_enable() succeeds, LCD
refreshing remains enabled. A subsequent attempt to load the
framebuffer module can fail because refreshing is still marked
as in use.
Flatten the initialization flow and introduce cleanup labels to
release resources in reverse order. Call cfag12864b_disable() on
failures after refreshing has been enabled.
Fixes: 70e840499aae ("[PATCH] drivers: add LCD support")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
drivers/auxdisplay/cfag12864bfb.c | 34 +++++++++++++++++--------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/drivers/auxdisplay/cfag12864bfb.c b/drivers/auxdisplay/cfag12864bfb.c
index 24baf6b2c587..c507286641bd 100644
--- a/drivers/auxdisplay/cfag12864bfb.c
+++ b/drivers/auxdisplay/cfag12864bfb.c
@@ -118,13 +118,13 @@ static struct platform_device *cfag12864bfb_device;
static int __init cfag12864bfb_init(void)
{
- int ret = -EINVAL;
+ int ret;
/* cfag12864b_init() must be called first */
if (!cfag12864b_isinited()) {
printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
"cfag12864b is not initialized\n");
- goto none;
+ return -EINVAL;
}
if (cfag12864b_enable()) {
@@ -134,23 +134,27 @@ static int __init cfag12864bfb_init(void)
}
ret = platform_driver_register(&cfag12864bfb_driver);
+ if (ret)
+ goto err_disable;
- if (!ret) {
- cfag12864bfb_device =
- platform_device_alloc(CFAG12864BFB_NAME, 0);
+ cfag12864bfb_device = platform_device_alloc(CFAG12864BFB_NAME, 0);
+ if (!cfag12864bfb_device) {
+ ret = -ENOMEM;
+ goto err_unregister_driver;
+ }
- if (cfag12864bfb_device)
- ret = platform_device_add(cfag12864bfb_device);
- else
- ret = -ENOMEM;
+ ret = platform_device_add(cfag12864bfb_device);
+ if (ret)
+ goto err_put_device;
- if (ret) {
- platform_device_put(cfag12864bfb_device);
- platform_driver_unregister(&cfag12864bfb_driver);
- }
- }
+ return 0;
-none:
+err_put_device:
+ platform_device_put(cfag12864bfb_device);
+err_unregister_driver:
+ platform_driver_unregister(&cfag12864bfb_driver);
+err_disable:
+ cfag12864b_disable();
return ret;
}
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] auxdisplay: cfag12864bfb: Fix init cleanup and simplify error paths
2026-11-17 10:27 [PATCH] auxdisplay: cfag12864bfb: Fix init cleanup and simplify error paths Haoxiang Li
@ 2026-11-17 10:33 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2026-11-17 10:33 UTC (permalink / raw)
To: Haoxiang Li; +Cc: ojeda, andy, geert, pmarques, akpm, maxextreme, linux-kernel
On Tue, Nov 17, 2026 at 06:27:28PM +0800, Haoxiang Li wrote:
> If initialization fails after cfag12864b_enable() succeeds, LCD
> refreshing remains enabled. A subsequent attempt to load the
> framebuffer module can fail because refreshing is still marked
> as in use.
>
> Flatten the initialization flow and introduce cleanup labels to
> release resources in reverse order. Call cfag12864b_disable() on
> failures after refreshing has been enabled.
Can't you use platform_device_register_full()?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 10:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 10:27 [PATCH] auxdisplay: cfag12864bfb: Fix init cleanup and simplify error paths Haoxiang Li
2026-11-17 10:33 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®