linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ARM: ptrace: Use bitfield helpers
@ 2024-02-15 13:54 Geert Uytterhoeven
  2024-02-15 17:50 ` Oleg Nesterov
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2024-02-15 13:54 UTC (permalink / raw)
  To: Oleg Nesterov, Russell King, Uwe Kleine-König
  Cc: linux-arm-kernel, linux-kernel, Geert Uytterhoeven

The isa_mode() macro extracts two fields, and recombines them into a
single value.

Make this more obvious by using the FIELD_GET() helper, and shifting the
result into its final resting place.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
No changes in generated assembler code.

v2:
  - Drop irrelevant comment about non-existing off-by-one error,
  - Remove unnecessary parens.
---
 arch/arm/include/asm/ptrace.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h
index 7f44e88d1f25bcc5..14a38cc67e0bc966 100644
--- a/arch/arm/include/asm/ptrace.h
+++ b/arch/arm/include/asm/ptrace.h
@@ -10,6 +10,7 @@
 #include <uapi/asm/ptrace.h>
 
 #ifndef __ASSEMBLY__
+#include <linux/bitfield.h>
 #include <linux/types.h>
 
 struct pt_regs {
@@ -35,8 +36,8 @@ struct svc_pt_regs {
 
 #ifndef CONFIG_CPU_V7M
 #define isa_mode(regs) \
-	((((regs)->ARM_cpsr & PSR_J_BIT) >> (__ffs(PSR_J_BIT) - 1)) | \
-	 (((regs)->ARM_cpsr & PSR_T_BIT) >> (__ffs(PSR_T_BIT))))
+	(FIELD_GET(PSR_J_BIT, (regs)->ARM_cpsr) << 1 | \
+	 FIELD_GET(PSR_T_BIT, (regs)->ARM_cpsr))
 #else
 #define isa_mode(regs) 1 /* Thumb */
 #endif
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ARM: ptrace: Use bitfield helpers
  2024-02-15 13:54 [PATCH v2] ARM: ptrace: Use bitfield helpers Geert Uytterhoeven
@ 2024-02-15 17:50 ` Oleg Nesterov
  0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2024-02-15 17:50 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Russell King, Uwe Kleine-König, linux-arm-kernel,
	linux-kernel

Sorry for the noise, can't resist...

I am replying only because I wasn't aware of bitfield.h and useful
helpers there.

Thank you ;)

On 02/15, Geert Uytterhoeven wrote:
>
>  #ifndef __ASSEMBLY__
> +#include <linux/bitfield.h>
>  #include <linux/types.h>
>
>  struct pt_regs {
> @@ -35,8 +36,8 @@ struct svc_pt_regs {
>
>  #ifndef CONFIG_CPU_V7M
>  #define isa_mode(regs) \
> -	((((regs)->ARM_cpsr & PSR_J_BIT) >> (__ffs(PSR_J_BIT) - 1)) | \
> -	 (((regs)->ARM_cpsr & PSR_T_BIT) >> (__ffs(PSR_T_BIT))))
> +	(FIELD_GET(PSR_J_BIT, (regs)->ARM_cpsr) << 1 | \
> +	 FIELD_GET(PSR_T_BIT, (regs)->ARM_cpsr))

Reviewed-by: Oleg Nesterov <oleg@redhat.com>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-15 17:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-15 13:54 [PATCH v2] ARM: ptrace: Use bitfield helpers Geert Uytterhoeven
2024-02-15 17:50 ` Oleg Nesterov

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).