Skip to content

Commit d9b9647

Browse files
Michal SwiatkowskiNipaLocal
authored andcommitted
devlink: fix xa_alloc_cyclic error handling
Pierre Riteau <[email protected]> found suspicious handling an error from xa_alloc_cyclic() in scheduler code [1]. The same is done in devlink_rel_alloc(). In case of returning 1 from xa_alloc_cyclic() (wrapping) ERR_PTR(1) will be returned, which will cause IS_ERR() to be false. Which can lead to dereference not allocated pointer (rel). Fix it by checking if err is lower than zero. This wasn't found in real usecase, only noticed. Credit to Pierre. Signed-off-by: Michal Swiatkowski <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent d1cf428 commit d9b9647

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/devlink/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static struct devlink_rel *devlink_rel_alloc(void)
117117

118118
err = xa_alloc_cyclic(&devlink_rels, &rel->index, rel,
119119
xa_limit_32b, &next, GFP_KERNEL);
120-
if (err) {
120+
if (err < 0) {
121121
kfree(rel);
122122
return ERR_PTR(err);
123123
}

0 commit comments

Comments
 (0)