|
4 | 4 |
|
5 | 5 | #include <asm/types.h> |
6 | 6 | #include <linux/bits.h> |
| 7 | +#include <linux/typecheck.h> |
7 | 8 |
|
8 | 9 | #include <uapi/linux/kernel.h> |
9 | 10 |
|
@@ -253,6 +254,55 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr, |
253 | 254 | __clear_bit(nr, addr); |
254 | 255 | } |
255 | 256 |
|
| 257 | +/** |
| 258 | + * __ptr_set_bit - Set bit in a pointer's value |
| 259 | + * @nr: the bit to set |
| 260 | + * @addr: the address of the pointer variable |
| 261 | + * |
| 262 | + * Example: |
| 263 | + * void *p = foo(); |
| 264 | + * __ptr_set_bit(bit, &p); |
| 265 | + */ |
| 266 | +#define __ptr_set_bit(nr, addr) \ |
| 267 | + ({ \ |
| 268 | + typecheck_pointer(*(addr)); \ |
| 269 | + __set_bit(nr, (unsigned long *)(addr)); \ |
| 270 | + }) |
| 271 | + |
| 272 | +/** |
| 273 | + * __ptr_clear_bit - Clear bit in a pointer's value |
| 274 | + * @nr: the bit to clear |
| 275 | + * @addr: the address of the pointer variable |
| 276 | + * |
| 277 | + * Example: |
| 278 | + * void *p = foo(); |
| 279 | + * __ptr_clear_bit(bit, &p); |
| 280 | + */ |
| 281 | +#define __ptr_clear_bit(nr, addr) \ |
| 282 | + ({ \ |
| 283 | + typecheck_pointer(*(addr)); \ |
| 284 | + __clear_bit(nr, (unsigned long *)(addr)); \ |
| 285 | + }) |
| 286 | + |
| 287 | +/** |
| 288 | + * __ptr_test_bit - Test bit in a pointer's value |
| 289 | + * @nr: the bit to test |
| 290 | + * @addr: the address of the pointer variable |
| 291 | + * |
| 292 | + * Example: |
| 293 | + * void *p = foo(); |
| 294 | + * if (__ptr_test_bit(bit, &p)) { |
| 295 | + * ... |
| 296 | + * } else { |
| 297 | + * ... |
| 298 | + * } |
| 299 | + */ |
| 300 | +#define __ptr_test_bit(nr, addr) \ |
| 301 | + ({ \ |
| 302 | + typecheck_pointer(*(addr)); \ |
| 303 | + test_bit(nr, (unsigned long *)(addr)); \ |
| 304 | + }) |
| 305 | + |
256 | 306 | #ifdef __KERNEL__ |
257 | 307 |
|
258 | 308 | #ifndef set_mask_bits |
|
0 commit comments