Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A586C433F5 for ; Wed, 24 Nov 2021 12:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344319AbhKXMqb (ORCPT ); Wed, 24 Nov 2021 07:46:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:49656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243070AbhKXMls (ORCPT ); Wed, 24 Nov 2021 07:41:48 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C893B6124F; Wed, 24 Nov 2021 12:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637756689; bh=m37HfHA2uS4J8gVRrzVJJGhYBFkFrWGGDLvUYYhGtBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TrQ1hV11hjMpbPHmmO+R7jyUmUPOSfCHU8rXQLszZrNdLZweg8Sr2BFxAOclbSZHJ ZPXTR/wQS4gW1agvkseWwgpGgjq8MN2Co5gSPqJCJ1noSUvV9Chujd0JXLNv/EhKPu ZhwN8ORGqdRKLhEqyAK2GIf0V0i08pCG9M6FBAFQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Miguel Ojeda , Sasha Levin Subject: [PATCH 4.14 169/251] auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string Date: Wed, 24 Nov 2021 12:56:51 +0100 Message-Id: <20211124115716.137070329@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115710.214900256@linuxfoundation.org> References: <20211124115710.214900256@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Geert Uytterhoeven [ Upstream commit afcb5a811ff3ab3969f09666535eb6018a160358 ] 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 Signed-off-by: Miguel Ojeda Signed-off-by: Sasha Levin --- 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 58403052514f0..4d57185037a0d 100644 --- a/drivers/auxdisplay/img-ascii-lcd.c +++ b/drivers/auxdisplay/img-ascii-lcd.c @@ -284,6 +284,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.33.0