Skip to content

Commit

Permalink
auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
geertu authored and ojeda committed Oct 21, 2021
1 parent ae53c69 commit afcb5a8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/auxdisplay/img-ascii-lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ static int img_ascii_lcd_display(struct img_ascii_lcd_ctx *ctx,
if (msg[count - 1] == '\n')
count--;

if (!count) {
/* clear the LCD */
devm_kfree(&ctx->pdev->dev, ctx->message);
ctx->message = NULL;
ctx->message_len = 0;
memset(ctx->curr, ' ', ctx->cfg->num_chars);
ctx->cfg->update(ctx);
return 0;
}

new_msg = devm_kmalloc(&ctx->pdev->dev, count + 1, GFP_KERNEL);
if (!new_msg)
return -ENOMEM;
Expand Down

0 comments on commit afcb5a8

Please sign in to comment.