public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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>,
	Willy Tarreau <willy@haproxy.com>,
	Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
Subject: [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()
Date: Mon, 24 Feb 2025 19:27:43 +0200	[thread overview]
Message-ID: <20250224173010.219024-7-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20250224173010.219024-1-andriy.shevchenko@linux.intel.com>

HD44780 APIs are operate on struct charlcd object. Moreover, the current users
always call charlcd_alloc() and hd44780_common_alloc(). Make the latter call
the former, so eliminate the additional allocation, make it consistent with
the rest of API and avoid duplication.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/auxdisplay/hd44780.c        | 18 ++++++------------
 drivers/auxdisplay/hd44780_common.c | 14 ++++++++------
 drivers/auxdisplay/hd44780_common.h |  4 ++--
 drivers/auxdisplay/panel.c          | 17 +++++------------
 4 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/drivers/auxdisplay/hd44780.c b/drivers/auxdisplay/hd44780.c
index ef38cb7bf13d..cef42656c4b0 100644
--- a/drivers/auxdisplay/hd44780.c
+++ b/drivers/auxdisplay/hd44780.c
@@ -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[] = {
diff --git a/drivers/auxdisplay/hd44780_common.c b/drivers/auxdisplay/hd44780_common.c
index 3f8a496ccb8e..fb340d18fcad 100644
--- a/drivers/auxdisplay/hd44780_common.c
+++ b/drivers/auxdisplay/hd44780_common.c
@@ -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);
 
diff --git a/drivers/auxdisplay/hd44780_common.h b/drivers/auxdisplay/hd44780_common.h
index fe1386e3cf79..4c87f55722b6 100644
--- a/drivers/auxdisplay/hd44780_common.h
+++ b/drivers/auxdisplay/hd44780_common.h
@@ -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);
diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c
index aa1d03fef22e..91ccb9789d43 100644
--- a/drivers/auxdisplay/panel.c
+++ b/drivers/auxdisplay/panel.c
@@ -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 @@ static void panel_attach(struct parport *port)
 	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;
 	}
 
-- 
2.45.1.3035.g276e886db78b


  parent reply	other threads:[~2025-02-24 17:30 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24 17:27 [PATCH v1 0/7] auxdisplay: charlcd: Refactor memory allocation Andy Shevchenko
2025-02-24 17:27 ` [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common" Andy Shevchenko
2025-03-07  9:03   ` Geert Uytterhoeven
2025-03-07 16:57     ` Andy Shevchenko
2025-03-07 18:14       ` Geert Uytterhoeven
2025-03-07 18:57         ` Andy Shevchenko
2025-03-07 19:05           ` Geert Uytterhoeven
2025-03-10  8:12             ` Andy Shevchenko
2025-03-10  9:39               ` Geert Uytterhoeven
2025-03-10 10:53                 ` Andy Shevchenko
2025-03-10 15:15                 ` Andy Shevchenko
2025-02-24 17:27 ` [PATCH v1 2/7] auxdisplay: lcd2s: Allocate memory for custom data in charlcd_alloc() Andy Shevchenko
2025-03-07  9:03   ` Geert Uytterhoeven
2025-02-24 17:27 ` [PATCH v1 3/7] auxdisplay: hd44780: Introduce hd44780_common_free() Andy Shevchenko
2025-03-07  9:04   ` Geert Uytterhoeven
2025-02-24 17:27 ` [PATCH v1 4/7] auxdisplay: hd44780: Make use of hd44780_common_free() Andy Shevchenko
2025-03-07  9:05   ` Geert Uytterhoeven
2025-03-07 17:00     ` Andy Shevchenko
2025-02-24 17:27 ` [PATCH v1 5/7] auxdisplay: panel: " Andy Shevchenko
2025-03-07  9:05   ` Geert Uytterhoeven
2025-03-07 17:02     ` Andy Shevchenko
2025-03-07 18:14       ` Geert Uytterhoeven
2025-02-24 17:27 ` Andy Shevchenko [this message]
2025-03-07  9:14   ` [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc() Geert Uytterhoeven
2025-03-07 17:08     ` Andy Shevchenko
2025-03-07 18:19       ` Geert Uytterhoeven
2025-03-07 19:01         ` Andy Shevchenko
2025-03-07 19:06           ` Geert Uytterhoeven
2025-03-10  8:14             ` Andy Shevchenko
2025-02-24 17:27 ` [PATCH v1 7/7] auxdisplay: hd44780: Rename hd to hdc in hd44780_common_alloc() Andy Shevchenko
2025-03-03 10:30 ` [PATCH v1 0/7] auxdisplay: charlcd: Refactor memory allocation Andy Shevchenko
2025-03-04 14:29   ` 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=20250224173010.219024-7-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=ksenija.stanojevic@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@haproxy.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