power: supply: ltc3651-charger: Fix wrong pointer passed to PTR_ERR()
PATCH 1/1 power: supply: ltc3651-charger: Fix wrong pointer passed to PTR_ERR()
From: Wei Yongjun <[email protected]>
PTR_ERR should access the value just tested by IS_ERR, otherwise the wrong error code will be returned.
--- drivers/power/supply/ltc3651-charger.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/power/supply/ltc3651-charger.c +3 -3
@@ -110,21 +110,21 @@ static int ltc3651_charger_probe(struct platform_device *pdev) ltc3651_charger->acpr_gpio =devm_gpiod_get (&pdev->dev,"lltc,acpr" ,GPIOD_IN );if (IS_ERR (ltc3651_charger->acpr_gpio)) { - ret =PTR_ERR (ltc3651_charger->charger); + ret =PTR_ERR (ltc3651_charger->acpr_gpio);dev_err (&pdev->dev,"Failed to acquire acpr GPIO: %d\n" , ret);return ret; } ltc3651_charger->fault_gpio =devm_gpiod_get_optional (&pdev->dev,"lltc,fault" ,GPIOD_IN );if (IS_ERR (ltc3651_charger->fault_gpio)) { - ret =PTR_ERR (ltc3651_charger->charger); + ret =PTR_ERR (ltc3651_charger->fault_gpio);dev_err (&pdev->dev,"Failed to acquire fault GPIO: %d\n" , ret);return ret; } ltc3651_charger->chrg_gpio =devm_gpiod_get_optional (&pdev->dev,"lltc,chrg" ,GPIOD_IN );if (IS_ERR (ltc3651_charger->chrg_gpio)) { - ret =PTR_ERR (ltc3651_charger->charger); + ret =PTR_ERR (ltc3651_charger->chrg_gpio);dev_err (&pdev->dev,"Failed to acquire chrg GPIO: %d\n" , ret);return ret; }
Quoted 6 lines · Wei Yongjun
From: Wei Yongjun <[email protected]>
PTR_ERRshould access the value just tested byIS_ERR, otherwise the wrong error code will be returned.Signed-off-by Wei Yongjun <[email protected]>
This does fix the issue, but maybe we want to use PTR_ERR_OR_ZERO()?
ltc3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev, "lltc,acpr", GPIOD_IN); ret = PTR_ERR_OR_ZERO(ltc3651_charger->acpr_gpio); if (ret) ...
Or even
err = PTR_ERR_OR_ZERO((ltc3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev, "lltc,acpr", GPIOD_IN))); if (err) ...
To make sure we never mix up pointer. Maybe we need ERR_OR_ASSIGN(ptr1, ptr2) to avoid the ugly assignment in argument above...
Thanks.
Quoted 34 lines
--- drivers/power/supply/ltc3651-charger.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/power/supply/ltc3651-charger.c +3
-3@@ -110,21 +110,21 @@ static int ltc3651_charger_probe(struct platform_device *pdev) ltc3651_charger->acpr_gpio =devm_gpiod_get (&pdev->dev,"lltc,acpr" ,GPIOD_IN );if (IS_ERR (ltc3651_charger->acpr_gpio)) { - ret =PTR_ERR (ltc3651_charger->charger); + ret =PTR_ERR (ltc3651_charger->acpr_gpio);dev_err (&pdev->dev,"Failed to acquire acpr GPIO: %d\n" , ret);return ret; } ltc3651_charger->fault_gpio =devm_gpiod_get_optional (&pdev->dev,"lltc,fault" ,GPIOD_IN );if (IS_ERR (ltc3651_charger->fault_gpio)) { - ret =PTR_ERR (ltc3651_charger->charger); + ret =PTR_ERR (ltc3651_charger->fault_gpio);dev_err (&pdev->dev,"Failed to acquire fault GPIO: %d\n" , ret);return ret; } ltc3651_charger->chrg_gpio =devm_gpiod_get_optional (&pdev->dev,"lltc,chrg" ,GPIOD_IN );if (IS_ERR (ltc3651_charger->chrg_gpio)) { - ret =PTR_ERR (ltc3651_charger->charger); + ret =PTR_ERR (ltc3651_charger->chrg_gpio);dev_err (&pdev->dev,"Failed to acquire chrg GPIO: %d\n" , ret);return ret; }
Signature · 1 line
Dmitry
Hi, Dmitry
Quoted 21 lines
Subject: Re: [PATCH -next] power: supply: ltc3651-charger: Fix wrong pointer passed to
PTR_ERR()Quoted 6 lines · Wei Yongjun
From: Wei Yongjun <[email protected]>
PTR_ERRshould access the value just tested byIS_ERR, otherwise the wrong error code will be returned.Signed-off-by Wei Yongjun <[email protected]>This does fix the issue, but maybe we want to use
PTR_ERR_OR_ZERO()?ltc3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev, "lltc,acpr", GPIOD_IN); ret = PTR_ERR_OR_ZERO(ltc3651_charger->acpr_gpio); if (ret) ...Or even
Quoted 9 lines
err = PTR_ERR_OR_ZERO((ltc3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev, "lltc,acpr", GPIOD_IN))); if (err) ...To make sure we never mix up pointer. Maybe we need ERR_OR_ASSIGN(ptr1,
ptr2) to avoid the ugly assignment in argument above...
I have checked devm_gpiod_get() and seems it never return NULL. And the other places call devm_gpiod_get() never check for NULL return. So I think PTR_ERR_OR_ZERO() is not need here.
Regards,
Yongjun Wei
Hi Wei,
Quoted 28 lines · weiyongjun (A)
Hi, Dmitry
Quoted 26 lines
Subject: Re: [PATCH -next] power: supply: ltc3651-charger: Fix wrong pointer passed to
PTR_ERR()Quoted 6 lines · Wei Yongjun
From: Wei Yongjun <[email protected]>
PTR_ERRshould access the value just tested byIS_ERR, otherwise the wrong error code will be returned.Signed-off-by Wei Yongjun <[email protected]>This does fix the issue, but maybe we want to use
PTR_ERR_OR_ZERO()?ltc3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev, "lltc,acpr", GPIOD_IN); ret = PTR_ERR_OR_ZERO(ltc3651_charger->acpr_gpio); if (ret) ...Or even
err = PTR_ERR_OR_ZERO((ltc3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev, "lltc,acpr", GPIOD_IN))); if (err) ...
Quoted 8 lines
Quoted 4 lines
To make sure we never mix up pointer. Maybe we need ERR_OR_ASSIGN(ptr1,
ptr2) to avoid the ugly assignment in argument above...I have checked
devm_gpiod_get()and seems it never return NULL. And the other places calldevm_gpiod_get()never check for NULL return. So I thinkPTR_ERR_OR_ZERO()is not need here.
The request to use PTR_ERR_OR_ZERO() had nothing to do with devm_gpiod_get() returning NULL and everything with reducing number of times one has to write "ltc3651_charger->acpr_gpio". The original problem was that we checked the wrong value, if we provide macro incorporating assignment and conversion to an error code in one step this will reduce number of times we screw up like that in the future.
Thanks.
Signature · 1 line
Dmitry
Sebastian Reichel
maintainerHi,
Quoted 4 lines · Wei Yongjun
From: Wei Yongjun <[email protected]>
PTR_ERRshould access the value just tested byIS_ERR, otherwise the wrong error code will be returned.
I queued the same patch from Dan, which had the better description incl. a Fixes, but added your Signed-off-by.
-- Sebastian