[PATCH] regulator: pca9450: use dev_err_probe on errors requesting resources

Ahmad Fatoum posted 1 patch 1 year ago
drivers/regulator/pca9450-regulator.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
[PATCH] regulator: pca9450: use dev_err_probe on errors requesting resources
Posted by Ahmad Fatoum 1 year ago
Probe functions requesting resources may return -EPROBE_DEFER to
the driver core to instruct it to retry probe at a later time.
This is not unusual and printing an error message unconditionally
is just confusing to users:

  nxp-pca9450 0-0025: Failed to register regulator(buck1): -517

Using dev_err_probe remedies this:

The error message will only be shown if the error code is not
-EPROBE_DEFER and if it is, the deferral reason is saved for display
at a later time.

Fixes: 0935ff5f1f0a ("regulator: pca9450: add pca9450 pmic driver")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/regulator/pca9450-regulator.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9450-regulator.c
index 9714afe347dcc0205b40243252638dff5f9298ad..8f5ba59f7fe52bee1e467a3e6adf81a6a5476221 100644
--- a/drivers/regulator/pca9450-regulator.c
+++ b/drivers/regulator/pca9450-regulator.c
@@ -953,13 +953,10 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
 		config.dev = pca9450->dev;
 
 		rdev = devm_regulator_register(pca9450->dev, desc, &config);
-		if (IS_ERR(rdev)) {
-			ret = PTR_ERR(rdev);
-			dev_err(pca9450->dev,
-				"Failed to register regulator(%s): %d\n",
-				desc->name, ret);
-			return ret;
-		}
+		if (IS_ERR(rdev))
+			return dev_err_probe(pca9450->dev, PTR_ERR(rdev),
+				"Failed to register regulator(%s)\n",
+				desc->name);
 	}
 
 	if (pca9450->irq) {
@@ -968,9 +965,9 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
 						(IRQF_TRIGGER_FALLING | IRQF_ONESHOT),
 						"pca9450-irq", pca9450);
 		if (ret != 0) {
-			dev_err(pca9450->dev, "Failed to request IRQ: %d\n",
-				pca9450->irq);
-			return ret;
+			return dev_err_probe(pca9450->dev, ret,
+					     "Failed to request IRQ: %d\n",
+					     pca9450->irq);
 		}
 		/* Unmask all interrupt except PWRON/WDOG/RSVD */
 		ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_INT1_MSK,
@@ -1022,10 +1019,10 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
 	 */
 	pca9450->sd_vsel_gpio = gpiod_get_optional(pca9450->dev, "sd-vsel", GPIOD_OUT_HIGH);
 
