Skip to content

Commit afcb5a8

Browse files
geertuojeda
authored andcommitted
auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string
While writing an empty string to a device attribute is a no-op, and thus does not need explicit safeguards, the user can still write a single newline to an attribute file: echo > .../message If that happens, img_ascii_lcd_display() trims the newline, yielding an empty string, and causing an infinite loop in img_ascii_lcd_scroll(). Fix this by adding a check for empty strings. Clear the display in case one is encountered. Fixes: 0cad855 ("auxdisplay: img-ascii-lcd: driver for simple ASCII LCD displays") Signed-off-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent ae53c69 commit afcb5a8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/auxdisplay/img-ascii-lcd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@ static int img_ascii_lcd_display(struct img_ascii_lcd_ctx *ctx,
280280
if (msg[count - 1] == '\n')
281281
count--;
282282

283+
if (!count) {
284+
/* clear the LCD */
285+
devm_kfree(&ctx->pdev->dev, ctx->message);
286+
ctx->message = NULL;
287+
ctx->message_len = 0;
288+
memset(ctx->curr, ' ', ctx->cfg->num_chars);
289+
ctx->cfg->update(ctx);
290+
return 0;
291+
}
292+
283293
new_msg = devm_kmalloc(&ctx->pdev->dev, count + 1, GFP_KERNEL);
284294
if (!new_msg)
285295
return -ENOMEM;

0 commit comments

Comments
 (0)