Message ID | 20240212170423.2860895-11-andriy.shevchenko@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-62051-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp80598dyb; Mon, 12 Feb 2024 10:05:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJiO9C3aN+CosezvDEPrTIb4DEdzeeIgFGs7hA7czVv8xCmIl0JuOB8HpK+W1ib15kkL31 X-Received: by 2002:a05:6358:33a5:b0:178:94bc:72f1 with SMTP id i37-20020a05635833a500b0017894bc72f1mr9736201rwd.22.1707761112189; Mon, 12 Feb 2024 10:05:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707761112; cv=pass; d=google.com; s=arc-20160816; b=Wu20uiMHRHPaW+Qhzpppghc7LyGBmvF5lU4M6v0vXWbavRyCJY8wHvAJyJxo68d7hC rKiy/7Fc7inPCHTO5Su58k4LNjPXpe2Y4OAKDULNEzuJTl2ZTRNPzcCAUuBgu+KkhYCc FmEh3N2l/iTy1aZXEUVcixdOJJMArTz5IdcZYWlY3P5ocYFPs5QqivGw97NJAUN0Qd3U UCiIb1UGtX8zUIQwtQG3Vc8Pkmt5+Irb2rx38jWBVYVZrYOYkJmcjzHwQAxTBJE5GPtB /4ThQOSgmToYtr9PFC6l/bVr1ImTphXdAOtpI3JU2tNxxHRXMUYBJjA420OB2x8aG5Ja s4NQ== 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=6+oX/UcHZISim8TVlLTruFpg/kz2cigX2uvRvTwyPas=; fh=kn2qxq+4A8l9wRZXPmltBlObN8sOd2oFVUvBUeu8Gks=; b=dWc2JDvDc+A9QVULZiPNWz4WhueORDc12FWgXpmHwg4VYU5lJIh8SJfx5U7jSCrOJ1 vcdaUAjooE0KpJg59DvOS9CkVKb2l1O5QKCBBPDH4SpveFtkTgrgX50qlQ10PhVf0FdY OTArdIcYc7x20aHwtVnnFI2B70gox06ZT079VLHpF0R/OEpPu28fS3ROoOtR7F1QMiZM HmJ/oBTNiTtmskTtifEpnl/2uhGmzgw/wkMTQ2EHuXb+0r1Z4IpxAQUuhO3UhnBJnTZv 7+XIvWU6Y0pJGgnz4ojJT9f3+X96lPJz/7exYmUlyWmo6LqHsNA0xAmVb+Pg3ZcW3xde fVlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HLItknqn; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62051-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62051-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCW0JasIxuahiVrFZ5L/E8NQo0vZ3LQ8xTr4OkKkAlG9TlIoQPkmgoFubraonX2D/8PsHv6BIAYV9qVEHoTryLfbPA7OOw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e18-20020ac85992000000b0042bf171ffe8si1067699qte.524.2024.02.12.10.05.12 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 10:05:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62051-ouuuleilei=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=HLItknqn; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62051-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62051-ouuuleilei=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 1148E1C220D8 for <ouuuleilei@gmail.com>; Mon, 12 Feb 2024 17:10:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A6934DA1B; Mon, 12 Feb 2024 17:04:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HLItknqn" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 1EF9F4776F; Mon, 12 Feb 2024 17:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757495; cv=none; b=ULi6FFrOfR9GFSzag23dPOiXfixjRfxqx4+hCQ0Gp7FkdOe2il8Y9poIS5fONSUhKz4z/b0nwIR8w/ZbLNxFim2K/+5oAF6Ei3gtMoGrTwwzlTBDdYQKpcYyCSD3Z+P/QoQpW5NreA+y3GClQjL+PlMR83hwBA5KBL/ytJbw9N4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757495; c=relaxed/simple; bh=bZSIwuNODdqGZ3IZxNzcIUdpLQwmXGNmwkHg29fDE5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XHFvWHKHNGGAbRNiXhW2ikgGWD2gWighTwDq2L0m8N/ubwAefJ9Wi0webPARCg8evQHoQXz2F0Roz+NAZKFSYyLzNtTuLwSZT33XzyqMjUgqZzvBFHFUWoMm6bN/F1AGsn4fCEyp691wewp/5P8TnKtvbOD72j00qDN0HUDcBW0= 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=HLItknqn; arc=none smtp.client-ip=198.175.65.10 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=1707757494; x=1739293494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bZSIwuNODdqGZ3IZxNzcIUdpLQwmXGNmwkHg29fDE5g=; b=HLItknqnrSl76axjDpRdgjb6axGJNLnDp0gr3Ewsuv8GeLOLJa+DFP4J KcvvdZ86Bx5BgbgAfmuYlU5scywnY2pSQLqYO9O8UscssSNo4hiF1sKBV yQEGbMszB09Hxv/Mk/DdE6wejlIaKfMfZcENr4Bpw7Pn6a8qJVT0BVLaQ udiylNtgX4wPyfDCjrt5eswjTY6vI4KnHXqftPEgpAULoypmqH802/dSW yD/6YLUTUTaaJVkRIEDyq6eyTugdDPTLhxvTeg/xeO8xD90FGa3YX43KN OTWop5xVGH7qI8ER7OfMm/0ByiX7exZw1v2f0FlC8kGoR1pvtrBXoB73I Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="19153224" X-IronPort-AV: E=Sophos;i="6.06,264,1705392000"; d="scan'208";a="19153224" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 09:04:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="935116826" X-IronPort-AV: E=Sophos;i="6.06,264,1705392000"; d="scan'208";a="935116826" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 09:04:47 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 09521338; Mon, 12 Feb 2024 19:04:43 +0200 (EET) From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko <andy@kernel.org>, Geert Uytterhoeven <geert@linux-m68k.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Robin van der Gracht <robin@protonic.nl>, Paul Burton <paulburton@kernel.org> Subject: [PATCH v2 10/15] auxdisplay: linedisp: Provide a small buffer in the struct linedisp Date: Mon, 12 Feb 2024 19:01:43 +0200 Message-ID: <20240212170423.2860895-11-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240212170423.2860895-1-andriy.shevchenko@linux.intel.com> References: <20240212170423.2860895-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790717316260488767 X-GMAIL-MSGID: 1790717316260488767 |
Series |
auxdisplay: linedisp: Clean up and add new driver
|
|
Commit Message
Andy Shevchenko
Feb. 12, 2024, 5:01 p.m. UTC
There is a driver that uses small buffer for the string, when we
add a new one, we may avoid duplication and use one provided by
the line display library. Allow user to skip buffer pointer when
registering a device.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/auxdisplay/line-display.c | 4 ++--
drivers/auxdisplay/line-display.h | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)
Comments
Hi Andy, On Mon, Feb 12, 2024 at 6:04 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > There is a driver that uses small buffer for the string, when we > add a new one, we may avoid duplication and use one provided by > the line display library. Allow user to skip buffer pointer when > registering a device. > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Thanks for your patch! > --- a/drivers/auxdisplay/line-display.c > +++ b/drivers/auxdisplay/line-display.c > @@ -330,8 +330,8 @@ 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->buf = buf ? buf : linedisp->curr; > + linedisp->num_chars = buf ? num_chars : min(num_chars, LINEDISP_DEFAULT_BUF_SZ); I think it would be safer to return an error if buf == NULL and num_chars < LINEDISP_DEFAULT_BUF_SZ. Else a careless driver that doesn't check linedisp->num_chars might overflow the buffer. > linedisp->scroll_rate = DEFAULT_SCROLL_RATE; > > err = ida_alloc(&linedisp_id, GFP_KERNEL); Gr{oetje,eeting}s, Geert
On Thu, Feb 15, 2024 at 11:40:44AM +0100, Geert Uytterhoeven wrote: > On Mon, Feb 12, 2024 at 6:04 PM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: .. > > + linedisp->buf = buf ? buf : linedisp->curr; > > + linedisp->num_chars = buf ? num_chars : min(num_chars, LINEDISP_DEFAULT_BUF_SZ); > > I think it would be safer to return an error if buf == NULL and > num_chars < LINEDISP_DEFAULT_BUF_SZ. I think you meant >= ? > Else a careless driver that doesn't check linedisp->num_chars might > overflow the buffer. Okay, check has been added.
On Thu, Feb 15, 2024 at 02:17:00PM +0200, Andy Shevchenko wrote: > On Thu, Feb 15, 2024 at 11:40:44AM +0100, Geert Uytterhoeven wrote: > > On Mon, Feb 12, 2024 at 6:04 PM Andy Shevchenko > > <andriy.shevchenko@linux.intel.com> wrote: .. > > > + linedisp->buf = buf ? buf : linedisp->curr; > > > + linedisp->num_chars = buf ? num_chars : min(num_chars, LINEDISP_DEFAULT_BUF_SZ); > > > > I think it would be safer to return an error if buf == NULL and > > num_chars < LINEDISP_DEFAULT_BUF_SZ. > > I think you meant >= ? > > > Else a careless driver that doesn't check linedisp->num_chars might > > overflow the buffer. > > Okay, check has been added. Hold on, but I have min() being called, isn't it enough?
Hi Andy, On Thu, Feb 15, 2024 at 1:19 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > On Thu, Feb 15, 2024 at 02:17:00PM +0200, Andy Shevchenko wrote: > > On Thu, Feb 15, 2024 at 11:40:44AM +0100, Geert Uytterhoeven wrote: > > > On Mon, Feb 12, 2024 at 6:04 PM Andy Shevchenko > > > <andriy.shevchenko@linux.intel.com> wrote: > > > > + linedisp->buf = buf ? buf : linedisp->curr; > > > > + linedisp->num_chars = buf ? num_chars : min(num_chars, LINEDISP_DEFAULT_BUF_SZ); > > > > > > I think it would be safer to return an error if buf == NULL and > > > num_chars < LINEDISP_DEFAULT_BUF_SZ. > > > > I think you meant >= ? Oops, yes/ > > > > > Else a careless driver that doesn't check linedisp->num_chars might > > > overflow the buffer. > > > > Okay, check has been added. > > Hold on, but I have min() being called, isn't it enough? Yes you have. A careless driver might not use linedisp->num_chars later, but instead just hardcode e.g. memcpy(linedisp->buf, source, LARGE_BUF_SIZE). Gr{oetje,eeting}s, Geert
On Thu, Feb 15, 2024 at 01:33:29PM +0100, Geert Uytterhoeven wrote: > On Thu, Feb 15, 2024 at 1:19 PM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: > > On Thu, Feb 15, 2024 at 02:17:00PM +0200, Andy Shevchenko wrote: > > > On Thu, Feb 15, 2024 at 11:40:44AM +0100, Geert Uytterhoeven wrote: > > > > On Mon, Feb 12, 2024 at 6:04 PM Andy Shevchenko > > > > <andriy.shevchenko@linux.intel.com> wrote: > > > > > + linedisp->buf = buf ? buf : linedisp->curr; > > > > > + linedisp->num_chars = buf ? num_chars : min(num_chars, LINEDISP_DEFAULT_BUF_SZ); > > > > > > > > I think it would be safer to return an error if buf == NULL and > > > > num_chars < LINEDISP_DEFAULT_BUF_SZ. > > > > > > I think you meant >= ? > > Oops, yes/ > > > > > > > > Else a careless driver that doesn't check linedisp->num_chars might > > > > overflow the buffer. > > > > > > Okay, check has been added. > > > > Hold on, but I have min() being called, isn't it enough? > > Yes you have. > > A careless driver might not use linedisp->num_chars later, but instead > just hardcode e.g. memcpy(linedisp->buf, source, LARGE_BUF_SIZE). I see the point, yes, we need an additional check.
diff --git a/drivers/auxdisplay/line-display.c b/drivers/auxdisplay/line-display.c index 75852ce6cc8d..d730cd0e1d03 100644 --- a/drivers/auxdisplay/line-display.c +++ b/drivers/auxdisplay/line-display.c @@ -330,8 +330,8 @@ 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->buf = buf ? buf : linedisp->curr; + linedisp->num_chars = buf ? num_chars : min(num_chars, LINEDISP_DEFAULT_BUF_SZ); linedisp->scroll_rate = DEFAULT_SCROLL_RATE; err = ida_alloc(&linedisp_id, GFP_KERNEL); diff --git a/drivers/auxdisplay/line-display.h b/drivers/auxdisplay/line-display.h index 65d782111f53..4c354b8f376e 100644 --- a/drivers/auxdisplay/line-display.h +++ b/drivers/auxdisplay/line-display.h @@ -54,12 +54,15 @@ struct linedisp_ops { void (*update)(struct linedisp *linedisp); }; +#define LINEDISP_DEFAULT_BUF_SZ 8u + /** * struct linedisp - character line display private data structure * @dev: the line display device * @id: instance id of this display * @timer: timer used to implement scrolling * @ops: character line display operations + * @curr: fallback buffer for the string * @buf: pointer to the buffer for the string currently displayed * @message: the full message to display or scroll on the display * @num_chars: the number of characters that can be displayed @@ -73,6 +76,7 @@ struct linedisp { struct timer_list timer; const struct linedisp_ops *ops; struct linedisp_map *map; + char curr[LINEDISP_DEFAULT_BUF_SZ]; char *buf; char *message; unsigned int num_chars;