-	if (IS_ERR(pca9450->sd_vsel_gpio)) {
-		dev_err(&i2c->dev, "Failed to get SD_VSEL GPIO\n");
-		return PTR_ERR(pca9450->sd_vsel_gpio);
-	}
+	if (IS_ERR(pca9450->sd_vsel_gpio))
+		return dev_err_probe(&i2c->dev,
+				     PTR_ERR(pca9450->sd_vsel_gpio),
+				     "Failed to get SD_VSEL GPIO\n");
 
 	dev_info(&i2c->dev, "%s probed.\n",
 		type == PCA9450_TYPE_PCA9450A ? "pca9450a" :

---
base-commit: 78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
change-id: 20241217-pca9450-dev_err_probe-778149cae5ee

Best regards,
-- 
Ahmad Fatoum <a.fatoum@pengutronix.de>
Re: [PATCH] regulator: pca9450: use dev_err_probe on errors requesting resources
Posted by Frieder Schrempf 1 year ago
On 17.12.24 9:59 AM, Ahmad Fatoum wrote:
> Probe functions requesting resources may return -EPROBE_DEFER to
> the driver core to instruct it to retry probe at a later time.
> This is not unusual and printing an error message unconditionally
> is just confusing to users:
> 
>   nxp-pca9450 0-0025: Failed to register regulator(buck1): -517
> 
> Using dev_err_probe remedies this:
> 
> The error message will only be shown if the error code is not
> -EPROBE_DEFER and if it is, the deferral reason is saved for display
> at a later time.
> 
> Fixes: 0935ff5f1f0a ("regulator: pca9450: add pca9450 pmic driver")
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

There is a similar change already queued in next:

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/regulator/pca9450-regulator.c?id=0f5c601098bd3c9cdfea3e01aacdd9d0c4010ea7

> ---
>  drivers/regulator/pca9450-regulator.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9450-regulator.c
> index 9714afe347dcc0205b40243252638dff5f9298ad..8f5ba59f7fe52bee1e467a3e6adf81a6a5476221 100644
> --- a/drivers/regulator/pca9450-regulator.c
> +++ b/drivers/regulator/pca9450-regulator.c
> @@ -953,13 +953,10 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
>  		config.dev = pca9450->dev;
>  
>  		rdev = devm_regulator_register(pca9450->dev, desc, &config);
> -		if (IS_ERR(rdev)) {
> -			ret = PTR_ERR(rdev);
> -			dev_err(pca9450->dev,
> -				"Failed to register regulator(%s): %d\n",
> -				desc->name, ret);
> -			return ret;
> -		}
> +		if (IS_ERR(rdev))
> +			return dev_err_probe(pca9450->dev, PTR_ERR(rdev),
> +				"Failed to register regulator(%s)\n",
> +				desc->name);
>  	}
>  
>  	if (pca9450->irq) {
> @@ -968,9 +965,9 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
>  						(IRQF_TRIGGER_FALLING | IRQF_ONESHOT),
>  						"pca9450-irq", pca9450);
>  		if (ret != 0) {
> -			dev_err(pca9450->dev, "Failed to request IRQ: %d\n",
> -				pca9450->irq);
> -			return ret;
> +			return dev_err_probe(pca9450->dev, ret,
> +					     "Failed to request IRQ: %d\n",
> +					     pca9450->irq);
>  		}
>  		/* Unmask all interrupt except PWRON/WDOG/RSVD */
>  		ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_INT1_MSK,
> @@ -1022,10 +1019,10 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
>  	 */
>  	pca9450->sd_vsel_gpio = gpiod_get_optional(pca9450->dev, "sd-vsel", GPIOD_OUT_HIGH);
>  
> -	if (IS_ERR(pca9450->sd_vsel_gpio)) {
> -		dev_err(&i2c->dev, "Failed to get SD_VSEL GPIO\n");
> -		return PTR_ERR(pca9450->sd_vsel_gpio);
> -	}
> +	if (IS_ERR(pca9450->sd_vsel_gpio))
> +		return dev_err_probe(&i2c->dev,
> +				     PTR_ERR(pca9450->sd_vsel_gpio),
> +				     "Failed to get SD_VSEL GPIO\n");
>  
>  	dev_info(&i2c->dev, "%s probed.\n",
>  		type == PCA9450_TYPE_PCA9450A ? "pca9450a" :
> 
> ---
> base-commit: 78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
> change-id: 20241217-pca9450-dev_err_probe-778149cae5ee
> 
> Best regards,
Re: [PATCH] regulator: pca9450: use dev_err_probe on errors requesting resources
Posted by Ahmad Fatoum 1 year ago
Hello Frieder,

On 17.12.24 10:04, Frieder Schrempf wrote:
> On 17.12.24 9:59 AM, Ahmad Fatoum wrote:
>> Probe functions requesting resources may return -EPROBE_DEFER to
>> the driver core to instruct it to retry probe at a later time.
>> This is not unusual and printing an error message unconditionally
>> is just confusing to users:
>>
>>   nxp-pca9450 0-0025: Failed to register regulator(buck1): -517
>>
>> Using dev_err_probe remedies this:
>>
>> The error message will only be shown if the error code is not
>> -EPROBE_DEFER and if it is, the deferral reason is saved for display
>> at a later time.
>>
>> Fixes: 0935ff5f1f0a ("regulator: pca9450: add pca9450 pmic driver")
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> 
> There is a similar change already queued in next:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/regulator/pca9450-regulator.c?id=0f5c601098bd3c9cdfea3e01aacdd9d0c4010ea7

Thanks for pointing this out.

Sorry for the noise!
Ahmad

> 
>> ---
>>  drivers/regulator/pca9450-regulator.c | 25 +++++++++++--------------
>>  1 file changed, 11 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9450-regulator.c
>> index 9714afe347dcc0205b40243252638dff5f9298ad..8f5ba59f7fe52bee1e467a3e6adf81a6a5476221 100644
>> --- a/drivers/regulator/pca9450-regulator.c
>> +++ b/drivers/regulator/pca9450-regulator.c
>> @@ -953,13 +953,10 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
>>  		config.dev = pca9450->dev;
>>  
>>  		rdev = devm_regulator_register(pca9450->dev, desc, &config);
>> -		if (IS_ERR(rdev)) {
>> -			ret = PTR_ERR(rdev);
>> -			dev_err(pca9450->dev,
>> -				"Failed to register regulator(%s): %d\n",
>> -				desc->name, ret);
>> -			return ret;
>> -		}
>> +		if (IS_ERR(rdev))
>> +			return dev_err_probe(pca9450->dev, PTR_ERR(rdev),
>> +				"Failed to register regulator(%s)\n",
>> +				desc->name);
>>  	}
>>  
>>  	if (pca9450->irq) {
>> @@ -968,9 +965,9 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
>>  						(IRQF_TRIGGER_FALLING | IRQF_ONESHOT),
>>  						"pca9450-irq", pca9450);
>>  		if (ret != 0) {
>> -			dev_err(pca9450->dev, "Failed to request IRQ: %d\n",
>> -				pca9450->irq);
>> -			return ret;
>> +			return dev_err_probe(pca9450->dev, ret,
>> +					     "Failed to request IRQ: %d\n",
>> +					     pca9450->irq);
>>  		}
>>  		/* Unmask all interrupt except PWRON/WDOG/RSVD */
>>  		ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_INT1_MSK,
>> @@ -1022,10 +1019,10 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
>>  	 */
>>  	pca9450->sd_vsel_gpio = gpiod_get_optional(pca9450->dev, "sd-vsel", GPIOD_OUT_HIGH);
>>  
>> -	if (IS_ERR(pca9450->sd_vsel_gpio)) {
>> -		dev_err(&i2c->dev, "Failed to get SD_VSEL GPIO\n");
>> -		return PTR_ERR(pca9450->sd_vsel_gpio);
>> -	}
>> +	if (IS_ERR(pca9450->sd_vsel_gpio))
>> +		return dev_err_probe(&i2c->dev,
>> +				     PTR_ERR(pca9450->sd_vsel_gpio),
>> +				     "Failed to get SD_VSEL GPIO\n");
>>  
>>  	dev_info(&i2c->dev, "%s probed.\n",
>>  		type == PCA9450_TYPE_PCA9450A ? "pca9450a" :
>>
>> ---
>> base-commit: 78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
>> change-id: 20241217-pca9450-dev_err_probe-778149cae5ee
>>
>> Best regards,
> 
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |