lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 22 Nov 2021 16:54:05 +0100
From:   Geert Uytterhoeven <geert+renesas@...der.be>
To:     Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc:     linux-kernel@...r.kernel.org,
        Geert Uytterhoeven <geert+renesas@...der.be>
Subject: [PATCH] intel_th: Use bitfield helpers

Use the FIELD_{GET,PREP}() helpers, instead of open-coding the same
operations.

Signed-off-by: Geert Uytterhoeven <geert+renesas@...der.be>
---
Compile-tested only.

See "[PATCH 00/17] Non-const bitfield helper conversions"
(https://lore.kernel.org/r/cover.1637592133.git.geert+renesas@glider.be)
for background and more conversions.
---
 drivers/hwtracing/intel_th/msu.c |  8 ++++----
 drivers/hwtracing/intel_th/pti.c | 13 +++++++------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/msu.c
index 432ade0842f68724..3ee5ad18f0a61ef6 100644
--- a/drivers/hwtracing/intel_th/msu.c
+++ b/drivers/hwtracing/intel_th/msu.c
@@ -7,6 +7,7 @@
 
 #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
 
+#include <linux/bitfield.h>
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/device.h>
@@ -789,8 +790,8 @@ static int msc_configure(struct msc *msc)
 	reg &= ~(MSC_MODE | MSC_WRAPEN | MSC_EN | MSC_RD_HDR_OVRD);
 
 	reg |= MSC_EN;
-	reg |= msc->mode << __ffs(MSC_MODE);
-	reg |= msc->burst_len << __ffs(MSC_LEN);
+	reg |= FIELD_PREP(MSC_MODE, msc->mode);
+	reg |= FIELD_PREP(MSC_LEN, msc->burst_len);
 
 	if (msc->wrap)
 		reg |= MSC_WRAPEN;
@@ -1691,8 +1692,7 @@ static int intel_th_msc_init(struct msc *msc)
 	INIT_LIST_HEAD(&msc->iter_list);
 
 	msc->burst_len =
-		(ioread32(msc->reg_base + REG_MSU_MSC0CTL) & MSC_LEN) >>
-		__ffs(MSC_LEN);
+		FIELD_GET(MSC_LEN, ioread32(msc->reg_base + REG_MSU_MSC0CTL));
 
 	return 0;
 }
diff --git a/drivers/hwtracing/intel_th/pti.c b/drivers/hwtracing/intel_th/pti.c
index 09132ab8bc23265a..eadc236ec43e0ad3 100644
--- a/drivers/hwtracing/intel_th/pti.c
+++ b/drivers/hwtracing/intel_th/pti.c
@@ -7,6 +7,7 @@
 
 #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
 
+#include <linux/bitfield.h>
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/device.h>
@@ -152,12 +153,12 @@ static int intel_th_pti_activate(struct intel_th_device *thdev)
 	u32 ctl = PTI_EN;
 
 	if (pti->patgen)
-		ctl |= pti->patgen << __ffs(PTI_PATGENMODE);
+		ctl |= FIELD_PREP(PTI_PATGENMODE, pti->patgen);
 	if (pti->freeclk)
 		ctl |= PTI_FCEN;
-	ctl |= pti->mode << __ffs(PTI_MODE);
-	ctl |= pti->clkdiv << __ffs(PTI_CLKDIV);
-	ctl |= pti->lpp_dest << __ffs(LPP_DEST);
+	ctl |= FIELD_PREP(PTI_MODE, pti->mode);
+	ctl |= FIELD_PREP(PTI_CLKDIV, pti->clkdiv);
+	ctl |= FIELD_PREP(LPP_DEST, pti->lpp_dest);
 
 	iowrite32(ctl, pti->base + REG_PTI_CTL);
 
@@ -179,8 +180,8 @@ static void read_hw_config(struct pti_device *pti)
 {
 	u32 ctl = ioread32(pti->base + REG_PTI_CTL);
 
-	pti->mode	= (ctl & PTI_MODE) >> __ffs(PTI_MODE);
-	pti->clkdiv	= (ctl & PTI_CLKDIV) >> __ffs(PTI_CLKDIV);
+	pti->mode	= FIELD_GET(PTI_MODE, ctl);
+	pti->clkdiv	= FIELD_GET(PTI_CLKDIV, ctl);
 	pti->freeclk	= !!(ctl & PTI_FCEN);
 
 	if (!pti_mode[pti->mode])
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