Skip to content

Commit

Permalink
regulator: fix use after free issue
Browse files Browse the repository at this point in the history
This is caused by dereferencing 'rdev' after put_device() in
the _regulator_get()/_regulator_put() functions.
This patch just moves the put_device() down a bit to avoid the
issue.

Signed-off-by: Wen Yang <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
taskset authored and broonie committed Nov 27, 2019
1 parent c15d5a6 commit 4affd79
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1937,8 +1937,8 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
regulator = create_regulator(rdev, dev, id);
if (regulator == NULL) {
regulator = ERR_PTR(-ENOMEM);
put_device(&rdev->dev);
module_put(rdev->owner);
put_device(&rdev->dev);
return regulator;
}

Expand Down Expand Up @@ -2059,13 +2059,13 @@ static void _regulator_put(struct regulator *regulator)

rdev->open_count--;
rdev->exclusive = 0;
put_device(&rdev->dev);
regulator_unlock(rdev);

kfree_const(regulator->supply_name);
kfree(regulator);

module_put(rdev->owner);
put_device(&rdev->dev);
}

/**
Expand Down

0 comments on commit 4affd79

Please sign in to comment.