Skip to content

Commit 0dfe540

Browse files
keesYuryNorov
authored andcommitted
nodemask: Fix return values to be unsigned
The nodemask routines had mixed return values that provided potentially signed return values that could never happen. This was leading to the compiler getting confusing about the range of possible return values (it was thinking things could be negative where they could not be). Fix all the nodemask routines that should be returning unsigned (or bool) values. Silences: mm/swapfile.c: In function ‘setup_swap_info’: mm/swapfile.c:2291:47: error: array subscript -1 is below array bounds of ‘struct plist_node[]’ [-Werror=array-bounds] 2291 | p->avail_lists[i].prio = 1; | ~~~~~~~~~~~~~~^~~ In file included from mm/swapfile.c:16: ./include/linux/swap.h:292:27: note: while referencing ‘avail_lists’ 292 | struct plist_node avail_lists[]; /* | ^~~~~~~~~~~ Reported-by: Christophe de Dinechin <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Cc: Alexey Dobriyan <[email protected]> Cc: Yury Norov <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Zhen Lei <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Yury Norov <[email protected]>
1 parent 005f170 commit 0dfe540

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

include/linux/nodemask.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
* void nodes_shift_right(dst, src, n) Shift right
4343
* void nodes_shift_left(dst, src, n) Shift left
4444
*
45-
* int first_node(mask) Number lowest set bit, or MAX_NUMNODES
46-
* int next_node(node, mask) Next node past 'node', or MAX_NUMNODES
47-
* int next_node_in(node, mask) Next node past 'node', or wrap to first,
45+
* unsigned int first_node(mask) Number lowest set bit, or MAX_NUMNODES
46+
* unsigend int next_node(node, mask) Next node past 'node', or MAX_NUMNODES
47+
* unsigned int next_node_in(node, mask) Next node past 'node', or wrap to first,
4848
* or MAX_NUMNODES
49-
* int first_unset_node(mask) First node not set in mask, or
49+
* unsigned int first_unset_node(mask) First node not set in mask, or
5050
* MAX_NUMNODES
5151
*
5252
* nodemask_t nodemask_of_node(node) Return nodemask with bit 'node' set
@@ -153,7 +153,7 @@ static inline void __nodes_clear(nodemask_t *dstp, unsigned int nbits)
153153

154154
#define node_test_and_set(node, nodemask) \
155155
__node_test_and_set((node), &(nodemask))
156-
static inline int __node_test_and_set(int node, nodemask_t *addr)
156+
static inline bool __node_test_and_set(int node, nodemask_t *addr)
157157
{
158158
return test_and_set_bit(node, addr->bits);
159159
}
@@ -200,36 +200,36 @@ static inline void __nodes_complement(nodemask_t *dstp,
200200

201201
#define nodes_equal(src1, src2) \
202202
__nodes_equal(&(src1), &(src2), MAX_NUMNODES)
203-
static inline int __nodes_equal(const nodemask_t *src1p,
203+
static inline bool __nodes_equal(const nodemask_t *src1p,
204204
const nodemask_t *src2p, unsigned int nbits)
205205
{
206206
return bitmap_equal(src1p->bits, src2p->bits, nbits);
207207
}
208208

209209
#define nodes_intersects(src1, src2) \
210210
__nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
211-
static inline int __nodes_intersects(const nodemask_t *src1p,
211+
static inline bool __nodes_intersects(const nodemask_t *src1p,
212212
const nodemask_t *src2p, unsigned int nbits)
213213
{
214214
return bitmap_intersects(src1p->bits, src2p->bits, nbits);
215215
}
216216

217217
#define nodes_subset(src1, src2) \
218218
__nodes_subset(&(src1), &(src2), MAX_NUMNODES)
219-
static inline int __nodes_subset(const nodemask_t *src1p,
219+
static inline bool __nodes_subset(const nodemask_t *src1p,
220220
const nodemask_t *src2p, unsigned int nbits)
221221
{
222222
return bitmap_subset(src1p->bits, src2p->bits, nbits);
223223
}
224224

225225
#define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
226-
static inline int __nodes_empty(const nodemask_t *srcp, unsigned int nbits)
226+
static inline bool __nodes_empty(const nodemask_t *srcp, unsigned int nbits)
227227
{
228228
return bitmap_empty(srcp->bits, nbits);
229229
}
230230

231231
#define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
232-
static inline int __nodes_full(const nodemask_t *srcp, unsigned int nbits)
232+
static inline bool __nodes_full(const nodemask_t *srcp, unsigned int nbits)
233233
{
234234
return bitmap_full(srcp->bits, nbits);
235235
}
@@ -260,23 +260,23 @@ static inline void __nodes_shift_left(nodemask_t *dstp,
260260
> MAX_NUMNODES, then the silly min_ts could be dropped. */
261261

262262
#define first_node(src) __first_node(&(src))
263-
static inline int __first_node(const nodemask_t *srcp)
263+
static inline unsigned int __first_node(const nodemask_t *srcp)
264264
{
265-
return min_t(int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
265+
return min_t(unsigned int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
266266
}
267267

268268
#define next_node(n, src) __next_node((n), &(src))
269-
static inline int __next_node(int n, const nodemask_t *srcp)
269+
static inline unsigned int __next_node(int n, const nodemask_t *srcp)
270270
{
271-
return min_t(int,MAX_NUMNODES,find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
271+
return min_t(unsigned int, MAX_NUMNODES, find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
272272
}
273273

274274
/*
275275
* Find the next present node in src, starting after node n, wrapping around to
276276
* the first node in src if needed. Returns MAX_NUMNODES if src is empty.
277277
*/
278278
#define next_node_in(n, src) __next_node_in((n), &(src))
279-
int __next_node_in(int node, const nodemask_t *srcp);
279+
unsigned int __next_node_in(int node, const nodemask_t *srcp);
280280

281281
static inline void init_nodemask_of_node(nodemask_t *mask, int node)
282282
{
@@ -296,9 +296,9 @@ static inline void init_nodemask_of_node(nodemask_t *mask, int node)
296296
})
297297

298298
#define first_unset_node(mask) __first_unset_node(&(mask))
299-
static inline int __first_unset_node(const nodemask_t *maskp)
299+
static inline unsigned int __first_unset_node(const nodemask_t *maskp)
300300
{
301-
return min_t(int,MAX_NUMNODES,
301+
return min_t(unsigned int, MAX_NUMNODES,
302302
find_first_zero_bit(maskp->bits, MAX_NUMNODES));
303303
}
304304

@@ -436,11 +436,11 @@ static inline int num_node_state(enum node_states state)
436436

437437
#define first_online_node first_node(node_states[N_ONLINE])
438438
#define first_memory_node first_node(node_states[N_MEMORY])
439-
static inline int next_online_node(int nid)
439+
static inline unsigned int next_online_node(int nid)
440440
{
441441
return next_node(nid, node_states[N_ONLINE]);
442442
}
443-
static inline int next_memory_node(int nid)
443+
static inline unsigned int next_memory_node(int nid)
444444
{
445445
return next_node(nid, node_states[N_MEMORY]);
446446
}

lib/nodemask.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <linux/module.h>
44
#include <linux/random.h>
55

6-
int __next_node_in(int node, const nodemask_t *srcp)
6+
unsigned int __next_node_in(int node, const nodemask_t *srcp)
77
{
8-
int ret = __next_node(node, srcp);
8+
unsigned int ret = __next_node(node, srcp);
99

1010
if (ret == MAX_NUMNODES)
1111
ret = __first_node(srcp);

0 commit comments

Comments
 (0)