[PATCH v2] hwmon: (ina2xx) make regulator 'vs' support optional

Ciprian Costea posted 1 patch 10 months ago
drivers/hwmon/ina2xx.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
[PATCH v2] hwmon: (ina2xx) make regulator 'vs' support optional
Posted by Ciprian Costea 10 months ago
From: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>

According to the 'ti,ina2xx' binding, the 'vs-supply' property is
optional. Use devm_regulator_get_enable_optional() to avoid a kernel
warning message if the property is not provided.

Co-developed-by: Florin Buica <florin.buica@nxp.com>
Signed-off-by: Florin Buica <florin.buica@nxp.com>
Signed-off-by: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
---
 drivers/hwmon/ina2xx.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 345fe7db9de9..b79e9c2072b3 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -959,8 +959,11 @@ static int ina2xx_probe(struct i2c_client *client)
 		return PTR_ERR(data->regmap);
 	}
 
-	ret = devm_regulator_get_enable(dev, "vs");
-	if (ret)
+	/* Regulator core returns -ENODEV if the 'vs' is not available.
+	 * Hence the check for -ENODEV return code is necessary.
+	 */
+	ret = devm_regulator_get_enable_optional(dev, "vs");
+	if (ret < 0 && ret != -ENODEV)
 		return dev_err_probe(dev, ret, "failed to enable vs regulator\n");
 
 	ret = ina2xx_init(dev, data);
-- 
2.45.2
Re: [PATCH v2] hwmon: (ina2xx) make regulator 'vs' support optional
Posted by Guenter Roeck 10 months ago
On Wed, Apr 09, 2025 at 10:45:29AM +0300, Ciprian Costea wrote:
> From: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
> 
> According to the 'ti,ina2xx' binding, the 'vs-supply' property is
> optional. Use devm_regulator_get_enable_optional() to avoid a kernel
> warning message if the property is not provided.
> 
> Co-developed-by: Florin Buica <florin.buica@nxp.com>
> Signed-off-by: Florin Buica <florin.buica@nxp.com>
> Signed-off-by: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>

Applied, after converting multi-line comment to standard form.

Guenter

> ---
>  drivers/hwmon/ina2xx.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> index 345fe7db9de9..b79e9c2072b3 100644
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
> @@ -959,8 +959,11 @@ static int ina2xx_probe(struct i2c_client *client)
>  		return PTR_ERR(data->regmap);
>  	}
>  
> -	ret = devm_regulator_get_enable(dev, "vs");
> -	if (ret)
> +	/* Regulator core returns -ENODEV if the 'vs' is not available.
> +	 * Hence the check for -ENODEV return code is necessary.
> +	 */
> +	ret = devm_regulator_get_enable_optional(dev, "vs");
> +	if (ret < 0 && ret != -ENODEV)
>  		return dev_err_probe(dev, ret, "failed to enable vs regulator\n");
>  
>  	ret = ina2xx_init(dev, data);
Re: [PATCH v2] hwmon: (ina2xx) make regulator 'vs' support optional
Posted by Enric Balletbo i Serra 10 months ago
Hi Ciprian,

Many thanks for your patch.

On Wed, Apr 9, 2025 at 9:45 AM Ciprian Costea
<ciprianmarian.costea@oss.nxp.com> wrote:
>
> From: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
>
> According to the 'ti,ina2xx' binding, the 'vs-supply' property is
> optional. Use devm_regulator_get_enable_optional() to avoid a kernel
> warning message if the property is not provided.
>
> Co-developed-by: Florin Buica <florin.buica@nxp.com>
> Signed-off-by: Florin Buica <florin.buica@nxp.com>
> Signed-off-by: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>

I verified that using the following patch gets rid of the kernel
warning about using the dummy regulator, and that the driver continue
working as expected.

[    7.247679] ina2xx 2-0040: power monitor ina231 (Rshunt = 1000 uOhm)

So,

Tested-by: Enric Balletbo i Serra <eballetbo@kernel.org>

Thanks,
  Enric


> ---
>  drivers/hwmon/ina2xx.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> index 345fe7db9de9..b79e9c2072b3 100644
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
> @@ -959,8 +959,11 @@ static int ina2xx_probe(struct i2c_client *client)
>                 return PTR_ERR(data->regmap);
>         }
>
> -       ret = devm_regulator_get_enable(dev, "vs");
> -       if (ret)
> +       /* Regulator core returns -ENODEV if the 'vs' is not available.
> +        * Hence the check for -ENODEV return code is necessary.
> +        */
> +       ret = devm_regulator_get_enable_optional(dev, "vs");
> +       if (ret < 0 && ret != -ENODEV)
>                 return dev_err_probe(dev, ret, "failed to enable vs regulator\n");
>
>         ret = ina2xx_init(dev, data);
> --
> 2.45.2
>