[PATCH] auxdisplay: cfag12864bfb: Fix init cleanup and simplify error paths

From: Haoxiang Li

Date: Tue Nov 17 2026 - 05:28:38 EST


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@xxxxxxx>
---
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