public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/nmi: Simplify return statement in nmi_registers_valid()
@ 2025-09-08 15:32 Thorsten Blum
  2025-09-08 16:52 ` Alexander Gordeev
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2025-09-08 15:32 UTC (permalink / raw)
  To: Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, Thorsten Blum
  Cc: linux-s390, linux-kernel

Don't negate the 'mci.*' operands and use the logical AND operator to
simplify the return statement.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/s390/kernel/nmi.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index 11f33243a23f..cbefd6bde104 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -321,9 +321,7 @@ static bool notrace nmi_registers_valid(union mci mci)
 	cr2.reg = get_lowcore()->cregs_save_area[2];
 	if (cr2.gse && !mci.gs && !test_cpu_flag(CIF_MCCK_GUEST))
 		return false;
-	if (!mci.ms || !mci.pm || !mci.ia)
-		return false;
-	return true;
+	return mci.ms && mci.pm && mci.ia;
 }
 NOKPROBE_SYMBOL(nmi_registers_valid);
 
-- 
2.51.0


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

* Re: [PATCH] s390/nmi: Simplify return statement in nmi_registers_valid()
  2025-09-08 15:32 [PATCH] s390/nmi: Simplify return statement in nmi_registers_valid() Thorsten Blum
@ 2025-09-08 16:52 ` Alexander Gordeev
  2025-09-09  6:25   ` Heiko Carstens
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Gordeev @ 2025-09-08 16:52 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Sven Schnelle, linux-s390, linux-kernel

On Mon, Sep 08, 2025 at 05:32:20PM +0200, Thorsten Blum wrote:
...
> @@ -321,9 +321,7 @@ static bool notrace nmi_registers_valid(union mci mci)
>  	cr2.reg = get_lowcore()->cregs_save_area[2];
>  	if (cr2.gse && !mci.gs && !test_cpu_flag(CIF_MCCK_GUEST))
>  		return false;
> -	if (!mci.ms || !mci.pm || !mci.ia)
> -		return false;
> -	return true;
> +	return mci.ms && mci.pm && mci.ia;
>  }
>  NOKPROBE_SYMBOL(nmi_registers_valid);

This change does not make the whole function readability better.

Thanks!

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

* Re: [PATCH] s390/nmi: Simplify return statement in nmi_registers_valid()
  2025-09-08 16:52 ` Alexander Gordeev
@ 2025-09-09  6:25   ` Heiko Carstens
  2025-09-09  8:08     ` Thorsten Blum
  0 siblings, 1 reply; 4+ messages in thread
From: Heiko Carstens @ 2025-09-09  6:25 UTC (permalink / raw)
  To: Alexander Gordeev
  Cc: Thorsten Blum, Vasily Gorbik, Christian Borntraeger,
	Sven Schnelle, linux-s390, linux-kernel

On Mon, Sep 08, 2025 at 06:52:11PM +0200, Alexander Gordeev wrote:
> On Mon, Sep 08, 2025 at 05:32:20PM +0200, Thorsten Blum wrote:
> ...
> > @@ -321,9 +321,7 @@ static bool notrace nmi_registers_valid(union mci mci)
> >  	cr2.reg = get_lowcore()->cregs_save_area[2];
> >  	if (cr2.gse && !mci.gs && !test_cpu_flag(CIF_MCCK_GUEST))
> >  		return false;
> > -	if (!mci.ms || !mci.pm || !mci.ia)
> > -		return false;
> > -	return true;
> > +	return mci.ms && mci.pm && mci.ia;
> >  }
> >  NOKPROBE_SYMBOL(nmi_registers_valid);
> 
> This change does not make the whole function readability better.

It actually would decrease readability since every if-statement tells
you one condition when registers are not valid. Negating the last one
makes this harder to understand.

But in general please do not send patches like this, which do not come
with a significant improvement.

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

* Re: [PATCH] s390/nmi: Simplify return statement in nmi_registers_valid()
  2025-09-09  6:25   ` Heiko Carstens
@ 2025-09-09  8:08     ` Thorsten Blum
  0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-09-09  8:08 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Alexander Gordeev, Vasily Gorbik, Christian Borntraeger,
	Sven Schnelle, linux-s390, linux-kernel

On 9. Sep 2025, at 08:25, Heiko Carstens wrote:
> On Mon, Sep 08, 2025 at 06:52:11PM +0200, Alexander Gordeev wrote:
>> 
>> This change does not make the whole function readability better.
> 
> It actually would decrease readability since every if-statement tells
> you one condition when registers are not valid. Negating the last one
> makes this harder to understand.

Ah my bad, that makes sense. I didn't take the whole function into
account.

Thanks,
Thorsten


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

end of thread, other threads:[~2025-09-09  8:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-08 15:32 [PATCH] s390/nmi: Simplify return statement in nmi_registers_valid() Thorsten Blum
2025-09-08 16:52 ` Alexander Gordeev
2025-09-09  6:25   ` Heiko Carstens
2025-09-09  8:08     ` Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox