Skip to content

Commit 4ce026d

Browse files
committed
auxdisplay: linedisp: Allocate buffer for the string
Always allocate a buffer for the currently displayed characters. It makes the line display API simpler. Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Tested-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent 34ddc83 commit 4ce026d

4 files changed

Lines changed: 18 additions & 21 deletions

File tree

drivers/auxdisplay/ht16k33.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ struct ht16k33_seg {
9292
struct seg14_conversion_map seg14;
9393
} map;
9494
unsigned int map_size;
95-
char curr[4];
9695
};
9796

9897
struct ht16k33_priv {
@@ -457,7 +456,7 @@ static void ht16k33_seg7_update(struct work_struct *work)
457456
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
458457
work.work);
459458
struct ht16k33_seg *seg = &priv->seg;
460-
char *s = seg->curr;
459+
char *s = seg->linedisp.buf;
461460
uint8_t buf[9];
462461

463462
buf[0] = map_to_seg7(&seg->map.seg7, *s++);
@@ -478,7 +477,7 @@ static void ht16k33_seg14_update(struct work_struct *work)
478477
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
479478
work.work);
480479
struct ht16k33_seg *seg = &priv->seg;
481-
char *s = seg->curr;
480+
char *s = seg->linedisp.buf;
482481
uint8_t buf[8];
483482

484483
put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf);
@@ -700,8 +699,7 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv,
700699
if (err)
701700
return err;
702701

703-
err = linedisp_register(&seg->linedisp, dev, 4, seg->curr,
704-
&ht16k33_linedisp_ops);
702+
err = linedisp_register(&seg->linedisp, dev, 4, &ht16k33_linedisp_ops);
705703
if (err)
706704
goto err_remove_map_file;
707705

drivers/auxdisplay/img-ascii-lcd.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ struct img_ascii_lcd_config {
3737
* @regmap: the regmap through which LCD registers are accessed
3838
* @offset: the offset within regmap to the start of the LCD registers
3939
* @cfg: pointer to the LCD model configuration
40-
* @curr: the string currently displayed on the LCD
4140
*/
4241
struct img_ascii_lcd_ctx {
4342
struct linedisp linedisp;
@@ -47,7 +46,6 @@ struct img_ascii_lcd_ctx {
4746
};
4847
u32 offset;
4948
const struct img_ascii_lcd_config *cfg;
50-
char curr[] __aligned(8);
5149
};
5250

5351
/*
@@ -61,12 +59,12 @@ static void boston_update(struct linedisp *linedisp)
6159
ulong val;
6260

6361
#if BITS_PER_LONG == 64
64-
val = *((u64 *)&ctx->curr[0]);
62+
val = *((u64 *)&linedisp->buf[0]);
6563
__raw_writeq(val, ctx->base);
6664
#elif BITS_PER_LONG == 32
67-
val = *((u32 *)&ctx->curr[0]);
65+
val = *((u32 *)&linedisp->buf[0]);
6866
__raw_writel(val, ctx->base);
69-
val = *((u32 *)&ctx->curr[4]);
67+
val = *((u32 *)&linedisp->buf[4]);
7068
__raw_writel(val, ctx->base + 4);
7169
#else
7270
# error Not 32 or 64 bit
@@ -93,7 +91,7 @@ static void malta_update(struct linedisp *linedisp)
9391

9492
for (i = 0; i < linedisp->num_chars; i++) {
9593
err = regmap_write(ctx->regmap,
96-
ctx->offset + (i * 8), ctx->curr[i]);
94+
ctx->offset + (i * 8), linedisp->buf[i]);
9795
if (err)
9896
break;
9997
}
@@ -195,7 +193,7 @@ static void sead3_update(struct linedisp *linedisp)
195193

196194
err = regmap_write(ctx->regmap,
197195
ctx->offset + SEAD3_REG_LCD_DATA,
198-
ctx->curr[i]);
196+
linedisp->buf[i]);
199197
if (err)
200198
break;
201199
}
@@ -236,7 +234,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev)
236234
struct img_ascii_lcd_ctx *ctx;
237235
int err;
238236

239-
ctx = devm_kzalloc(dev, sizeof(*ctx) + cfg->num_chars, GFP_KERNEL);
237+
ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
240238
if (!ctx)
241239
return -ENOMEM;
242240

@@ -253,8 +251,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev)
253251
return PTR_ERR(ctx->base);
254252
}
255253

256-
err = linedisp_register(&ctx->linedisp, dev, cfg->num_chars, ctx->curr,
257-
&cfg->ops);
254+
err = linedisp_register(&ctx->linedisp, dev, cfg->num_chars, &cfg->ops);
258255
if (err)
259256
return err;
260257

drivers/auxdisplay/line-display.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ static void linedisp_release(struct device *dev)
265265

266266
kfree(linedisp->map);
267267
kfree(linedisp->message);
268+
kfree(linedisp->buf);
268269
ida_free(&linedisp_id, linedisp->id);
269270
}
270271

@@ -316,22 +317,19 @@ static int linedisp_init_map(struct linedisp *linedisp)
316317
* @linedisp: pointer to character line display structure
317318
* @parent: parent device
318319
* @num_chars: the number of characters that can be displayed
319-
* @buf: pointer to a buffer that can hold @num_chars characters
320320
* @ops: character line display operations
321321
*
322322
* Return: zero on success, else a negative error code.
323323
*/
324324
int linedisp_register(struct linedisp *linedisp, struct device *parent,
325-
unsigned int num_chars, char *buf,
326-
const struct linedisp_ops *ops)
325+
unsigned int num_chars, const struct linedisp_ops *ops)
327326
{
328327
int err;
329328

330329
memset(linedisp, 0, sizeof(*linedisp));
331330
linedisp->dev.parent = parent;
332331
linedisp->dev.type = &linedisp_type;
333332
linedisp->ops = ops;
334-
linedisp->buf = buf;
335333
linedisp->num_chars = num_chars;
336334
linedisp->scroll_rate = DEFAULT_SCROLL_RATE;
337335

@@ -343,6 +341,11 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent,
343341
device_initialize(&linedisp->dev);
344342
dev_set_name(&linedisp->dev, "linedisp.%u", linedisp->id);
345343

344+
err = -ENOMEM;
345+
linedisp->buf = kzalloc(linedisp->num_chars, GFP_KERNEL);
346+
if (!linedisp->buf)
347+
goto out_put_device;
348+
346349
/* initialise a character mapping, if required */
347350
err = linedisp_init_map(linedisp);
348351
if (err)

drivers/auxdisplay/line-display.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ struct linedisp {
8282
};
8383

8484
int linedisp_register(struct linedisp *linedisp, struct device *parent,
85-
unsigned int num_chars, char *buf,
86-
const struct linedisp_ops *ops);
85+
unsigned int num_chars, const struct linedisp_ops *ops);
8786
void linedisp_unregister(struct linedisp *linedisp);
8887

8988
#endif /* LINEDISP_H */

0 commit comments

Comments
 (0)