Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3500653pxf; Mon, 22 Mar 2021 07:53:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2J9/2v1FkOSVaLF2rA+ochAqlRZFmI8uSIxib2mPy0Ku2tDcDS12qvf6If9y00iDPhqHy X-Received: by 2002:a17:906:c210:: with SMTP id d16mr112452ejz.187.1616424782804; Mon, 22 Mar 2021 07:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616424782; cv=none; d=google.com; s=arc-20160816; b=RU1hkm0fKeXAa8roD1bCb/+uYQinvr0aI0LJnlyoVtqExG4D96hKVXqRtSxChUqltl YBAg6l5njrRkB2KVC/cgWnVzFuFq+P4vwN0GXP8SvTy/GQfqr/Nmy3mPBdDk2ZZwBwFQ sD+WJWhjwg5vSXwHII9n6AkhFMu1tfino3RIV03L7HHSeFwR9EN27O4ZEmolnLYVIYEj lVf/WJN+0TpV2Z0X5HkgVhFcHmpJGWl1TgyOxVPVSTYW3Qg4v5K9j7yfacnE3RGd8nLs DdcCRK/Wd34KJllwSGz/zejFshYQrQpvqsqsSr6bgYV53qQLelrhCcMXclBhE2G9PplU BKPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3QM5JdCHrw3QnNrvVAZ3H5yCHNeqBvjxRtrpVztUOR4=; b=ev5bwLiL/uAhRBCqNObXqj/c5XmroTKXu4pVGysvQXKgLEHsbuGha/0hBd7DAia/wx 7bdysOxlN33tOm5mnz99r076IaK7NXtVpMV6Wp5ooq/uzsobRA6ZMDZr1173j0MC8yoS 4sri4gNBeWippkPELCrOHP7myeprO4rYq/3Q65Dgn70nUwon2DrFDt0ZsbmLneX8+mKi CYk1df/Pt54VaXcQa8PcfT/4I+aZjAVgLw8Erzuw8W2MLvIYqeE/jw44ebncweB4eovJ YmB3IB/TGWwwzuQh+5rRpI/AiaXddY2ZhUX80aLQyGD8NKcdIZvwX0lFq+mKE/sSClfp lb0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si11093426eja.638.2021.03.22.07.52.40; Mon, 22 Mar 2021 07:53:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231360AbhCVOuD (ORCPT + 99 others); Mon, 22 Mar 2021 10:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbhCVOtB (ORCPT ); Mon, 22 Mar 2021 10:49:01 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAAE4C0613AA for ; Mon, 22 Mar 2021 07:48:55 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:250b:f16c:c5e2:505d]) by michel.telenet-ops.be with bizsmtp id jSot2400m2HDxaV06SotqS; Mon, 22 Mar 2021 15:48:53 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lOLrQ-009ZWC-UW; Mon, 22 Mar 2021 15:48:52 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1lOLrP-004T5l-GS; Mon, 22 Mar 2021 15:48:51 +0100 From: Geert Uytterhoeven To: Robin van der Gracht , Rob Herring , Miguel Ojeda , Paul Burton , Greg Kroah-Hartman Cc: devicetree@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 03/17] auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string Date: Mon, 22 Mar 2021 15:48:34 +0100 Message-Id: <20210322144848.1065067-4-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210322144848.1065067-1-geert@linux-m68k.org> References: <20210322144848.1065067-1-geert@linux-m68k.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Untested with img-ascii-lcd, but triggered with my initial version of linedisp. --- 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