Skip to content

Commit 65f095b

Browse files
committed
auxdisplay: hd44780: Call charlcd_alloc() from hd44780_common_alloc()
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>
1 parent 664d217 commit 65f095b

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

drivers/auxdisplay/hd44780.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,17 @@ static int hd44780_probe(struct platform_device *pdev)
222222
return -EINVAL;
223223
}
224224

225-
hdc = hd44780_common_alloc();
226-
if (!hdc)
227-
return -ENOMEM;
228-
229-
lcd = charlcd_alloc(0);
225+
lcd = hd44780_common_alloc();
230226
if (!lcd)
231-
goto fail1;
227+
return -ENOMEM;
232228

233229
hd = kzalloc(sizeof(*hd), GFP_KERNEL);
234230
if (!hd)
235231
goto fail2;
236232

233+
hdc = lcd->drvdata;
237234
hdc->hd44780 = hd;
238-
lcd->drvdata = hdc;
235+
239236
for (i = 0; i < ifwidth; i++) {
240237
hd->pins[base + i] = devm_gpiod_get_index(dev, "data", i,
241238
GPIOD_OUT_LOW);
@@ -313,9 +310,7 @@ static int hd44780_probe(struct platform_device *pdev)
313310
fail3:
314311
kfree(hd);
315312
fail2:
316-
charlcd_free(lcd);
317-
fail1:
318-
hd44780_common_free(hdc);
313+
hd44780_common_free(lcd);
319314
return ret;
320315
}
321316

@@ -326,8 +321,7 @@ static void hd44780_remove(struct platform_device *pdev)
326321

327322
charlcd_unregister(lcd);
328323
kfree(hdc->hd44780);
329-
hd44780_common_free(hdc);
330-
charlcd_free(lcd);
324+
hd44780_common_free(lcd);
331325
}
332326

333327
static const struct of_device_id hd44780_of_match[] = {

drivers/auxdisplay/hd44780_common.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,24 +351,26 @@ int hd44780_common_redefine_char(struct charlcd *lcd, char *esc)
351351
}
352352
EXPORT_SYMBOL_GPL(hd44780_common_redefine_char);
353353

354-
struct hd44780_common *hd44780_common_alloc(void)
354+
struct charlcd *hd44780_common_alloc(void)
355355
{
356356
struct hd44780_common *hd;
357+
struct charlcd *lcd;
357358

358-
hd = kzalloc(sizeof(*hd), GFP_KERNEL);
359-
if (!hd)
359+
lcd = charlcd_alloc(sizeof(*hd));
360+
if (!lcd)
360361
return NULL;
361362

363+
hd = lcd->drvdata;
362364
hd->ifwidth = 8;
363365
hd->bwidth = DEFAULT_LCD_BWIDTH;
364366
hd->hwidth = DEFAULT_LCD_HWIDTH;
365-
return hd;
367+
return lcd;
366368
}
367369
EXPORT_SYMBOL_GPL(hd44780_common_alloc);
368370

369-
void hd44780_common_free(struct hd44780_common *hd)
371+
void hd44780_common_free(struct charlcd *lcd)
370372
{
371-
kfree(hd);
373+
charlcd_free(lcd);
372374
}
373375
EXPORT_SYMBOL_GPL(hd44780_common_free);
374376

drivers/auxdisplay/hd44780_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ int hd44780_common_fontsize(struct charlcd *lcd, enum charlcd_fontsize size);
3131
int hd44780_common_lines(struct charlcd *lcd, enum charlcd_lines lines);
3232
int hd44780_common_redefine_char(struct charlcd *lcd, char *esc);
3333

34-
struct hd44780_common *hd44780_common_alloc(void);
35-
void hd44780_common_free(struct hd44780_common *hd);
34+
struct charlcd *hd44780_common_alloc(void);
35+
void hd44780_common_free(struct charlcd *lcd);

drivers/auxdisplay/panel.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -831,18 +831,12 @@ static void lcd_init(void)
831831
struct charlcd *charlcd;
832832
struct hd44780_common *hdc;
833833

834-
hdc = hd44780_common_alloc();
835-
if (!hdc)
834+
charlcd = hd44780_common_alloc();
835+
if (!charlcd)
836836
return;
837837

838-
charlcd = charlcd_alloc(0);
839-
if (!charlcd) {
840-
hd44780_common_free(hdc);
841-
return;
842-
}
843-
838+
hdc = charlcd->drvdata;
844839
hdc->hd44780 = &lcd;
845-
charlcd->drvdata = hdc;
846840

847841
/*
848842
* Init lcd struct with load-time values to preserve exact
@@ -1664,7 +1658,7 @@ static void panel_attach(struct parport *port)
16641658
if (lcd.enabled)
16651659
charlcd_unregister(lcd.charlcd);
16661660
err_unreg_device:
1667-
charlcd_free(lcd.charlcd);
1661+
hd44780_common_free(lcd.charlcd);
16681662
lcd.charlcd = NULL;
16691663
parport_unregister_device(pprt);
16701664
pprt = NULL;
@@ -1691,8 +1685,7 @@ static void panel_detach(struct parport *port)
16911685
if (lcd.enabled) {
16921686
charlcd_unregister(lcd.charlcd);
16931687
lcd.initialized = false;
1694-
hd44780_common_free(lcd.charlcd->drvdata);
1695-
charlcd_free(lcd.charlcd);
1688+
hd44780_common_free(lcd.charlcd);
16961689
lcd.charlcd = NULL;
16971690
}
16981691

0 commit comments

Comments
 (0)