Skip to contentSkip to conversation

auxdisplay: charlcd: Refactor memory allocation

PATCH In review Andy Shevchenko 2 participants 32 messages Feb 24, 2025 – Mar 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover auxdisplay: charlcd: Refactor memory allocation

The users of charlcd_alloc() call for additional memory allocation. We may do it at the time of the main call as many other APIs do. For this partially revert the change that brought us to the current state of affairs, and refactor the code based on the original implementation.

Andy Shevchenko (7):
auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to

    struct hd44780_common"

auxdisplay: lcd2s: Allocate memory for custom data in charlcd_alloc()
auxdisplay: hd44780: Introduce hd44780_common_free()
auxdisplay: hd44780: Make use of hd44780_common_free()
auxdisplay: panel: Make use of hd44780_common_free()
auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()
auxdisplay: hd44780: Rename hd to hdc in hd44780_common_alloc()

 drivers/auxdisplay/charlcd.c        |  5 +++--
 drivers/auxdisplay/charlcd.h        |  5 +++--
 drivers/auxdisplay/hd44780.c        | 19 ++++++-------------
 drivers/auxdisplay/hd44780_common.c | 24 ++++++++++++++++--------
 drivers/auxdisplay/hd44780_common.h |  4 +++-
 drivers/auxdisplay/lcd2s.c          | 12 ++++--------
 drivers/auxdisplay/panel.c          | 17 +++++------------
 7 files changed, 40 insertions(+), 46 deletions(-)
Signature · 1 line
2.45.1.3035.g276e886db78b
#1 lore raw

PATCH 1/7 auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct hd44780_common") makes charlcd_alloc() argument-less effectively dropping the single allocation for the struct charlcd_priv object along with the driver specific one. Restore that behaviour here.

---
 drivers/auxdisplay/charlcd.c | 5 +++--
 drivers/auxdisplay/charlcd.h | 5 +++--
 drivers/auxdisplay/hd44780.c | 2 +-
 drivers/auxdisplay/lcd2s.c   | 2 +-
 drivers/auxdisplay/panel.c   | 2 +-
 5 files changed, 9 insertions(+), 7 deletions(-)
drivers/auxdisplay/charlcd.c +3 -2
index 19b619376d48..09020bb8ad15 100644
@@ -595,18 +595,19 @@ static int charlcd_init(struct charlcd *lcd)
 	return 0;
 }
 
-struct charlcd *charlcd_alloc(void)
+struct charlcd *charlcd_alloc(unsigned int drvdata_size)
 {
 	struct charlcd_priv *priv;
 	struct charlcd *lcd;
 
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	priv = kzalloc(sizeof(*priv) + drvdata_size, GFP_KERNEL);
 	if (!priv)
 		return NULL;
 
 	priv->esc_seq.len = -1;
 
 	lcd = &priv->lcd;
+	lcd->drvdata = priv->drvdata;
 
 	return lcd;
 }
drivers/auxdisplay/charlcd.h +3 -2
index 4d4287209d04..d10b89740bca 100644
@@ -51,7 +51,7 @@ struct charlcd {
 		unsigned long y;
 	} addr;
 
