Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 85ad1d13ee9b ("md: set MD_CHANGE_PENDING in a atomic region")
Cc: Guoqing Jiang <gqjiang@suse.com>

+8 -8
+8 -8
include/linux/bitops.h
··· 251 251 #endif 252 252 253 253 #ifndef bit_clear_unless 254 - #define bit_clear_unless(ptr, _clear, _test) \ 254 + #define bit_clear_unless(ptr, clear, test) \ 255 255 ({ \ 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__; \ 258 258 \ 259 259 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__); \ 264 264 \ 265 - !(old & test); \ 265 + !(old__ & test__); \ 266 266 }) 267 267 #endif 268 268