linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peilin Ye <yepeilin.cs@gmail.com>
To: Daniel Vetter <daniel@ffwll.ch>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Sven Schneider <s.schneider@arkona-technologies.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peilin Ye <yepeilin.cs@gmail.com>
Subject: [PATCH 1/2] Fonts: Support FONT_EXTRA_WORDS macros for font_6x8
Date: Sun, 18 Oct 2020 18:12:04 +0000	[thread overview]
Message-ID: <926453876c92caac34cba8545716a491754d04d5.1603037079.git.yepeilin.cs@gmail.com> (raw)
In-Reply-To: <20200820082137.5907-1-s.hauer@pengutronix.de>

Recently, in commit 6735b4632def ("Fonts: Support FONT_EXTRA_WORDS macros
for built-in fonts"), we wrapped each of our built-in data buffers in a
`font_data` structure, in order to use the following macros on them, see
include/linux/font.h:

	#define REFCOUNT(fd)	(((int *)(fd))[-1])
	#define FNTSIZE(fd)	(((int *)(fd))[-2])
	#define FNTCHARCNT(fd)	(((int *)(fd))[-3])
	#define FNTSUM(fd)	(((int *)(fd))[-4])

	#define FONT_EXTRA_WORDS 4

Do the same thing to our new 6x8 font. For built-in fonts, currently we
only use FNTSIZE(). Since this is only a temporary solution for an
out-of-bounds issue in the framebuffer layer (see commit 5af08640795b
("fbcon: Fix global-out-of-bounds read in fbcon_get_font()")), all the
three other fields are intentionally set to zero in order to discourage
using these negative-indexing macros.

Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
 lib/fonts/font_6x8.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/fonts/font_6x8.c b/lib/fonts/font_6x8.c
index e06447788418..700039a9ceae 100644
--- a/lib/fonts/font_6x8.c
+++ b/lib/fonts/font_6x8.c
@@ -3,8 +3,8 @@
 
 #define FONTDATAMAX 2048
 
-static const unsigned char fontdata_6x8[FONTDATAMAX] = {
-
+static struct font_data fontdata_6x8 = {
+	{ 0, 0, FONTDATAMAX, 0 }, {
 	/* 0 0x00 '^@' */
 	0x00, /* 000000 */
 	0x00, /* 000000 */
@@ -2564,13 +2564,13 @@ static const unsigned char fontdata_6x8[FONTDATAMAX] = {
 	0x00, /* 000000 */
 	0x00, /* 000000 */
 	0x00, /* 000000 */
-};
+} };
 
 const struct font_desc font_6x8 = {
 	.idx	= FONT6x8_IDX,
 	.name	= "6x8",
 	.width	= 6,
 	.height	= 8,
-	.data	= fontdata_6x8,
+	.data	= fontdata_6x8.data,
 	.pref	= 0,
 };
-- 
2.25.1

WARNING: multiple messages have this Message-ID (diff)
From: Peilin Ye <yepeilin.cs@gmail.com>
To: Daniel Vetter <daniel@ffwll.ch>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Sven Schneider <s.schneider@arkona-technologies.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peilin Ye <yepeilin.cs@gmail.com>
Subject: [PATCH 1/2] Fonts: Support FONT_EXTRA_WORDS macros for font_6x8
Date: Sun, 18 Oct 2020 14:12:04 -0400	[thread overview]
Message-ID: <926453876c92caac34cba8545716a491754d04d5.1603037079.git.yepeilin.cs@gmail.com> (raw)
Message-ID: <20201018181204.PUKZ1WDsV8ccuOPJ46c_WUj7gg3SmTUMrCROiezsRa8@z> (raw)
In-Reply-To: <20200820082137.5907-1-s.hauer@pengutronix.de>

Recently, in commit 6735b4632def ("Fonts: Support FONT_EXTRA_WORDS macros
for built-in fonts"), we wrapped each of our built-in data buffers in a
`font_data` structure, in order to use the following macros on them, see
include/linux/font.h:

	#define REFCOUNT(fd)	(((int *)(fd))[-1])
	#define FNTSIZE(fd)	(((int *)(fd))[-2])
	#define FNTCHARCNT(fd)	(((int *)(fd))[-3])
	#define FNTSUM(fd)	(((int *)(fd))[-4])

	#define FONT_EXTRA_WORDS 4

Do the same thing to our new 6x8 font. For built-in fonts, currently we
only use FNTSIZE(). Since this is only a temporary solution for an
out-of-bounds issue in the framebuffer layer (see commit 5af08640795b
("fbcon: Fix global-out-of-bounds read in fbcon_get_font()")), all the
three other fields are intentionally set to zero in order to discourage
using these negative-indexing macros.

Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
 lib/fonts/font_6x8.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/fonts/font_6x8.c b/lib/fonts/font_6x8.c
index e06447788418..700039a9ceae 100644
--- a/lib/fonts/font_6x8.c
+++ b/lib/fonts/font_6x8.c
@@ -3,8 +3,8 @@
 
 #define FONTDATAMAX 2048
 
-static const unsigned char fontdata_6x8[FONTDATAMAX] = {
-
+static struct font_data fontdata_6x8 = {
+	{ 0, 0, FONTDATAMAX, 0 }, {
 	/* 0 0x00 '^@' */
 	0x00, /* 000000 */
 	0x00, /* 000000 */
@@ -2564,13 +2564,13 @@ static const unsigned char fontdata_6x8[FONTDATAMAX] = {
 	0x00, /* 000000 */
 	0x00, /* 000000 */
 	0x00, /* 000000 */
-};
+} };
 
 const struct font_desc font_6x8 = {
 	.idx	= FONT6x8_IDX,
 	.name	= "6x8",
 	.width	= 6,
 	.height	= 8,
-	.data	= fontdata_6x8,
+	.data	= fontdata_6x8.data,
 	.pref	= 0,
 };
-- 
2.25.1


  parent reply	other threads:[~2020-10-18 18:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-20  8:21 [PATCH v2] lib/fonts: add font 6x8 for OLED display Sascha Hauer
2020-08-20  8:42 ` Greg Kroah-Hartman
2020-09-08 11:37   ` Bartlomiej Zolnierkiewicz
2020-10-18 18:12 ` Peilin Ye [this message]
2020-10-18 18:12   ` [PATCH 1/2] Fonts: Support FONT_EXTRA_WORDS macros for font_6x8 Peilin Ye
2020-10-18 18:14   ` [PATCH 2/2] docs: fb: Add font_6x8 to available built-in fonts Peilin Ye
2020-10-18 18:14     ` Peilin Ye
2020-10-18 20:54     ` [PATCH 2/2 RESEND] " Peilin Ye
2020-10-18 20:54       ` Peilin Ye
2020-10-19 15:56       ` Daniel Vetter
2020-10-19 15:56         ` Daniel Vetter
2020-10-18 20:09   ` [PATCH 1/2] Fonts: Support FONT_EXTRA_WORDS macros for font_6x8 Daniel Vetter
2020-10-18 20:09     ` Daniel Vetter
2020-10-18 20:18     ` Peilin Ye
2020-10-18 20:18       ` Peilin Ye
2020-10-18 20:33       ` Daniel Vetter
2020-10-18 20:33         ` Daniel Vetter
2020-10-18 20:44         ` Peilin Ye
2020-10-18 20:44           ` Peilin Ye
2020-10-18 21:51           ` Daniel Vetter
2020-10-18 21:51             ` Daniel Vetter
2020-10-19  9:55             ` Peilin Ye
2020-10-19  9:55               ` Peilin Ye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=926453876c92caac34cba8545716a491754d04d5.1603037079.git.yepeilin.cs@gmail.com \
    --to=yepeilin.cs@gmail.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=daniel@ffwll.ch \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=s.schneider@arkona-technologies.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).