-	void *drvdata;
+	void *drvdata;			/* Set by charlcd_alloc() */
 };
 
 /**
@@ -95,7 +95,8 @@ struct charlcd_ops {
 };
 
 void charlcd_backlight(struct charlcd *lcd, enum charlcd_onoff on);
-struct charlcd *charlcd_alloc(void);
+
+struct charlcd *charlcd_alloc(unsigned int drvdata_size);
 void charlcd_free(struct charlcd *lcd);
 
 int charlcd_register(struct charlcd *lcd);
drivers/auxdisplay/hd44780.c +1 -1
index 9d0ae9c02e9b..1d67fe324341 100644
@@ -226,7 +226,7 @@ static int hd44780_probe(struct platform_device *pdev)
 	if (!hdc)
 		return -ENOMEM;
 
-	lcd = charlcd_alloc();
+	lcd = charlcd_alloc(0);
 	if (!lcd)
 		goto fail1;
 
drivers/auxdisplay/lcd2s.c +1 -1
index f831ce762508..d573d36e3067 100644
@@ -310,7 +310,7 @@ static int lcd2s_i2c_probe(struct i2c_client *i2c)
 	if (err < 0)
 		return err;
 
-	lcd = charlcd_alloc();
+	lcd = charlcd_alloc(0);
 	if (!lcd)
 		return -ENOMEM;
 
drivers/auxdisplay/panel.c +1 -1
index 6dc8798d01f9..4da142692d55 100644
@@ -835,7 +835,7 @@ static void lcd_init(void)
 	if (!hdc)
 		return;
 
-	charlcd = charlcd_alloc();
+	charlcd = charlcd_alloc(0);
 	if (!charlcd) {
 		kfree(hdc);
 		return;
Signature · 1 line
2.45.1.3035.g276e886db78b
reviewer Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Hi Andy,

Thanks for your patch!

Quoted 1 line · Andy Shevchenko

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Quoted 5 lines

hd44780_common") makes charlcd_alloc() argument-less effectively dropping the single allocation for the struct charlcd_priv object along with the driver specific one. Restore that behaviour here.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Quoted 6 lines · Geert Uytterhoeven

Hi Andy,

Quoted 1 line · Andy Shevchenko

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

My English is not native I would appreciate a link to a material to study the case you pointed out.

Quoted 7 lines
Quoted 5 lines

hd44780_common") makes charlcd_alloc() argument-less effectively dropping the single allocation for the struct charlcd_priv object along with the driver specific one. Restore that behaviour here.

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Hi Andy,

Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 1 line · Andy Shevchenko

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

You can have a noun with or without an article:
- "a commit": an unspecified commit,
- "the commit": a specific commit, specified by context.
- "commit 1234abcd": a specific commit, specified by what follows.

Quoted 2 lines

My English is not native I would appreciate a link to a material to study the case you pointed out.

Neither is mine, but the use of articles is similar in English and Dutch. (I am aware your mother tongue does not have articles ;-)

I found plenty of articles explaining cases 1 and 2. Case 3 can be considered equivalent to "Mount Everest" in
https://learnenglish.britishcouncil.org/grammar/a1-a2-grammar/articles-the-or-no-article

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

You can have a noun with or without an article:

This is not so simple :-), esp. if a noun is a weekday or a toponym.

Quoted 7 lines

- "a commit": an unspecified commit,
- "the commit": a specific commit, specified by context.
- "commit 1234abcd": a specific commit, specified by what follows.

Quoted 2 lines

My English is not native I would appreciate a link to a material to study the case you pointed out.

Quoted 6 lines

Neither is mine, but the use of articles is similar in English and Dutch. (I am aware your mother tongue does not have articles ;-)

I found plenty of articles explaining cases 1 and 2. Case 3 can be considered equivalent to "Mount Everest" in
https://learnenglish.britishcouncil.org/grammar/a1-a2-grammar/articles-the-or-no-article

Okay, so you actually think that the hash and the title can be considered as "name of a place". Hmm... I don't think it applies here. It's not a place. Moreover some places require "the" article.

Here https://www.butte.edu/departments/cas/tipsheets/grammar/articles.html,
for example, the sentence "The 2003 federal budget" sounds to me closer to our case. Every year there is a federal budget, but we explicitly point out to one and reader knows what is this. The same with the commit.

Sorry, but I am still not convinced.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Hi Andy,

Quoted 26 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

You can have a noun with or without an article:

This is not so simple :-), esp. if a noun is a weekday or a toponym.

Quoted 10 lines

- "a commit": an unspecified commit,
- "the commit": a specific commit, specified by context.
- "commit 1234abcd": a specific commit, specified by what follows.

Quoted 2 lines

My English is not native I would appreciate a link to a material to study the case you pointed out.

Neither is mine, but the use of articles is similar in English and Dutch. (I am aware your mother tongue does not have articles ;-)

Quoted 7 lines
Quoted 3 lines

I found plenty of articles explaining cases 1 and 2. Case 3 can be considered equivalent to "Mount Everest" in
https://learnenglish.britishcouncil.org/grammar/a1-a2-grammar/articles-the-or-no-article

Okay, so you actually think that the hash and the title can be considered as "name of a place". Hmm... I don't think it applies here. It's not a place. Moreover some places require "the" article.

Only if they are a region, not if they are a country (yes, that's unrelated here).

Quoted 6 lines

Here https://www.butte.edu/departments/cas/tipsheets/grammar/articles.html,
for example, the sentence "The 2003 federal budget" sounds to me closer to our case. Every year there is a federal budget, but we explicitly point out to one and reader knows what is this. The same with the commit.

Sorry, but I am still not convinced.

In "The 2003 federal budget", both "2003" and "federal" are adjectives. In "commit 1234abcd", "1234abcd" is a name.

Cfr. "King Charles". "The King Charles" would be used only when putting a very special emphasis on "king".

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#7 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Quoted 44 lines · Geert Uytterhoeven
Quoted 26 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

You can have a noun with or without an article:

This is not so simple :-), esp. if a noun is a weekday or a toponym.

Quoted 10 lines

- "a commit": an unspecified commit,
- "the commit": a specific commit, specified by context.
- "commit 1234abcd": a specific commit, specified by what follows.

Quoted 2 lines

My English is not native I would appreciate a link to a material to study the case you pointed out.

Neither is mine, but the use of articles is similar in English and Dutch. (I am aware your mother tongue does not have articles ;-)

Quoted 7 lines
Quoted 3 lines

I found plenty of articles explaining cases 1 and 2. Case 3 can be considered equivalent to "Mount Everest" in
https://learnenglish.britishcouncil.org/grammar/a1-a2-grammar/articles-the-or-no-article

Okay, so you actually think that the hash and the title can be considered as "name of a place". Hmm... I don't think it applies here. It's not a place. Moreover some places require "the" article.

Only if they are a region, not if they are a country (yes, that's unrelated here).

Quoted 5 lines

Here https://www.butte.edu/departments/cas/tipsheets/grammar/articles.html,
for example, the sentence "The 2003 federal budget" sounds to me closer to our case. Every year there is a federal budget, but we explicitly point out to one and reader knows what is this. The same with the commit.

Quoted 7 lines
Quoted 1 line

Sorry, but I am still not convinced.

In "The 2003 federal budget", both "2003" and "federal" are adjectives. In "commit 1234abcd", "1234abcd" is a name.

Cfr. "King Charles". "The King Charles" would be used only when putting a very special emphasis on "king".

I have talked to the language teacher (okay, her native is not English), and she told me that no article is for the cases of location, person, or character. None of that category the commit falls into.

So, still not convinced.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Hi Andy,

Quoted 50 lines · Andy Shevchenko
Quoted 49 lines · Geert Uytterhoeven
Quoted 26 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

You can have a noun with or without an article:

This is not so simple :-), esp. if a noun is a weekday or a toponym.

Quoted 10 lines

- "a commit": an unspecified commit,
- "the commit": a specific commit, specified by context.
- "commit 1234abcd": a specific commit, specified by what follows.

Quoted 2 lines

My English is not native I would appreciate a link to a material to study the case you pointed out.

Neither is mine, but the use of articles is similar in English and Dutch. (I am aware your mother tongue does not have articles ;-)

Quoted 7 lines
Quoted 3 lines

I found plenty of articles explaining cases 1 and 2. Case 3 can be considered equivalent to "Mount Everest" in
https://learnenglish.britishcouncil.org/grammar/a1-a2-grammar/articles-the-or-no-article

Okay, so you actually think that the hash and the title can be considered as "name of a place". Hmm... I don't think it applies here. It's not a place. Moreover some places require "the" article.

Only if they are a region, not if they are a country (yes, that's unrelated here).

Quoted 6 lines

Here https://www.butte.edu/departments/cas/tipsheets/grammar/articles.html,
for example, the sentence "The 2003 federal budget" sounds to me closer to our case. Every year there is a federal budget, but we explicitly point out to one and reader knows what is this. The same with the commit.

Sorry, but I am still not convinced.

In "The 2003 federal budget", both "2003" and "federal" are adjectives. In "commit 1234abcd", "1234abcd" is a name.

Quoted 8 lines
Quoted 2 lines

Cfr. "King Charles". "The King Charles" would be used only when putting a very special emphasis on "king".

I have talked to the language teacher (okay, her native is not English), and she told me that no article is for the cases of location, person, or character. None of that category the commit falls into.

So, still not convinced.

I have a hard time finding the official rule (git commits did not exist when English grammar was written ;-)... Examples are easier to find. E.g. the first sentence on [1] does not start with an article:

European route E40 is the longest European route.

[1] https://en.wikipedia.org/wiki/European_route_E40

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#9 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

Quoted 59 lines · Geert Uytterhoeven
Quoted 57 lines · Andy Shevchenko
Quoted 44 lines · Geert Uytterhoeven
Quoted 26 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

You can have a noun with or without an article:

This is not so simple :-), esp. if a noun is a weekday or a toponym.

Quoted 10 lines

- "a commit": an unspecified commit,
- "the commit": a specific commit, specified by context.
- "commit 1234abcd": a specific commit, specified by what follows.

Quoted 2 lines

My English is not native I would appreciate a link to a material to study the case you pointed out.

Neither is mine, but the use of articles is similar in English and Dutch. (I am aware your mother tongue does not have articles ;-)

Quoted 7 lines
Quoted 3 lines

I found plenty of articles explaining cases 1 and 2. Case 3 can be considered equivalent to "Mount Everest" in
https://learnenglish.britishcouncil.org/grammar/a1-a2-grammar/articles-the-or-no-article

Okay, so you actually think that the hash and the title can be considered as "name of a place". Hmm... I don't think it applies here. It's not a place. Moreover some places require "the" article.

Only if they are a region, not if they are a country (yes, that's unrelated here).

Quoted 5 lines

Here https://www.butte.edu/departments/cas/tipsheets/grammar/articles.html,
for example, the sentence "The 2003 federal budget" sounds to me closer to our case. Every year there is a federal budget, but we explicitly point out to one and reader knows what is this. The same with the commit.

Quoted 7 lines
Quoted 1 line

Sorry, but I am still not convinced.

In "The 2003 federal budget", both "2003" and "federal" are adjectives. In "commit 1234abcd", "1234abcd" is a name.

Cfr. "King Charles". "The King Charles" would be used only when putting a very special emphasis on "king".

I have talked to the language teacher (okay, her native is not English), and she told me that no article is for the cases of location, person, or character. None of that category the commit falls into.

Quoted 7 lines
Quoted 1 line

So, still not convinced.

I have a hard time finding the official rule (git commits did not exist when English grammar was written ;-)... Examples are easier to find. E.g. the first sentence on [1] does not start with an article:

European route E40 is the longest European route.

I believe this falls to the "location" category. Can you find something which is not related to geography?

Quoted 1 line

[1] https://en.wikipedia.org/wiki/European_route_E40

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

Re: [PATCH v1 1/7] auxdisplay: charlcd: Partially revert "Move hwidth and bwidth to struct hd44780_common"

In reply to Geert Uytterhoeven
Quoted 59 lines · Geert Uytterhoeven
Quoted 57 lines · Andy Shevchenko
Quoted 44 lines · Geert Uytterhoeven
Quoted 26 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The commit 2545c1c948a6 ("auxdisplay: Move hwidth and bwidth to struct

s/The commit/Commit/

Why? We know that we are talking about the very specific commit.

You can have a noun with or without an article:

This is not so simple :-), esp. if a noun is a weekday or a toponym.

Quoted 10 lines

- "a commit": an unspecified commit,
- "the commit": a specific commit, specified by context.
- "commit 1234abcd": a specific commit, specified by what follows.

Quoted 2 lines

My English is not native I would appreciate a link to a material to study the case you pointed out.

Neither is mine, but the use of articles is similar in English and Dutch. (I am aware your mother tongue does not have articles ;-)

Quoted 7 lines
Quoted 3 lines

I found plenty of articles explaining cases 1 and 2. Case 3 can be considered equivalent to "Mount Everest" in
https://learnenglish.britishcouncil.org/grammar/a1-a2-grammar/articles-the-or-no-article

Okay, so you actually think that the hash and the title can be considered as "name of a place". Hmm... I don't think it applies here. It's not a place. Moreover some places require "the" article.

Only if they are a region, not if they are a country (yes, that's unrelated here).

Quoted 5 lines

Here https://www.butte.edu/departments/cas/tipsheets/grammar/articles.html,
for example, the sentence "The 2003 federal budget" sounds to me closer to our case. Every year there is a federal budget, but we explicitly point out to one and reader knows what is this. The same with the commit.

Quoted 7 lines
Quoted 1 line

Sorry, but I am still not convinced.

In "The 2003 federal budget", both "2003" and "federal" are adjectives. In "commit 1234abcd", "1234abcd" is a name.

Cfr. "King Charles". "The King Charles" would be used only when putting a very special emphasis on "king".

I have talked to the language teacher (okay, her native is not English), and she told me that no article is for the cases of location, person, or character. None of that category the commit falls into.

Quoted 7 lines
Quoted 1 line

So, still not convinced.

I have a hard time finding the official rule (git commits did not exist when English grammar was written ;-)... Examples are easier to find. E.g. the first sentence on [1] does not start with an article:

European route E40 is the longest European route.

Okay, seems AI may help here. It tells that grammatically article is needed, but in technical texts (like this one) it's the usual case to drop it and it's considered grammatically correct.

We both are right but from different angles. And yours seems the winner today :)

I'll update the message accordingly.

Quoted 1 line

[1] https://en.wikipedia.org/wiki/European_route_E40

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

PATCH 2/7 auxdisplay: lcd2s: Allocate memory for custom data in charlcd_alloc()

In reply to Andy Shevchenko

Allocate memory for custom data in charlcd_alloc() instead of doing that explicitly in the driver.

---
 drivers/auxdisplay/lcd2s.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/auxdisplay/lcd2s.c +4 -8
index d573d36e3067..d18735665706 100644
@@ -301,20 +301,18 @@ static int lcd2s_i2c_probe(struct i2c_client *i2c)
 			I2C_FUNC_SMBUS_WRITE_BLOCK_DATA))
 		return -EIO;
 
-	lcd2s = devm_kzalloc(&i2c->dev, sizeof(*lcd2s), GFP_KERNEL);
-	if (!lcd2s)
-		return -ENOMEM;
-
 	/* Test, if the display is responding */
 	err = lcd2s_i2c_smbus_write_byte(i2c, LCD2S_CMD_DISPLAY_OFF);
 	if (err < 0)
 		return err;
 
