History

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.

Matthew Wilcox committed 7 years ago

Commit f818b821 parent 2fa044e2 files · +17 −16Browse files

Unified · Split

2 files
  1. include/linux/xarray.h +12 −11
  2. lib/test_xarray.c +5 −5
include/linux/xarray.h+12−11
@@ -497,12 +497,13 @@ void *__xa_erase(struct xarray *, unsigned long index); · 496 unmodified lines
497497 void *__xa_store(struct xarray *, unsigned long index, void *entry, gfp_t);
498498 void *__xa_cmpxchg(struct xarray *, unsigned long index, void *old,
499499 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);
501502 int __must_check __xa_alloc(struct xarray *, u32 *id, void *entry,
502503 struct xa_limit, gfp_t);
503504 int __must_check __xa_alloc_cyclic(struct xarray *, u32 *id, void *entry,
504505 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);
506507 void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t);
507508 void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t);
508509
@@ -704,8 +705,8 @@ static inline void *xa_cmpxchg_irq(struct xarray *xa, unsigned long index, · 195 unmodified lines
704705 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
705706 * -ENOMEM if memory could not be allocated.
706707 */
707−static inline int xa_insert(struct xarray *xa, unsigned long index,
708− void *entry, gfp_t gfp)
708+static inline int __must_check xa_insert(struct xarray *xa,
709+ unsigned long index, void *entry, gfp_t gfp)
709710 {
710711 int err;
711712
@@ -733,8 +734,8 @@ static inline int xa_insert(struct xarray *xa, unsigned long index, · 21 unmodified lines
733734 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
734735 * -ENOMEM if memory could not be allocated.
735736 */
736−static inline int xa_insert_bh(struct xarray *xa, unsigned long index,
737− void *entry, gfp_t gfp)
737+static inline int __must_check xa_insert_bh(struct xarray *xa,
738+ unsigned long index, void *entry, gfp_t gfp)
738739 {
739740 int err;
740741
@@ -762,8 +763,8 @@ static inline int xa_insert_bh(struct xarray *xa, unsigned long index, · 21 unmodified lines
762763 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
763764 * -ENOMEM if memory could not be allocated.
764765 */
765−static inline int xa_insert_irq(struct xarray *xa, unsigned long index,
766− void *entry, gfp_t gfp)
766+static inline int __must_check xa_insert_irq(struct xarray *xa,
767+ unsigned long index, void *entry, gfp_t gfp)
767768 {
768769 int err;
769770
@@ -978,7 +979,7 @@ static inline int xa_alloc_cyclic_irq(struct xarray *xa, u32 *id, void *entry, · 208 unmodified lines
978979 * May sleep if the @gfp flags permit.
979980 * Return: 0 if the reservation succeeded or -ENOMEM if it failed.
980981 */
981−static inline
982+static inline __must_check
982983 int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp)
983984 {
984985 int ret;
@@ -1002,7 +1003,7 @@ int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) · 17 unmodified lines
10021003 * disabling softirqs.
10031004 * Return: 0 if the reservation succeeded or -ENOMEM if it failed.
10041005 */
1005−static inline
1006+static inline __must_check
10061007 int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp)
10071008 {
10081009 int ret;
@@ -1026,7 +1027,7 @@ int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp) · 17 unmodified lines
10261027 * disabling interrupts.
10271028 * Return: 0 if the reservation succeeded or -ENOMEM if it failed.
10281029 */
1029−static inline
1030+static inline __must_check
10301031 int xa_reserve_irq(struct xarray *xa, unsigned long index, gfp_t gfp)
10311032 {
10321033 int ret;
lib/test_xarray.c+5−5
@@ -364,21 +364,21 @@ static noinline void check_reserve(struct xarray *xa) · 363 unmodified lines
364364
365365 /* An array with a reserved entry is not empty */
366366 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);
368368 XA_BUG_ON(xa, xa_empty(xa));
369369 XA_BUG_ON(xa, xa_load(xa, 12345678));
370370 xa_release(xa, 12345678);
371371 XA_BUG_ON(xa, !xa_empty(xa));
372372
373373 /* 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);
375375 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL);
376376 xa_release(xa, 12345678);
377377 xa_erase_index(xa, 12345678);
378378 XA_BUG_ON(xa, !xa_empty(xa));
379379
380380 /* 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);
382382 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, NULL, xa_mk_value(12345678),
383383 GFP_NOWAIT) != NULL);
384384 xa_release(xa, 12345678);
@@ -386,7 +386,7 @@ static noinline void check_reserve(struct xarray *xa) · 1 unmodified line
386386 XA_BUG_ON(xa, !xa_empty(xa));
387387
388388 /* But xa_insert does not */
389− xa_reserve(xa, 12345678, GFP_KERNEL);
389+ XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
390390 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) !=
391391 -EBUSY);
392392 XA_BUG_ON(xa, xa_empty(xa));
@@ -395,7 +395,7 @@ static noinline void check_reserve(struct xarray *xa) · 2 unmodified lines
395395
396396 /* Can iterate through a reserved entry */
397397 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);
399399 xa_store_index(xa, 7, GFP_KERNEL);
400400
401401 xa_for_each(xa, index, entry) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t