diff options
author | Matthew Wilcox <willy@infradead.org> | 2019-02-08 14:02:45 -0500 |
---|---|---|
committer | Matthew Wilcox <willy@infradead.org> | 2019-02-09 00:00:49 -0500 |
commit | f818b82b80164014d7ee3df89bb110808778c796 (patch) | |
tree | 36ee086ab1bd913f9a0519b1a4b8c08b7176b875 | |
parent | 2fa044e51a1f35d7b04cbde07ec513b0ba195e38 (diff) |
XArray: Mark xa_insert and xa_reserve as must_check
If the user doesn't care about the return value from xa_insert(), then
they should be using xa_store() instead. The point of xa_reserve() is
to get the return value early before taking another lock, so this should
also be __must_check.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
-rw-r--r-- | include/linux/xarray.h | 23 | ||||
-rw-r--r-- | lib/test_xarray.c | 10 |
2 files changed, 17 insertions, 16 deletions
diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 5ed6b462e754..687c150071a5 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h | |||
@@ -497,12 +497,13 @@ void *__xa_erase(struct xarray *, unsigned long index); | |||
497 | void *__xa_store(struct xarray *, unsigned long index, void *entry, gfp_t); | 497 | void *__xa_store(struct xarray *, unsigned long index, void *entry, gfp_t); |
498 | void *__xa_cmpxchg(struct xarray *, unsigned long index, void *old, | 498 | void *__xa_cmpxchg(struct xarray *, unsigned long index, void *old, |
499 | void *entry, gfp_t); | 499 | void *entry, gfp_t); |
500 | int __xa_insert(struct xarray *, unsigned long index, void *entry, gfp_t); | 500 | int __must_check __xa_insert(struct xarray *, unsigned long index, |
501 | void *entry, gfp_t); | ||
501 | int __must_check __xa_alloc(struct xarray *, u32 *id, void *entry, | 502 | int __must_check __xa_alloc(struct xarray *, u32 *id, void *entry, |
502 | struct xa_limit, gfp_t); | 503 | struct xa_limit, gfp_t); |
503 | int __must_check __xa_alloc_cyclic(struct xarray *, u32 *id, void *entry, | 504 | int __must_check __xa_alloc_cyclic(struct xarray *, u32 *id, void *entry, |
504 | struct xa_limit, u32 *next, gfp_t); | 505 | struct xa_limit, u32 *next, gfp_t); |
505 | int __xa_reserve(struct xarray *, unsigned long index, gfp_t); | 506 | int __must_check __xa_reserve(struct xarray *, unsigned long index, gfp_t); |
506 | void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t); | 507 | void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t); |
507 | void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t); | 508 | void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t); |
508 | 509 | ||
@@ -704,8 +705,8 @@ static inline void *xa_cmpxchg_irq(struct xarray *xa, unsigned long index, | |||
704 | * Return: 0 if the store succeeded. -EBUSY if another entry was present. | 705 | * Return: 0 if the store succeeded. -EBUSY if another entry was present. |
705 | * -ENOMEM if memory could not be allocated. | 706 | * -ENOMEM if memory could not be allocated. |
706 | */ | 707 | */ |
707 | static inline int xa_insert(struct xarray *xa, unsigned long index, | 708 | static inline int __must_check xa_insert(struct xarray *xa, |
708 | void *entry, gfp_t gfp) | 709 | unsigned long index, void *entry, gfp_t gfp) |
709 | { | 710 | { |
710 | int err; | 711 | int err; |
711 | 712 | ||
@@ -733,8 +734,8 @@ static inline int xa_insert(struct xarray *xa, unsigned long index, | |||
733 | * Return: 0 if the store succeeded. -EBUSY if another entry was present. | 734 | * Return: 0 if the store succeeded. -EBUSY if another entry was present. |
734 | * -ENOMEM if memory could not be allocated. | 735 | * -ENOMEM if memory could not be allocated. |
735 | */ | 736 | */ |
736 | static inline int xa_insert_bh(struct xarray *xa, unsigned long index, | 737 | static inline int __must_check xa_insert_bh(struct xarray *xa, |
737 | void *entry, gfp_t gfp) | 738 | unsigned long index, void *entry, gfp_t gfp) |
738 | { | 739 | { |
739 | int err; | 740 | int err; |
740 | 741 | ||
@@ -762,8 +763,8 @@ static inline int xa_insert_bh(struct xarray *xa, unsigned long index, | |||
762 | * Return: 0 if the store succeeded. -EBUSY if another entry was present. | 763 | * Return: 0 if the store succeeded. -EBUSY if another entry was present. |
763 | * -ENOMEM if memory could not be allocated. | 764 | * -ENOMEM if memory could not be allocated. |
764 | */ | 765 | */ |
765 | static inline int xa_insert_irq(struct xarray *xa, unsigned long index, | 766 | static inline int __must_check xa_insert_irq(struct xarray *xa, |
766 | void *entry, gfp_t gfp) | 767 | unsigned long index, void *entry, gfp_t gfp) |
767 | { | 768 | { |
768 | int err; | 769 | int err; |
769 | 770 | ||
@@ -978,7 +979,7 @@ static inline int xa_alloc_cyclic_irq(struct xarray *xa, u32 *id, void *entry, | |||
978 | * May sleep if the @gfp flags permit. | 979 | * May sleep if the @gfp flags permit. |
979 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | 980 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. |
980 | */ | 981 | */ |
981 | static inline | 982 | static inline __must_check |
982 | int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) | 983 | int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) |
983 | { | 984 | { |
984 | int ret; | 985 | int ret; |
@@ -1002,7 +1003,7 @@ int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) | |||
1002 | * disabling softirqs. | 1003 | * disabling softirqs. |
1003 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | 1004 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. |
1004 | */ | 1005 | */ |
1005 | static inline | 1006 | static inline __must_check |
1006 | int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp) | 1007 | int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp) |
1007 | { | 1008 | { |
1008 | int ret; | 1009 | int ret; |
@@ -1026,7 +1027,7 @@ int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp) | |||
1026 | * disabling interrupts. | 1027 | * disabling interrupts. |
1027 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | 1028 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. |
1028 | */ | 1029 | */ |
1029 | static inline | 1030 | static inline __must_check |
1030 | int xa_reserve_irq(struct xarray *xa, unsigned long index, gfp_t gfp) | 1031 | int xa_reserve_irq(struct xarray *xa, unsigned long index, gfp_t gfp) |
1031 | { | 1032 | { |
1032 | int ret; | 1033 | int ret; |
diff --git a/lib/test_xarray.c b/lib/test_xarray.c index eaf53f742c72..3eaa40ddc390 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c | |||
@@ -364,21 +364,21 @@ static noinline void check_reserve(struct xarray *xa) | |||
364 | 364 | ||
365 | /* An array with a reserved entry is not empty */ | 365 | /* An array with a reserved entry is not empty */ |
366 | XA_BUG_ON(xa, !xa_empty(xa)); | 366 | XA_BUG_ON(xa, !xa_empty(xa)); |
367 | xa_reserve(xa, 12345678, GFP_KERNEL); | 367 | XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); |
368 | XA_BUG_ON(xa, xa_empty(xa)); | 368 | XA_BUG_ON(xa, xa_empty(xa)); |
369 | XA_BUG_ON(xa, xa_load(xa, 12345678)); | 369 | XA_BUG_ON(xa, xa_load(xa, 12345678)); |
370 | xa_release(xa, 12345678); | 370 | xa_release(xa, 12345678); |
371 | XA_BUG_ON(xa, !xa_empty(xa)); | 371 | XA_BUG_ON(xa, !xa_empty(xa)); |
372 | 372 | ||
373 | /* Releasing a used entry does nothing */ | 373 | /* Releasing a used entry does nothing */ |
374 | xa_reserve(xa, 12345678, GFP_KERNEL); | 374 | XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); |
375 | XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL); | 375 | XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL); |
376 | xa_release(xa, 12345678); | 376 | xa_release(xa, 12345678); |
377 | xa_erase_index(xa, 12345678); | 377 | xa_erase_index(xa, 12345678); |
378 | XA_BUG_ON(xa, !xa_empty(xa)); | 378 | XA_BUG_ON(xa, !xa_empty(xa)); |
379 | 379 | ||
380 | /* cmpxchg sees a reserved entry as NULL */ | 380 | /* cmpxchg sees a reserved entry as NULL */ |
381 | xa_reserve(xa, 12345678, GFP_KERNEL); | 381 | XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); |
382 | XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, NULL, xa_mk_value(12345678), | 382 | XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, NULL, xa_mk_value(12345678), |
383 | GFP_NOWAIT) != NULL); | 383 | GFP_NOWAIT) != NULL); |
384 | xa_release(xa, 12345678); | 384 | xa_release(xa, 12345678); |
@@ -386,7 +386,7 @@ static noinline void check_reserve(struct xarray *xa) | |||
386 | XA_BUG_ON(xa, !xa_empty(xa)); | 386 | XA_BUG_ON(xa, !xa_empty(xa)); |
387 | 387 | ||
388 | /* But xa_insert does not */ | 388 | /* But xa_insert does not */ |
389 | xa_reserve(xa, 12345678, GFP_KERNEL); | 389 | XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); |
390 | XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != | 390 | XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != |
391 | -EBUSY); | 391 | -EBUSY); |
392 | XA_BUG_ON(xa, xa_empty(xa)); | 392 | XA_BUG_ON(xa, xa_empty(xa)); |
@@ -395,7 +395,7 @@ static noinline void check_reserve(struct xarray *xa) | |||
395 | 395 | ||
396 | /* Can iterate through a reserved entry */ | 396 | /* Can iterate through a reserved entry */ |
397 | xa_store_index(xa, 5, GFP_KERNEL); | 397 | xa_store_index(xa, 5, GFP_KERNEL); |
398 | xa_reserve(xa, 6, GFP_KERNEL); | 398 | XA_BUG_ON(xa, xa_reserve(xa, 6, GFP_KERNEL) != 0); |
399 | xa_store_index(xa, 7, GFP_KERNEL); | 399 | xa_store_index(xa, 7, GFP_KERNEL); |
400 | 400 | ||
401 | xa_for_each(xa, index, entry) { | 401 | xa_for_each(xa, index, entry) { |