-	lcd = charlcd_alloc(0);
+	lcd = charlcd_alloc(sizeof(*lcd2s));
 	if (!lcd)
 		return -ENOMEM;
 
-	lcd->drvdata = lcd2s;
+	lcd->ops = &lcd2s_ops;
+
+	lcd2s = lcd->drvdata;
 	lcd2s->i2c = i2c;
 	lcd2s->charlcd = lcd;
 
@@ -329,8 +327,6 @@ static int lcd2s_i2c_probe(struct i2c_client *i2c)
 	if (err)
 		goto fail1;
 
-	lcd->ops = &lcd2s_ops;
-
 	err = charlcd_register(lcd2s->charlcd);
 	if (err)
 		goto fail1;
Signature · 1 line
2.45.1.3035.g276e886db78b
reviewer Reviewed-by on v1 2/7
#12 lore raw

Re: [PATCH v1 2/7] auxdisplay: lcd2s: Allocate memory for custom data in charlcd_alloc()

Quoted 4 lines · Andy Shevchenko

Allocate memory for custom data in charlcd_alloc() instead of doing that explicitly in the driver.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#13 lore raw

PATCH 3/7 auxdisplay: hd44780: Introduce hd44780_common_free()

In reply to Andy Shevchenko

Introduce hd44780_common_free() for symmetrical operation to hd44780_common_alloc(). It will allow to modify the both in the future without touching the users.

