Skip to content

Commit 1812742

Browse files
author
Miklos Szeredi
committed
bitops: protect variables in set_mask_bits() macro
Unprotected naming of local variables within the set_mask_bits() can easily lead to using the wrong scope. Noticed this when "set_mask_bits(&foo->bar, 0, mask)" behaved as no-op. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: 00a1a05 ("ext4: atomically set inode->i_flags in ext4_set_inode_flags()") Cc: Theodore Ts'o <tytso@mit.edu>
1 parent e52a825 commit 1812742

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

include/linux/bitops.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,17 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr,
236236
#ifdef __KERNEL__
237237

238238
#ifndef set_mask_bits
239-
#define set_mask_bits(ptr, _mask, _bits) \
239+
#define set_mask_bits(ptr, mask, bits) \
240240
({ \
241-
const typeof(*ptr) mask = (_mask), bits = (_bits); \
242-
typeof(*ptr) old, new; \
241+
const typeof(*(ptr)) mask__ = (mask), bits__ = (bits); \
242+
typeof(*(ptr)) old__, new__; \
243243
\
244244
do { \
245-
old = READ_ONCE(*ptr); \
246-
new = (old & ~mask) | bits; \
247-
} while (cmpxchg(ptr, old, new) != old); \
245+
old__ = READ_ONCE(*(ptr)); \
246+
new__ = (old__ & ~mask__) | bits__; \
247+
} while (cmpxchg(ptr, old__, new__) != old__); \
248248
\
249-
new; \
249+
new__; \
250250
})
251251
#endif
252252

0 commit comments

Comments
 (0)