All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND] x86: Refactor __cmpxchg to cmpxchg in lock_cmos
@ 2019-01-05 15:29 Philipp K
  2019-09-24 17:47 ` Borislav Petkov
  0 siblings, 1 reply; 2+ messages in thread
From: Philipp K @ 2019-01-05 15:29 UTC (permalink / raw)
  Cc: Lukas Bulwahn, x86, Philipp Klocke, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, linux-kernel

It is unusual to reference __cmpxchg() from other files than cmpxchg.h and
similar.
Instead, cmpxchg() is used, which expands to __cmpxchg() and derives the
'size' parameter automatically with sizeof(*(ptr)).

So clean up the lock_cmos() function by using cmpxchg(), without changing
the generated code.

Signed-off-by: Philipp Klocke <philipp97kl@gmail.com>
---

This patch was acked by Ingo, so I would expect it to be added to pit.

 arch/x86/include/asm/mc146818rtc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/mc146818rtc.h
b/arch/x86/include/asm/mc146818rtc.h
index 97198001e567..b72e3bbba0a2 100644
--- a/arch/x86/include/asm/mc146818rtc.h
+++ b/arch/x86/include/asm/mc146818rtc.h
@@ -47,7 +47,7 @@ static inline void lock_cmos(unsigned char reg)
  cpu_relax();
  continue;
  }
- if (__cmpxchg(&cmos_lock, 0, new, sizeof(cmos_lock)) == 0)
+ if (cmpxchg(&cmos_lock, 0, new) == 0)
  return;
  }
 }
-- 
2.19.1

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

* Re: [RESEND] x86: Refactor __cmpxchg to cmpxchg in lock_cmos
  2019-01-05 15:29 [RESEND] x86: Refactor __cmpxchg to cmpxchg in lock_cmos Philipp K
@ 2019-09-24 17:47 ` Borislav Petkov
  0 siblings, 0 replies; 2+ messages in thread
From: Borislav Petkov @ 2019-09-24 17:47 UTC (permalink / raw)
  To: Philipp K
  Cc: Lukas Bulwahn, x86, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	linux-kernel

On Sat, Jan 05, 2019 at 04:29:13PM +0100, Philipp K wrote:
> It is unusual to reference __cmpxchg() from other files than cmpxchg.h and
> similar.
> Instead, cmpxchg() is used, which expands to __cmpxchg() and derives the
> 'size' parameter automatically with sizeof(*(ptr)).
> 
> So clean up the lock_cmos() function by using cmpxchg(), without changing
> the generated code.
> 
> Signed-off-by: Philipp Klocke <philipp97kl@gmail.com>
> ---
> 
> This patch was acked by Ingo, so I would expect it to be added to pit.

You mean tip. :)

>  arch/x86/include/asm/mc146818rtc.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/mc146818rtc.h
> b/arch/x86/include/asm/mc146818rtc.h
> index 97198001e567..b72e3bbba0a2 100644
> --- a/arch/x86/include/asm/mc146818rtc.h
> +++ b/arch/x86/include/asm/mc146818rtc.h
> @@ -47,7 +47,7 @@ static inline void lock_cmos(unsigned char reg)
>   cpu_relax();
>   continue;
>   }
> - if (__cmpxchg(&cmos_lock, 0, new, sizeof(cmos_lock)) == 0)
> + if (cmpxchg(&cmos_lock, 0, new) == 0)
>   return;
>   }
>  }
> -- 

I don't know how you created this diff but yours breaks the indentation.
It should look like this:

--
diff --git a/arch/x86/include/asm/mc146818rtc.h b/arch/x86/include/asm/mc146818rtc.h
index 97198001e567..b72e3bbba0a2 100644
--- a/arch/x86/include/asm/mc146818rtc.h
+++ b/arch/x86/include/asm/mc146818rtc.h
@@ -47,7 +47,7 @@ static inline void lock_cmos(unsigned char reg)
 			cpu_relax();
 			continue;
 		}
-		if (__cmpxchg(&cmos_lock, 0, new, sizeof(cmos_lock)) == 0)
+		if (cmpxchg(&cmos_lock, 0, new) == 0)
 			return;
 	}
 }
--

Also, you can simplify it even more by changing it to:

		if (!cmpxchg(&cmos_lock, 0, new))
			return;

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

end of thread, other threads:[~2019-09-24 17:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-05 15:29 [RESEND] x86: Refactor __cmpxchg to cmpxchg in lock_cmos Philipp K
2019-09-24 17:47 ` Borislav Petkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.