Skip to content

Commit edfa872

Browse files
author
Miklos Szeredi
committed
bitops: protect variables in bit_clear_unless() macro
Unprotected naming of local variables within bit_clear_unless() can easily lead to using the wrong scope. Noticed this by code review after having hit this issue in set_mask_bits() Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: 85ad1d1 ("md: set MD_CHANGE_PENDING in a atomic region") Cc: Guoqing Jiang <gqjiang@suse.com>
1 parent 1812742 commit edfa872

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

include/linux/bitops.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,18 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr,
251251
#endif
252252

253253
#ifndef bit_clear_unless
254-
#define bit_clear_unless(ptr, _clear, _test) \
254+
#define bit_clear_unless(ptr, clear, test) \
255255
({ \
256-
const typeof(*ptr) clear = (_clear), test = (_test); \
257-
typeof(*ptr) old, new; \
256+
const typeof(*(ptr)) clear__ = (clear), test__ = (test);\
257+
typeof(*(ptr)) old__, new__; \
258258
\
259259
do { \
260-
old = READ_ONCE(*ptr); \
261-
new = old & ~clear; \
262-
} while (!(old & test) && \
263-
cmpxchg(ptr, old, new) != old); \
260+
old__ = READ_ONCE(*(ptr)); \
261+
new__ = old__ & ~clear__; \
262+
} while (!(old__ & test__) && \
263+
cmpxchg(ptr, old__, new__) != old__); \
264264
\
265-
!(old & test); \
265+
!(old__ & test__); \
266266
})
267267
#endif
268268

0 commit comments

Comments
 (0)