]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 24 Feb 2025 17:27:43 +0000 (19:27 +0200)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 10 Mar 2025 16:03:02 +0000 (18:03 +0200)
HD44780 APIs all operate on struct charlcd objects. Moreover, the current users
always call charlcd_alloc() and hd44780_common_alloc(). Make the latter call
the former, so eliminate the additional allocation, to make it consistent with
the rest of API and avoid duplication.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
drivers/auxdisplay/hd44780.c
drivers/auxdisplay/hd44780_common.c
drivers/auxdisplay/hd44780_common.h
drivers/auxdisplay/panel.c

index ef38cb7bf13d8bd9f4600ed58a2962b4ebe3de52..cef42656c4b0a00c1dad70e4836e3672c5e7ce69 100644 (file)
@@ -222,20 +222,17 @@ static int hd44780_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
-       hdc = hd44780_common_alloc();
-       if (!hdc)
-               return -ENOMEM;
-
-       lcd = charlcd_alloc(0);
+       lcd = hd44780_common_alloc();
        if (!lcd)
-               goto fail1;
+               return -ENOMEM;
 
        hd = kzalloc(sizeof(*hd), GFP_KERNEL);
        if (!hd)
                goto fail2;
 
+       hdc = lcd->drvdata;
        hdc->hd44780 = hd;
-       lcd->drvdata = hdc;
+
        for (i = 0; i < ifwidth; i++) {
                hd->pins[base + i] = devm_gpiod_get_index(dev, "data", i,
                                                          GPIOD_OUT_LOW);
@@ -313,9 +310,7 @@ static int hd44780_probe(struct platform_device *pdev)
 fail3:
        kfree(hd);
 fail2:
-       charlcd_free(lcd);
-fail1:
-       hd44780_common_free(hdc);
+       hd44780_common_free(lcd);
        return ret;
 }
 
@@ -326,8 +321,7 @@ static void hd44780_remove(struct platform_device *pdev)
 
        charlcd_unregister(lcd);
        kfree(hdc->hd44780);
-       hd44780_common_free(hdc);
-       charlcd_free(lcd);
+       hd44780_common_free(lcd);
 }
 
 static const struct of_device_id hd44780_of_match[] = {
index 3f8a496ccb8e6db6e30b1867a301e618f015bc99..fb340d18fcada674f23a86946155fee36f837d20 100644 (file)
@@ -351,24 +351,26 @@ int hd44780_common_redefine_char(struct charlcd *lcd, char *esc)
 }
 EXPORT_SYMBOL_GPL(hd44780_common_redefine_char);
 
-struct hd44780_common *hd44780_common_alloc(void)
+struct charlcd *hd44780_common_alloc(void)
 {
        struct hd44780_common *hd;
+       struct charlcd *lcd;
 
-       hd = kzalloc(sizeof(*hd), GFP_KERNEL);
-       if (!hd)
+       lcd = charlcd_alloc(sizeof(*hd));
+       if (!lcd)
                return NULL;
 
+       hd = lcd->drvdata;
        hd->ifwidth = 8;
        hd->bwidth = DEFAULT_LCD_BWIDTH;
        hd->hwidth = DEFAULT_LCD_HWIDTH;
-       return hd;
+       return lcd;
 }
 EXPORT_SYMBOL_GPL(hd44780_common_alloc);
 
-void hd44780_common_free(struct hd44780_common *hd)
+void hd44780_common_free(struct charlcd *lcd)
 {
-       kfree(hd);
+       charlcd_free(lcd);
 }
 EXPORT_SYMBOL_GPL(hd44780_common_free);
 
index fe1386e3cf7973004162117d8129f6951a5b66b1..4c87f55722b6695571ad13a3dc5e3ae99e116dcf 100644 (file)
@@ -31,5 +31,5 @@ int hd44780_common_fontsize(struct charlcd *lcd, enum charlcd_fontsize size);
 int hd44780_common_lines(struct charlcd *lcd, enum charlcd_lines lines);
 int hd44780_common_redefine_char(struct charlcd *lcd, char *esc);
 
-struct hd44780_common *hd44780_common_alloc(void);
-void hd44780_common_free(struct hd44780_common *hd);
+struct charlcd *hd44780_common_alloc(void);
+void hd44780_common_free(struct charlcd *lcd);
index aa1d03fef22e9725672dbbaa3b545e1fe142aa74..91ccb9789d4303587ad19bf474b9dd7fbd1c9510 100644 (file)
@@ -831,18 +831,12 @@ static void lcd_init(void)
        struct charlcd *charlcd;
        struct hd44780_common *hdc;
 
-       hdc = hd44780_common_alloc();
-       if (!hdc)
+       charlcd = hd44780_common_alloc();
+       if (!charlcd)
                return;
 
-       charlcd = charlcd_alloc(0);
-       if (!charlcd) {
-               hd44780_common_free(hdc);
-               return;
-       }
-
+       hdc = charlcd->drvdata;
        hdc->hd44780 = &lcd;
-       charlcd->drvdata = hdc;
 
        /*
         * Init lcd struct with load-time values to preserve exact
@@ -1664,7 +1658,7 @@ err_lcd_unreg:
        if (lcd.enabled)
                charlcd_unregister(lcd.charlcd);
 err_unreg_device:
-       charlcd_free(lcd.charlcd);
+       hd44780_common_free(lcd.charlcd);
        lcd.charlcd = NULL;
        parport_unregister_device(pprt);
        pprt = NULL;
@@ -1691,8 +1685,7 @@ static void panel_detach(struct parport *port)
        if (lcd.enabled) {
                charlcd_unregister(lcd.charlcd);
                lcd.initialized = false;
-               hd44780_common_free(lcd.charlcd->drvdata);
-               charlcd_free(lcd.charlcd);
+               hd44780_common_free(lcd.charlcd);
                lcd.charlcd = NULL;
        }