---
 drivers/auxdisplay/hd44780_common.c | 6 ++++++
 drivers/auxdisplay/hd44780_common.h | 2 ++
 2 files changed, 8 insertions(+)
drivers/auxdisplay/hd44780_common.c +6 -0
index 4ef87c3118c0..3f8a496ccb8e 100644
@@ -366,5 +366,11 @@ struct hd44780_common *hd44780_common_alloc(void)
 }
 EXPORT_SYMBOL_GPL(hd44780_common_alloc);
 
+void hd44780_common_free(struct hd44780_common *hd)
+{
+	kfree(hd);
+}
+EXPORT_SYMBOL_GPL(hd44780_common_free);
+
 MODULE_DESCRIPTION("Common functions for HD44780 (and compatibles) LCD displays");
 MODULE_LICENSE("GPL");
drivers/auxdisplay/hd44780_common.h +2 -0
index a16aa8c29c99..fe1386e3cf79 100644
@@ -30,4 +30,6 @@ int hd44780_common_blink(struct charlcd *lcd, enum charlcd_onoff on);
 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);
Signature · 1 line
2.45.1.3035.g276e886db78b
reviewer Reviewed-by on v1 3/7
#14 lore raw

Re: [PATCH v1 3/7] auxdisplay: hd44780: Introduce hd44780_common_free()

