Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

H. Nikolaus Schaller and committed by
Mark Brown
c82f27df 5eda8e95

+5 -3
+5 -3
drivers/regulator/core.c
··· 568 568 struct device_attribute *attr, char *buf) 569 569 { 570 570 struct regulator_dev *rdev = dev_get_drvdata(dev); 571 - ssize_t ret; 571 + int uV; 572 572 573 573 regulator_lock(rdev); 574 - ret = sprintf(buf, "%d\n", regulator_get_voltage_rdev(rdev)); 574 + uV = regulator_get_voltage_rdev(rdev); 575 575 regulator_unlock(rdev); 576 576 577 - return ret; 577 + if (uV < 0) 578 + return uV; 579 + return sprintf(buf, "%d\n", uV); 578 580 } 579 581 static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL); 580 582