diff mbox series

power: supply: cpcap-battery: Use IS_ERR() to check and simplify code

Message ID 20210720061836.29148-1-tangbin@cmss.chinamobile.com
State New
Headers show
Series power: supply: cpcap-battery: Use IS_ERR() to check and simplify code | expand

Commit Message

Tang Bin July 20, 2021, 6:18 a.m. UTC
Use IS_ERR() and PTR_ERR() instead of PTR_ERR_OR_ZERO() to
simplify code, avoid redundant judgements.

Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
 drivers/power/supply/cpcap-battery.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Sebastian Reichel Aug. 6, 2021, 9:47 p.m. UTC | #1
Hi,

On Tue, Jul 20, 2021 at 02:18:36PM +0800, Tang Bin wrote:
> Use IS_ERR() and PTR_ERR() instead of PTR_ERR_OR_ZERO() to

> simplify code, avoid redundant judgements.

> 

> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>

> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>

> ---


I think the original variant is the simpler one. Also
compiler should be able to optimize this.

-- Sebastian

>  drivers/power/supply/cpcap-battery.c | 5 ++---

>  1 file changed, 2 insertions(+), 3 deletions(-)

> 

> diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c

> index 90eba3646..7007e5d53 100644

> --- a/drivers/power/supply/cpcap-battery.c

> +++ b/drivers/power/supply/cpcap-battery.c

> @@ -912,10 +912,9 @@ static int cpcap_battery_probe(struct platform_device *pdev)

>  

>  	ddata->psy = devm_power_supply_register(ddata->dev, psy_desc,

>  						&psy_cfg);

> -	error = PTR_ERR_OR_ZERO(ddata->psy);

> -	if (error) {

> +	if (IS_ERR(ddata->psy)) {

>  		dev_err(ddata->dev, "failed to register power supply\n");

> -		return error;

> +		return PTR_ERR(ddata->psy);

>  	}

>  

>  	atomic_set(&ddata->active, 1);

> -- 

> 2.20.1.windows.1

> 

> 

>
diff mbox series

Patch

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 90eba3646..7007e5d53 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -912,10 +912,9 @@  static int cpcap_battery_probe(struct platform_device *pdev)
 
 	ddata->psy = devm_power_supply_register(ddata->dev, psy_desc,
 						&psy_cfg);
-	error = PTR_ERR_OR_ZERO(ddata->psy);
-	if (error) {
+	if (IS_ERR(ddata->psy)) {
 		dev_err(ddata->dev, "failed to register power supply\n");
-		return error;
+		return PTR_ERR(ddata->psy);
 	}
 
 	atomic_set(&ddata->active, 1);