Hi Andy,

Thanks for your patch!

Quoted 2 lines · Andy Shevchenko

Introduce hd44780_common_free() for symmetrical operation to hd44780_common_alloc(). It will allow to modify the both

s/the both/both

Quoted 3 lines

in the future without touching the users.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#15 lore raw

PATCH 4/7 auxdisplay: hd44780: Make use of hd44780_common_free()

In reply to Andy Shevchenko

Use the symmetrical API to free the common resources.

---
 drivers/auxdisplay/hd44780.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/auxdisplay/hd44780.c +2 -3
index 1d67fe324341..ef38cb7bf13d 100644
@@ -315,7 +315,7 @@ static int hd44780_probe(struct platform_device *pdev)
 fail2:
 	charlcd_free(lcd);
 fail1:
-	kfree(hdc);
+	hd44780_common_free(hdc);
 	return ret;
 }
 
@@ -326,8 +326,7 @@ static void hd44780_remove(struct platform_device *pdev)
 
 	charlcd_unregister(lcd);
 	kfree(hdc->hd44780);
-	kfree(lcd->drvdata);
-
+	hd44780_common_free(hdc);
 	charlcd_free(lcd);
 }
 
Signature · 1 line
2.45.1.3035.g276e886db78b
reviewer Reviewed-by on v1 4/7
#16 lore raw

Re: [PATCH v1 4/7] auxdisplay: hd44780: Make use of hd44780_common_free()

Hi Andy,

Quoted 3 lines · Andy Shevchenko

Use the symmetrical API to free the common resources.

