Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1119300pxv; Fri, 25 Jun 2021 06:01:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSjpuuWd7tkYQDQdrX9aVfti+vD8CIufss0doSW1kibg7oY1fc8i36wQQ1Wc/Xu45G5ThJ X-Received: by 2002:adf:e904:: with SMTP id f4mr11101432wrm.334.1624626084224; Fri, 25 Jun 2021 06:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624626084; cv=none; d=google.com; s=arc-20160816; b=G4AtTld3036V3x3EAQ+qgak2ajs6Jdmdpm4Y1y3HSj7wSuOdzRLCF7wQn0hiI1/xeE HaIAUHbfDtIXlV9OWI7ZSZdc81RYd5k3OpUYHHfViE9PnuNY6t/9JkFLlrHrtwQBeJpl ooaXnihQsmQR+t2GYH1AlKZ3JvtKZVGzkyH9YVyDWNIcyfUDiUqs0QuF8ondZiTnBvHY cqikojty5W1L//z77npjQ896EtEax10O9PE9JjNg4rbcVbiXX4ppXCr5BkcWXnreofwn VsgVZtoNpFta8CfewI+wFHCWv8HN91QI2vcaFPbCvn+BgCpYk/uzuYCqHT+Do/Qqryy+ uDOA== 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=cq7zaky+gsyOWFa75SpcWNbFvcu2Y/8rXuOP80NXAj8=; b=dJ01Ev32Dz34ePCODhoKmajSbx6LcDrt12/e3/k/cgqzgN1bvlKezo+xWpVImOg5rm y0m5miOrJa96j7f6TSnfxxA2VD1hEVCcK9OvlrGmLlKqcJbJOEs2GTS1o9MJWahIkSgd LPLSF6qTtZb/vRSdvDKbCmqjPCnuKZlCfKNs8mvLwbO0NQo1DUztHGJnQTM1vD0C2KVe QXA5SzeMK0dyvytTSUrdoHkshXIWLXSHiDCceEu37WVO88YwILRMx/K2wXcksZo3YPb8 0G111jzcPxSB/EEjT/XGxkteE8Zwjl8JcVU4CD7LkEtxyERqzgruiKlIfXd6rzx7CRGE Etag== 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 gz10si5286445ejc.389.2021.06.25.06.01.00; Fri, 25 Jun 2021 06:01:24 -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 S231932AbhFYNCL (ORCPT + 99 others); Fri, 25 Jun 2021 09:02:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbhFYNBq (ORCPT ); Fri, 25 Jun 2021 09:01:46 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E66E1C0619FE for ; Fri, 25 Jun 2021 05:59:17 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:1476:ce84:e216:add8]) by xavier.telenet-ops.be with bizsmtp id MQzC2500T2B1U9901QzCdp; Fri, 25 Jun 2021 14:59:14 +0200 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 1lwlQO-003TMC-CD; Fri, 25 Jun 2021 14:59:12 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1lwlQN-004sQE-Gl; Fri, 25 Jun 2021 14:59:11 +0200 From: Geert Uytterhoeven To: Robin van der Gracht , Rob Herring , Miguel Ojeda , Paul Burton , Greg Kroah-Hartman , Pavel Machek Cc: devicetree@vger.kernel.org, linux-leds@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 03/18] auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string Date: Fri, 25 Jun 2021 14:58:47 +0200 Message-Id: <20210625125902.1162428-4-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210625125902.1162428-1-geert@linux-m68k.org> References: <20210625125902.1162428-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. 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