[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHCN7xJbeYnNLbKOWFXrBLovjFNdtweuOu-arbQF1-=8JNojFg@mail.gmail.com>
Date: Tue, 10 Sep 2019 14:56:22 -0500
From: Adam Ford <aford173@...il.com>
To: "H. Nikolaus Schaller" <hns@...delico.com>
Cc: Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Discussions about the Letux Kernel
<letux-kernel@...nphoenux.org>, kernel@...a-handheld.com
Subject: Re: [PATCH] regulator: core: Fix error return for /sys access
On Tue, Sep 10, 2019 at 2:22 PM H. Nikolaus Schaller <hns@...delico.com> wrote:
>
> 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@...il.com>
> Signed-off-by: H. Nikolaus Schaller <hns@...delico.com>
Tested-by: Adam Ford <aford173@...il.com>
> ---
> drivers/regulator/core.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index e0c0cf462004..ea48cb5a68b8 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -564,13 +564,15 @@ static ssize_t regulator_uV_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> struct regulator_dev *rdev = dev_get_drvdata(dev);
> - ssize_t ret;
> + int uV;
>
> regulator_lock(rdev);
> - ret = sprintf(buf, "%d\n", regulator_get_voltage_rdev(rdev));
> + uV = regulator_get_voltage_rdev(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);
>
> --
> 2.19.1
>
Powered by blists - more mailing lists