Thanks for your patch!

Perhaps fold this into [PATCH v1 3/7]?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#17 lore raw

Re: [PATCH v1 4/7] auxdisplay: hd44780: Make use of hd44780_common_free()

Quoted 5 lines · Geert Uytterhoeven
Quoted 1 line · Andy Shevchenko

Use the symmetrical API to free the common resources.

Thanks!

Quoted 1 line

Perhaps fold this into [PATCH v1 3/7]?

I still think they are logically split.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#18 lore raw

PATCH 5/7 auxdisplay: panel: Make use of hd44780_common_free()

In reply to Andy Shevchenko

Use the symmetrical API to free the common resources.

---
 drivers/auxdisplay/panel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/panel.c +2 -2
index 4da142692d55..aa1d03fef22e 100644
@@ -837,7 +837,7 @@ static void lcd_init(void)
 
 	charlcd = charlcd_alloc(0);
 	if (!charlcd) {
-		kfree(hdc);
+		hd44780_common_free(hdc);
 		return;
 	}
 
@@ -1691,7 +1691,7 @@ static void panel_detach(struct parport *port)
 	if (lcd.enabled) {
 		charlcd_unregister(lcd.charlcd);
 		lcd.initialized = false;
-		kfree(lcd.charlcd->drvdata);
+		hd44780_common_free(lcd.charlcd->drvdata);
 		charlcd_free(lcd.charlcd);
 		lcd.charlcd = NULL;
 	}
Signature · 1 line
2.45.1.3035.g276e886db78b
reviewer Reviewed-by on v1 5/7
#19 lore raw

Re: [PATCH v1 5/7] auxdisplay: panel: Make use of hd44780_common_free()

Hi Andy,

Quoted 3 lines · Andy Shevchenko

Use the symmetrical API to free the common resources.

Thanks for your patch!

Perhaps fold this into [PATCH v1 3/7]?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#20 lore raw

Re: [PATCH v1 5/7] auxdisplay: panel: Make use of hd44780_common_free()

Quoted 5 lines · Geert Uytterhoeven
Quoted 1 line · Andy Shevchenko

Use the symmetrical API to free the common resources.

Thanks!

Quoted 1 line

Perhaps fold this into [PATCH v1 3/7]?

Since we are changing not only hd44780 parts, I made the split. But if you are insisting I may fold them.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#21 lore raw

Re: [PATCH v1 5/7] auxdisplay: panel: Make use of hd44780_common_free()

Hi Andy,

Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Geert Uytterhoeven
Quoted 1 line · Andy Shevchenko

Use the symmetrical API to free the common resources.

Quoted 8 lines
Quoted 1 line

Thanks!

Quoted 1 line

Perhaps fold this into [PATCH v1 3/7]?

Since we are changing not only hd44780 parts, I made the split. But if you are insisting I may fold them.

Up to you, you are the M ;-)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#22 lore raw

PATCH 6/7 auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()

In reply to Andy Shevchenko

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.

---
 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(-)
drivers/auxdisplay/hd44780.c +6 -12
index ef38cb7bf13d..cef42656c4b0 100644
@@ -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[] = {
drivers/auxdisplay/hd44780_common.c +8 -6
index 3f8a496ccb8e..fb340d18fcad 100644
@@ -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);
 
drivers/auxdisplay/hd44780_common.h +2 -2
index fe1386e3cf79..4c87f55722b6 100644
@@ -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);
drivers/auxdisplay/panel.c +5 -12
index aa1d03fef22e..91ccb9789d43 100644
@@ -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;
 	}
 
Signature · 1 line
2.45.1.3035.g276e886db78b
reviewer Reviewed-by on v1 6/7
#23 lore raw

Re: [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()

Hi Andy,

Thanks for your patch!

Quoted 1 line · Andy Shevchenko

HD44780 APIs are operate on struct charlcd object. Moreover, the current users

s/are/all/
s/object/objects/

Quoted 2 lines

always call charlcd_alloc() and hd44780_common_alloc(). Make the latter call the former, so eliminate the additional allocation, make it consistent with

either s/make/making/, or s/make/to make/

Quoted 3 lines

the rest of API and avoid duplication.

As the code looks correct to me:

Quoted 16 lines
drivers/auxdisplay/hd44780_common.c +4 -3
@@ -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)

drivers/auxdisplay/hd44780_common.c int hd44780_common_redefine_char(struct charlcd *lcd, char *esc) · line 369

Quoted 10 lines
drivers/auxdisplay/hd44780_common.c +2 -1
                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);

