Skip to content

Commit f3b97b7

Browse files
Michal Swiatkowskidavem330
authored andcommitted
devlink: fix xa_alloc_cyclic() error handling
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. Fixes: c137743 ("devlink: introduce object and nested devlink relationship infra") Signed-off-by: Michal Swiatkowski <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9a81fc3 commit f3b97b7

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)