Re: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast

From: Peter Zijlstra
Date: Tue Jun 05 2018 - 10:43:15 EST


On Tue, Jun 05, 2018 at 04:20:51PM +0200, Greg Kroah-Hartman wrote:
> I think Peter Hurley was just trying to hid the atomic mess behind
> function calls, which is why he didn't open-code it like you did here.

No reason to then not use the right types though. I mean, you can still
use the helper functions, but I figured they weren't worth the bother.
Esp. then using try_cmpxchg (which is relatively new) the helpers became
very thin.

> But this makes it a bit more obvious as to what "magic" is happening, so
> I like it.

Well, it also fixes one additional bug in that the old code used a
regular unsigned long load of the value:

- long count = sem->count;
+ long count = atomic_long_read(&sem->count);

which doesn't guarantee enough. The atomic_long_read() thing implies
READ_ONCE() which ensures the load is single copy atomic (GCC used to
guarantee that for regular loads/stores to naturally aligned native
words, but no longer).

> Care to turn it into a real patch so I can queue it up after 4.18-rc1 is
> out? Or do you want me to do that?

I can make a proper patch, hold on.