While I like the general idea, there are two things in the API I do not like:
1. The function is called "hd44780_common_alloc()", but returns a pointer to a different struct type than the name suggests,
2. The real "struct hd44780_common" must be obtained by the caller from charlcd.drvdata, which is of type "void *", i.e. unsafe.

What about changing it to e.g.?

    struct hd44780_common *hd44780_common_alloc(struct charlcd **lcd)

so you can return pointers to both structs?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#24 lore raw

Re: [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()

Quoted 10 lines · Geert Uytterhoeven
Quoted 1 line · Andy Shevchenko

HD44780 APIs are operate on struct charlcd object. Moreover, the current users

s/are/all/
s/object/objects/

Quoted 2 lines

always call charlcd_alloc() and hd44780_common_alloc(). Make the latter call the former, so eliminate the additional allocation, make it consistent with

Quoted 8 lines

either s/make/making/, or s/make/to make/

Quoted 3 lines

the rest of API and avoid duplication.

As the code looks correct to me:

Thanks I have corrected all grammar issues in the commit messages except one in the first patch which I do not understand.

...

Quoted 7 lines

While I like the general idea, there are two things in the API I do not like:
1. The function is called "hd44780_common_alloc()", but returns a pointer to a different struct type than the name suggests,
2. The real "struct hd44780_common" must be obtained by the caller from charlcd.drvdata, which is of type "void *", i.e. unsafe.

Quoted 5 lines

What about changing it to e.g.?

    struct hd44780_common *hd44780_common_alloc(struct charlcd **lcd)

so you can return pointers to both structs?

I don't like this prototype as it seems and feels confusing. Also note, the APIs are using struct charlcd while being in the hd44780 namespace. perhaps better to rename the function to hd44780_common_and_lcd_alloc()?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#25 lore raw

Re: [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()

Hi Andy,

Quoted 34 lines · Andy Shevchenko
Quoted 10 lines · Geert Uytterhoeven
Quoted 1 line · Andy Shevchenko

HD44780 APIs are operate on struct charlcd object. Moreover, the current users

s/are/all/
s/object/objects/

Quoted 2 lines

always call charlcd_alloc() and hd44780_common_alloc(). Make the latter call the former, so eliminate the additional allocation, make it consistent with

Quoted 8 lines

either s/make/making/, or s/make/to make/

Quoted 3 lines

the rest of API and avoid duplication.

As the code looks correct to me:

Thanks I have corrected all grammar issues in the commit messages except one in the first patch which I do not understand.

...

Quoted 9 lines

While I like the general idea, there are two things in the API I do not like:
1. The function is called "hd44780_common_alloc()", but returns a pointer to a different struct type than the name suggests,
2. The real "struct hd44780_common" must be obtained by the caller from charlcd.drvdata, which is of type "void *", i.e. unsafe.

What about changing it to e.g.?

Quoted 7 lines
Quoted 3 lines
    struct hd44780_common *hd44780_common_alloc(struct charlcd **lcd)

so you can return pointers to both structs?

I don't like this prototype as it seems and feels confusing. Also note, the APIs are using struct charlcd while being in the hd44780 namespace. perhaps better to rename the function to hd44780_common_and_lcd_alloc()?

That is one option.

Another option would be to add a "charlcd *lcd" member to struct hd44780_common.

That would allow to fix the other odd part in the API:

-void hd44780_common_free(struct charlcd *lcd) +void hd44780_common_free(struct hd4480_common *hd)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#26 lore raw

Re: [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()

Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

...

Quoted 19 lines
Quoted 9 lines
Quoted 9 lines

While I like the general idea, there are two things in the API I do not like:
1. The function is called "hd44780_common_alloc()", but returns a pointer to a different struct type than the name suggests,
2. The real "struct hd44780_common" must be obtained by the caller from charlcd.drvdata, which is of type "void *", i.e. unsafe.

What about changing it to e.g.?

Quoted 7 lines
Quoted 3 lines
    struct hd44780_common *hd44780_common_alloc(struct charlcd **lcd)

so you can return pointers to both structs?

I don't like this prototype as it seems and feels confusing. Also note, the APIs are using struct charlcd while being in the hd44780 namespace. perhaps better to rename the function to hd44780_common_and_lcd_alloc()?

That is one option.

Quoted 7 lines

Another option would be to add a "charlcd *lcd" member to struct hd44780_common.

That would allow to fix the other odd part in the API:

-void hd44780_common_free(struct charlcd *lcd) +void hd44780_common_free(struct hd4480_common *hd)

This I like better. In a separate patch I think?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#27 lore raw

Re: [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()

Hi Andy,

Quoted 31 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

...

Quoted 22 lines
Quoted 9 lines
Quoted 9 lines

While I like the general idea, there are two things in the API I do not like:
1. The function is called "hd44780_common_alloc()", but returns a pointer to a different struct type than the name suggests,
2. The real "struct hd44780_common" must be obtained by the caller from charlcd.drvdata, which is of type "void *", i.e. unsafe.

What about changing it to e.g.?

Quoted 7 lines
Quoted 3 lines
    struct hd44780_common *hd44780_common_alloc(struct charlcd **lcd)

so you can return pointers to both structs?

I don't like this prototype as it seems and feels confusing. Also note, the APIs are using struct charlcd while being in the hd44780 namespace. perhaps better to rename the function to hd44780_common_and_lcd_alloc()?

That is one option.

Another option would be to add a "charlcd *lcd" member to struct hd44780_common.

Quoted 6 lines
Quoted 4 lines

That would allow to fix the other odd part in the API:

-void hd44780_common_free(struct charlcd *lcd) +void hd44780_common_free(struct hd4480_common *hd)

This I like better. In a separate patch I think?

Fine for me...

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#28 lore raw

Re: [PATCH v1 6/7] auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()

Quoted 8 lines · Geert Uytterhoeven
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven

On Mon, 24 Feb 2025 at 18:30, Andy Shevchenko
<[email protected]> wrote:

...

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 9 lines
Quoted 9 lines

While I like the general idea, there are two things in the API I do not like:
1. The function is called "hd44780_common_alloc()", but returns a pointer to a different struct type than the name suggests,
2. The real "struct hd44780_common" must be obtained by the caller from charlcd.drvdata, which is of type "void *", i.e. unsafe.

What about changing it to e.g.?

Quoted 7 lines
Quoted 3 lines
    struct hd44780_common *hd44780_common_alloc(struct charlcd **lcd)

so you can return pointers to both structs?

I don't like this prototype as it seems and feels confusing. Also note, the APIs are using struct charlcd while being in the hd44780 namespace. perhaps better to rename the function to hd44780_common_and_lcd_alloc()?

That is one option.

Another option would be to add a "charlcd *lcd" member to struct hd44780_common.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

That would allow to fix the other odd part in the API:

-void hd44780_common_free(struct charlcd *lcd) +void hd44780_common_free(struct hd4480_common *hd)

This I like better. In a separate patch I think?

Fine for me...

Thanks, I will check what can I do, but currently it's not a high priority to me.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#29 lore raw

PATCH 7/7 auxdisplay: hd44780: Rename hd to hdc in hd44780_common_alloc()

In reply to Andy Shevchenko

The hd44780_common_alloc() uses hd for local variable while the respective header uses hdc, rename to make it consistent and avoid potential confuse with the drivers that use both for different reasons. No functional changes intended.

---
 drivers/auxdisplay/hd44780_common.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/auxdisplay/hd44780_common.c +6 -6
index fb340d18fcad..1792fe2a4460 100644
@@ -353,17 +353,17 @@ EXPORT_SYMBOL_GPL(hd44780_common_redefine_char);
 
 struct charlcd *hd44780_common_alloc(void)
 {
-	struct hd44780_common *hd;
+	struct hd44780_common *hdc;
 	struct charlcd *lcd;
 
-	lcd = charlcd_alloc(sizeof(*hd));
+	lcd = charlcd_alloc(sizeof(*hdc));
 	if (!lcd)
 		return NULL;
 
-	hd = lcd->drvdata;
-	hd->ifwidth = 8;
-	hd->bwidth = DEFAULT_LCD_BWIDTH;
-	hd->hwidth = DEFAULT_LCD_HWIDTH;
+	hdc = lcd->drvdata;
+	hdc->ifwidth = 8;
+	hdc->bwidth = DEFAULT_LCD_BWIDTH;
+	hdc->hwidth = DEFAULT_LCD_HWIDTH;
 	return lcd;
 }
 EXPORT_SYMBOL_GPL(hd44780_common_alloc);
Signature · 1 line
2.45.1.3035.g276e886db78b
#30 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

The users of charlcd_alloc() call for additional memory allocation. We may do it at the time of the main call as many other APIs do. For this partially revert the change that brought us to the current state of affairs, and refactor the code based on the original implementation.

Geert, if you are okay with this series, I want to proceed with it today.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#31 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

The users of charlcd_alloc() call for additional memory allocation. We may do it at the time of the main call as many other APIs do. For this partially revert the change that brought us to the current state of affairs, and refactor the code based on the original implementation.

Geert, if you are okay with this series, I want to proceed with it today.

Pushed to my review and testing queue, thanks!

P.S. If you think this shouldn't have been done, please tell me.

Signature · 2 lines
With Best Regards,
Andy Shevchenko