mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Jiri Slaby" <jslaby@suse.cz>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH v2 6/8] tty/vt: consolemap: improve UNI_*() macros definitions
Date: Tue, 14 Jun 2022 11:05:35 +0200	[thread overview]
Message-ID: <20220614090537.15557-6-jslaby@suse.cz> (raw)
In-Reply-To: <20220614090537.15557-1-jslaby@suse.cz>

Use FIELD_GET() and GENMASK() helpers instead of direct shifts and ANDs.
This makes the code even more obvious. I didn't know about the helpers
at the time of writing the macros.

Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/consolemap.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 16d0d8f04f0e..9e94ec0e0f83 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -23,6 +23,8 @@
  * stack overflow.
  */
 
+#include <linux/bitfield.h>
+#include <linux/bits.h>
 #include <linux/module.h>
 #include <linux/kd.h>
 #include <linux/errno.h>
@@ -190,10 +192,17 @@ static enum translation_map inv_translate[MAX_NR_CONSOLES];
 #define UNI_DIR_ROWS	32U
 #define UNI_ROW_GLYPHS	64U
 
-#define UNI_DIR(uni)		( (uni)                   >> 11)
-#define UNI_ROW(uni)		(((uni) & GENMASK(10, 6)) >>  6)
-#define UNI_GLYPH(uni)		( (uni) & GENMASK( 5, 0))
-#define UNI(dir, row, glyph)	(((dir) << 11) | ((row) << 6) | (glyph))
+#define UNI_DIR_BITS		GENMASK(15, 11)
+#define UNI_ROW_BITS		GENMASK(10,  6)
+#define UNI_GLYPH_BITS		GENMASK( 5,  0)
+
+#define UNI_DIR(uni)		FIELD_GET(UNI_DIR_BITS, (uni))
+#define UNI_ROW(uni)		FIELD_GET(UNI_ROW_BITS, (uni))
+#define UNI_GLYPH(uni)		FIELD_GET(UNI_GLYPH_BITS, (uni))
+
+#define UNI(dir, row, glyph)	(FIELD_PREP(UNI_DIR_BITS, (dir)) | \
+				 FIELD_PREP(UNI_ROW_BITS, (row)) | \
+				 FIELD_PREP(UNI_GLYPH_BITS, (glyph)))
 
 /**
  * struct uni_pagedict -- unicode directory
-- 
2.36.1


  parent reply	other threads:[~2022-06-14  9:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14  7:57 [PATCH 1/7] tty/vt: consolemap: use ARRAY_SIZE(), part II Jiri Slaby
2022-06-14  7:57 ` [PATCH 2/7] tty/vt: consolemap: remove unused parameter from set_inverse_trans_unicode() Jiri Slaby
2022-06-14  7:57 ` [PATCH 3/7] tty/vt: consolemap: saner variable names in set_inverse_trans_unicode() Jiri Slaby
2022-06-14  7:57 ` [PATCH 4/7] tty/vt: consolemap: saner variable names in set_inverse_transl() Jiri Slaby
2022-06-14  8:35   ` Ilpo Järvinen
2022-06-14  8:40     ` Jiri Slaby
2022-06-14  7:57 ` [PATCH 5/7] tty/vt: consolemap: rename struct vc_data::vc_uni_pagedir* Jiri Slaby
2022-06-14  8:38   ` Ilpo Järvinen
2022-06-14  7:57 ` [PATCH 6/7] tty/vt: consolemap: improve UNI_*() macros definitions Jiri Slaby
2022-06-14  7:57 ` [PATCH 7/7] tty/vt: consolemap: remove dflt reset from con_do_clear_unimap() Jiri Slaby
2022-06-14  8:41   ` Ilpo Järvinen
2022-06-14  8:17 ` [PATCH 1/7] tty/vt: consolemap: use ARRAY_SIZE(), part II Ilpo Järvinen
2022-06-14  8:32   ` Ilpo Järvinen
2022-06-14  9:03   ` Jiri Slaby
2022-06-14  9:05 ` [PATCH v2 1/8] " Jiri Slaby
2022-06-14  9:05   ` [PATCH v2 2/8] tty/vt: consolemap: remove unused parameter from set_inverse_trans_unicode() Jiri Slaby
2022-06-14  9:05   ` [PATCH v2 3/8] tty/vt: consolemap: saner variable names in set_inverse_trans_unicode() Jiri Slaby
2022-06-14  9:05   ` [PATCH v2 4/8] tty/vt: consolemap: saner variable names in set_inverse_transl() Jiri Slaby
2022-06-14  9:05   ` [PATCH v2 5/8] tty/vt: consolemap: rename struct vc_data::vc_uni_pagedir* Jiri Slaby
2022-06-14  9:05   ` Jiri Slaby [this message]
2022-06-14  9:05   ` [PATCH v2 7/8] tty/vt: consolemap: remove dflt reset from con_do_clear_unimap() Jiri Slaby
2022-06-14  9:05   ` [PATCH v2 8/8] tty/vt: consolemap: use E_TABSZ for the translations size Jiri Slaby

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=20220614090537.15557-6-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®