[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210811095759.1281480-4-geert@linux-m68k.org>
Date: Wed, 11 Aug 2021 11:57:43 +0200
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Robin van der Gracht <robin@...tonic.nl>,
Miguel Ojeda <ojeda@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Paul Burton <paulburton@...nel.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Pavel Machek <pavel@....cz>, Marek Behun <marek.behun@....cz>,
devicetree@...r.kernel.org, linux-leds@...r.kernel.org,
linux-mips@...r.kernel.org, linux-kernel@...r.kernel.org,
Geert Uytterhoeven <geert@...ux-m68k.org>
Subject: [PATCH v5 03/19] 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: 0cad855fbd083ee5 ("auxdisplay: img-ascii-lcd: driver for simple ASCII LCD displays")
Signed-off-by: Geert Uytterhoeven <geert@...ux-m68k.org>
---
Untested with img-ascii-lcd, but triggered with my initial version of
linedisp.
v5:
- No changes,
v4:
- No changes,
v3:
- No changes,
v2:
- No changes.
---
drivers/auxdisplay/img-ascii-lcd.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c
index 1cce409ce5cacbc8..e33ce0151cdfd150 100644
--- a/drivers/auxdisplay/img-ascii-lcd.c
+++ b/drivers/auxdisplay/img-ascii-lcd.c
@@ -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;
--
2.25.1
Powered by blists - more mailing lists