Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1259331rdb; Mon, 19 Feb 2024 09:04:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXo+AkWQ0ID+r1AAPcQU1yEGeWNrP8XsoC0yWSG40uVignYb3hnn/kSy9lhILTodRUOfCuQeSe0rwrfg6zrkthMAOWBS5e5DItkqXUopw== X-Google-Smtp-Source: AGHT+IHvVCN6jswUjDE04AxFgElkcplPwXVHzrMLL8ujUvuKoXgmIuaZp6+/1kIBjhXpWE+tcg+l X-Received: by 2002:ac8:7fca:0:b0:42c:1f01:ad24 with SMTP id b10-20020ac87fca000000b0042c1f01ad24mr14949342qtk.25.1708362261725; Mon, 19 Feb 2024 09:04:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708362261; cv=pass; d=google.com; s=arc-20160816; b=FcPsjqjejmSjTemEr1KdjerhUfUezyT9piRY8sRSS0s1gKJ4TtGCyctRKpxO8pa2Eu z4ZlW1FxYLxx5APupnFDLYYerDnQ+SKw/NWjiCZRsZfEgsztQDptSlWF5M0MQvJQ2aGx i/rlyd+6RG9PGYjdewvQdLH+wQnggXyby925pPd/dMBDr2R3w+SCNbKvht5fZ9n8RqN0 hmiNbw7AGzATJhizZ+K2nyw+404QQhsKjgBqqXiRBlmMM4d0fhbFEc5wkfh84uTHCVfI 0rR99ySRAJc2FChYEGG+SFDD24Rr5J9qoTPbfrCLixUZ2hp3oQRwcAc2Tky0EN6w7OF1 jQlg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qpMiEOXrS5HTVTb4Ym39EvH9q3F8efsC5s//DfQ5hLA=; fh=dqy4saYl98vaBioBitW8P99YvD9vNvqzqRubV0LdUlg=; b=CzipdTIXYcfcfyDvvXm6T8wDWgMCcWe7UXWYtrCjWqW4VEa3AL5hs7MOSzRpBgaZ0b nS+ziZRz/d+Ej7F5omdazbAvLu42jIi1HQYHR341bXDV4jnNRaPb1j63xfMiXUqcatX3 eOGs3m7J99ZxxiQpLXEm5eI7HGVuehg/MY76eBcWG7HijJmWZDh6jAZ3ehXFUq8hOT/L ety7izsIHw68RA3HlmxflwXi1K7K5klKedi3yWqWQA1WHftE5cnuYmRVZK4rKIIuW87a IxsDGh0QKhNMc4ToobSCmFHU07izksjKWxgpN1aF8wtd2JPZiRKanGeQw4rVQ6mMWbqx eptw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=je1kNWNv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71728-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f21-20020ac85d15000000b0042def413c13si6987707qtx.617.2024.02.19.09.04.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 09:04:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=je1kNWNv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71728-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 292441C22BD7 for ; Mon, 19 Feb 2024 17:04:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20F5244C90; Mon, 19 Feb 2024 17:03:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="je1kNWNv" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C83B446A6; Mon, 19 Feb 2024 17:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708362229; cv=none; b=lZ4nx9mXriOjtflHWY5/UfcWVa3Y7BGxHJlu6pfMRrwR3jw87uc7JDZb3rUYQXWQjsva7mP4kHS7uzNwohIjaL9VmJdoKQtKSHtpT4/JmE+25kK6ybpkCk6wDFkV94JjsNK9KNq9eSND1v+OSwfBvtQ2dX0iv0nI28g+l/3XUGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708362229; c=relaxed/simple; bh=I61aQrfxe8pltYJ1/AfqQL0Uek1s8wSiEP8xqVGCwiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jjZuzlcvqH93rgNKHGTKQpaY2Ww3aKfjhRbvq1GBsKvyX2TYFV76ZQZjL5U7qUfDxEgYrd+FyTsXrG+7+c7v7bPjs1liCDfnB0nXfdvCAmdgPGGXFjahN5alJd7tT3MtlIo+e5UIkKHm+b8NZ1QshQ/jyVNWf60zIWaf9jktMNM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=je1kNWNv; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708362228; x=1739898228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I61aQrfxe8pltYJ1/AfqQL0Uek1s8wSiEP8xqVGCwiU=; b=je1kNWNvx5iwzn3/oevvCiwzXpA8S91tunkbfBdO/4e5JU9PrygS6zTL FGm9wJTm+gnYq5/r6YNR+A76xOWIaYivvELcUNRs01mwUZdJqeo8SwszD VGTSYWbtSA+uUqt9lFMNHKqzdeNgK7vMp7kibr2sbd0TbilMQuz0rWA0T Xrb+xuo2AIcdAmtyKjv3kYOMI7tlcjETJdIBVXuscag2BuJHtdY5oCVU4 bkUJ2ET/3DEA3G+HRdO8qMBhmG8qp8sGiZlUOAiynGYHFjAP6hki17a9Y AsDRa8LXwpIFSRwjyb5mds/qKv63uw31tFMygsdWosgayECZRGidQfzvG Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2577405" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="2577405" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2024 09:03:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="936315353" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="936315353" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 19 Feb 2024 09:03:42 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 392CC49C; Mon, 19 Feb 2024 19:03:41 +0200 (EET) From: Andy Shevchenko To: Krzysztof Kozlowski , Andy Shevchenko , Geert Uytterhoeven , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robin van der Gracht , Paul Burton Subject: [PATCH v3 2/9] auxdisplay: linedisp: Allocate buffer for the string Date: Mon, 19 Feb 2024 18:58:01 +0200 Message-ID: <20240219170337.2161754-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240219170337.2161754-1-andriy.shevchenko@linux.intel.com> References: <20240219170337.2161754-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Always allocate a buffer for the currently displayed characters. It makes the line display API simpler. Signed-off-by: Andy Shevchenko --- drivers/auxdisplay/ht16k33.c | 8 +++----- drivers/auxdisplay/img-ascii-lcd.c | 17 +++++++---------- drivers/auxdisplay/line-display.c | 11 +++++++---- drivers/auxdisplay/line-display.h | 3 +-- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c index 32d3afd29177..19805f39a257 100644 --- a/drivers/auxdisplay/ht16k33.c +++ b/drivers/auxdisplay/ht16k33.c @@ -92,7 +92,6 @@ struct ht16k33_seg { struct seg14_conversion_map seg14; } map; unsigned int map_size; - char curr[4]; }; struct ht16k33_priv { @@ -457,7 +456,7 @@ static void ht16k33_seg7_update(struct work_struct *work) struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv, work.work); struct ht16k33_seg *seg = &priv->seg; - char *s = seg->curr; + char *s = seg->linedisp.buf; uint8_t buf[9]; buf[0] = map_to_seg7(&seg->map.seg7, *s++); @@ -478,7 +477,7 @@ static void ht16k33_seg14_update(struct work_struct *work) struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv, work.work); struct ht16k33_seg *seg = &priv->seg; - char *s = seg->curr; + char *s = seg->linedisp.buf; uint8_t buf[8]; put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf); @@ -700,8 +699,7 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv, if (err) return err; - err = linedisp_register(&seg->linedisp, dev, 4, seg->curr, - &ht16k33_linedisp_ops); + err = linedisp_register(&seg->linedisp, dev, 4, &ht16k33_linedisp_ops); if (err) goto err_remove_map_file; diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c index ecfb1c05bf55..925c4cd101e9 100644 --- a/drivers/auxdisplay/img-ascii-lcd.c +++ b/drivers/auxdisplay/img-ascii-lcd.c @@ -37,7 +37,6 @@ struct img_ascii_lcd_config { * @regmap: the regmap through which LCD registers are accessed * @offset: the offset within regmap to the start of the LCD registers * @cfg: pointer to the LCD model configuration - * @curr: the string currently displayed on the LCD */ struct img_ascii_lcd_ctx { struct linedisp linedisp; @@ -47,7 +46,6 @@ struct img_ascii_lcd_ctx { }; u32 offset; const struct img_ascii_lcd_config *cfg; - char curr[] __aligned(8); }; /* @@ -61,12 +59,12 @@ static void boston_update(struct linedisp *linedisp) ulong val; #if BITS_PER_LONG == 64 - val = *((u64 *)&ctx->curr[0]); + val = *((u64 *)&linedisp->buf[0]); __raw_writeq(val, ctx->base); #elif BITS_PER_LONG == 32 - val = *((u32 *)&ctx->curr[0]); + val = *((u32 *)&linedisp->buf[0]); __raw_writel(val, ctx->base); - val = *((u32 *)&ctx->curr[4]); + val = *((u32 *)&linedisp->buf[4]); __raw_writel(val, ctx->base + 4); #else # error Not 32 or 64 bit @@ -93,7 +91,7 @@ static void malta_update(struct linedisp *linedisp) for (i = 0; i < linedisp->num_chars; i++) { err = regmap_write(ctx->regmap, - ctx->offset + (i * 8), ctx->curr[i]); + ctx->offset + (i * 8), linedisp->buf[i]); if (err) break; } @@ -195,7 +193,7 @@ static void sead3_update(struct linedisp *linedisp) err = regmap_write(ctx->regmap, ctx->offset + SEAD3_REG_LCD_DATA, - ctx->curr[i]); + linedisp->buf[i]); if (err) break; } @@ -236,7 +234,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev) struct img_ascii_lcd_ctx *ctx; int err; - ctx = devm_kzalloc(dev, sizeof(*ctx) + cfg->num_chars, GFP_KERNEL); + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -253,8 +251,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev) return PTR_ERR(ctx->base); } - err = linedisp_register(&ctx->linedisp, dev, cfg->num_chars, ctx->curr, - &cfg->ops); + err = linedisp_register(&ctx->linedisp, dev, cfg->num_chars, &cfg->ops); if (err) return err; diff --git a/drivers/auxdisplay/line-display.c b/drivers/auxdisplay/line-display.c index 13be7c2f6bc3..e2b546210f8d 100644 --- a/drivers/auxdisplay/line-display.c +++ b/drivers/auxdisplay/line-display.c @@ -265,6 +265,7 @@ static void linedisp_release(struct device *dev) kfree(linedisp->map); kfree(linedisp->message); + kfree(linedisp->buf); ida_free(&linedisp_id, linedisp->id); } @@ -316,14 +317,12 @@ static int linedisp_init_map(struct linedisp *linedisp) * @linedisp: pointer to character line display structure * @parent: parent device * @num_chars: the number of characters that can be displayed - * @buf: pointer to a buffer that can hold @num_chars characters * @ops: character line display operations * * Return: zero on success, else a negative error code. */ int linedisp_register(struct linedisp *linedisp, struct device *parent, - unsigned int num_chars, char *buf, - const struct linedisp_ops *ops) + unsigned int num_chars, const struct linedisp_ops *ops) { int err; @@ -331,7 +330,6 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent, linedisp->dev.parent = parent; linedisp->dev.type = &linedisp_type; linedisp->ops = ops; - linedisp->buf = buf; linedisp->num_chars = num_chars; linedisp->scroll_rate = DEFAULT_SCROLL_RATE; @@ -343,6 +341,11 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent, device_initialize(&linedisp->dev); dev_set_name(&linedisp->dev, "linedisp.%u", linedisp->id); + err = -ENOMEM; + linedisp->buf = kzalloc(linedisp->num_chars, GFP_KERNEL); + if (!linedisp->buf) + goto out_put_device; + /* initialise a character mapping, if required */ err = linedisp_init_map(linedisp); if (err) diff --git a/drivers/auxdisplay/line-display.h b/drivers/auxdisplay/line-display.h index 4e310b0e611e..4348d7a2f69a 100644 --- a/drivers/auxdisplay/line-display.h +++ b/drivers/auxdisplay/line-display.h @@ -82,8 +82,7 @@ struct linedisp { }; int linedisp_register(struct linedisp *linedisp, struct device *parent, - unsigned int num_chars, char *buf, - const struct linedisp_ops *ops); + unsigned int num_chars, const struct linedisp_ops *ops); void linedisp_unregister(struct linedisp *linedisp); #endif /* LINEDISP_H */ -- 2.43.0.rc1.1.gbec44491f096