regulator: core: Fix error return for /sys access
regulator_uV_show() is missing error handling if regulator_get_voltage_rdev() returns negative values. Instead it prints the errno as a string, e.g. -EINVAL as "-22" which could be interpreted as -22 µV. We also do not need to hold the lock while converting the integer to a string. Reported-by: Adam Ford <aford173@gmail.com> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com> Tested-by: Adam Ford <aford173@gmail.com> Link: https://lore.kernel.org/r/f37f2a1276efcb34cf3b7f1a25481175be048806.1568143348.git.hns@goldelico.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:

committed by
Mark Brown

parent
5eda8e95b7
commit
c82f27df07
@@ -568,13 +568,15 @@ static ssize_t regulator_uV_show(struct device *dev,
|
|||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct regulator_dev *rdev = dev_get_drvdata(dev);
|
struct regulator_dev *rdev = dev_get_drvdata(dev);
|
||||||
ssize_t ret;
|
int uV;
|
||||||
|
|
||||||
regulator_lock(rdev);
|
regulator_lock(rdev);
|
||||||
ret = sprintf(buf, "%d\n", regulator_get_voltage_rdev(rdev));
|
uV = regulator_get_voltage_rdev(rdev);
|
||||||
regulator_unlock(rdev);
|
regulator_unlock(rdev);
|
||||||
|
|
||||||
return ret;
|
if (uV < 0)
|
||||||
|
return uV;
|
||||||
|
return sprintf(buf, "%d\n", uV);
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
|
static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user