mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-04-13 09:59:31 +00:00
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: c137743bce
("devlink: introduce object and nested devlink relationship infra")
Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
9a81fc3480
commit
f3b97b7d4b
1 changed files with 1 additions and 1 deletions
|
@ -117,7 +117,7 @@ static struct devlink_rel *devlink_rel_alloc(void)
|
|||
|
||||
err = xa_alloc_cyclic(&devlink_rels, &rel->index, rel,
|
||||
xa_limit_32b, &next, GFP_KERNEL);
|
||||
if (err) {
|
||||
if (err < 0) {
|
||||
kfree(rel);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue