diff mbox series

power: supply: mt6370: Fix missing error code in mt6370_chg_toggle_cfo()

Message ID 20230906084815.2827930-1-harshit.m.mogalapalli@oracle.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series power: supply: mt6370: Fix missing error code in mt6370_chg_toggle_cfo() | expand

Commit Message

Harshit Mogalapalli Sept. 6, 2023, 8:48 a.m. UTC
When mt6370_chg_field_get() suceeds, ret is set to zero and returning
zero when flash led is still in strobe mode looks incorrect.

Fixes: 233cb8a47d65 ("power: supply: mt6370: Add MediaTek MT6370 charger driver")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is based on static analysis with smatch, only compile tested.
---
 drivers/power/supply/mt6370-charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

AngeloGioacchino Del Regno Sept. 7, 2023, 10:43 a.m. UTC | #1
Il 06/09/23 10:48, Harshit Mogalapalli ha scritto:
> When mt6370_chg_field_get() suceeds, ret is set to zero and returning
> zero when flash led is still in strobe mode looks incorrect.
> 
> Fixes: 233cb8a47d65 ("power: supply: mt6370: Add MediaTek MT6370 charger driver")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> This is based on static analysis with smatch, only compile tested.
> ---
>   drivers/power/supply/mt6370-charger.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/mt6370-charger.c b/drivers/power/supply/mt6370-charger.c
> index f27dae5043f5..a9641bd3d8cf 100644
> --- a/drivers/power/supply/mt6370-charger.c
> +++ b/drivers/power/supply/mt6370-charger.c
> @@ -324,7 +324,7 @@ static int mt6370_chg_toggle_cfo(struct mt6370_priv *priv)
>   
>   	if (fl_strobe) {
>   		dev_err(priv->dev, "Flash led is still in strobe mode\n");
> -		return ret;
> +		return -EINVAL;

I think that returning 0 here was intentional, but I agree on a return ret
here being both confusing and wrong.

That's how I get this logic:

The function is enabling strobe mode, but if the flash led is *already* in
strobe mode, the function exits cleanly because there's nothing to do, as
the enablement is already done.

Hence.... I believe that the right fix is not to return -EINVAL, but rather
to change that to `return 0` instead.

ChiaEn, can you please confirm, or deny my statement?

Regards,
Angelo

>   	}
>   
>   	/* cfo off */
Dan Carpenter Sept. 7, 2023, 11:08 a.m. UTC | #2
On Thu, Sep 07, 2023 at 12:43:12PM +0200, AngeloGioacchino Del Regno wrote:
> Il 06/09/23 10:48, Harshit Mogalapalli ha scritto:
> > When mt6370_chg_field_get() suceeds, ret is set to zero and returning
> > zero when flash led is still in strobe mode looks incorrect.
> > 
> > Fixes: 233cb8a47d65 ("power: supply: mt6370: Add MediaTek MT6370 charger driver")
> > Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> > ---
> > This is based on static analysis with smatch, only compile tested.
> > ---
> >   drivers/power/supply/mt6370-charger.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/power/supply/mt6370-charger.c b/drivers/power/supply/mt6370-charger.c
> > index f27dae5043f5..a9641bd3d8cf 100644
> > --- a/drivers/power/supply/mt6370-charger.c
> > +++ b/drivers/power/supply/mt6370-charger.c
> > @@ -324,7 +324,7 @@ static int mt6370_chg_toggle_cfo(struct mt6370_priv *priv)
> >   	if (fl_strobe) {
> >   		dev_err(priv->dev, "Flash led is still in strobe mode\n");
> > -		return ret;
> > +		return -EINVAL;
> 
> I think that returning 0 here was intentional, but I agree on a return ret
> here being both confusing and wrong.

If it's a success path then probably we should remove the dev_err().

regards,
dan carpenter
ChiaEn Wu Sept. 8, 2023, 2:19 a.m. UTC | #3
On Thu, Sep 07, 2023 at 02:08:17PM +0300, Dan Carpenter wrote:

[...]

> > > diff --git a/drivers/power/supply/mt6370-charger.c b/drivers/power/supply/mt6370-charger.c
> > > index f27dae5043f5..a9641bd3d8cf 100644
> > > --- a/drivers/power/supply/mt6370-charger.c
> > > +++ b/drivers/power/supply/mt6370-charger.c
> > > @@ -324,7 +324,7 @@ static int mt6370_chg_toggle_cfo(struct mt6370_priv *priv)
> > >   	if (fl_strobe) {
> > >   		dev_err(priv->dev, "Flash led is still in strobe mode\n");
> > > -		return ret;
> > > +		return -EINVAL;
> > 
> > I think that returning 0 here was intentional, but I agree on a return ret
> > here being both confusing and wrong.
> 
> If it's a success path then probably we should remove the dev_err().
> 

Hi all,
Sorry for the late reply!

I agree with the first half of Angelo's statement, I did make the
mistake on this 'return ret'.
What I was trying to say is that you should not to toggle cfo function
when the FLED of MT6370 is still in "strobe mode".

Therefore, I think the change of Harshit's patch is correct.
It should be 'return -EINVAL' or 'return -EPERM' here.

Thanks!


Reviewed-by: ChiaEn Wu <chiaen_wu@richtek.com>


Best regards,
ChiaEn Wu
AngeloGioacchino Del Regno Sept. 8, 2023, 10:01 a.m. UTC | #4
Il 08/09/23 04:19, ChiaEn Wu ha scritto:
> On Thu, Sep 07, 2023 at 02:08:17PM +0300, Dan Carpenter wrote:
> 
> [...]
> 
>>>> diff --git a/drivers/power/supply/mt6370-charger.c b/drivers/power/supply/mt6370-charger.c
>>>> index f27dae5043f5..a9641bd3d8cf 100644
>>>> --- a/drivers/power/supply/mt6370-charger.c
>>>> +++ b/drivers/power/supply/mt6370-charger.c
>>>> @@ -324,7 +324,7 @@ static int mt6370_chg_toggle_cfo(struct mt6370_priv *priv)
>>>>    	if (fl_strobe) {
>>>>    		dev_err(priv->dev, "Flash led is still in strobe mode\n");
>>>> -		return ret;
>>>> +		return -EINVAL;
>>>
>>> I think that returning 0 here was intentional, but I agree on a return ret
>>> here being both confusing and wrong.
>>
>> If it's a success path then probably we should remove the dev_err().
>>
> 
> Hi all,
> Sorry for the late reply!
> 
> I agree with the first half of Angelo's statement, I did make the
> mistake on this 'return ret'.
> What I was trying to say is that you should not to toggle cfo function
> when the FLED of MT6370 is still in "strobe mode".
> 
> Therefore, I think the change of Harshit's patch is correct.
> It should be 'return -EINVAL' or 'return -EPERM' here.
> 
> Thanks!
> 
> 
> Reviewed-by: ChiaEn Wu <chiaen_wu@richtek.com>
> 
> 
> Best regards,
> ChiaEn Wu

Cool. In that case:

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Sebastian Reichel Sept. 11, 2023, 8:15 p.m. UTC | #5
On Wed, 06 Sep 2023 01:48:15 -0700, Harshit Mogalapalli wrote:
> When mt6370_chg_field_get() suceeds, ret is set to zero and returning
> zero when flash led is still in strobe mode looks incorrect.
> 
> 

Applied, thanks!

[1/1] power: supply: mt6370: Fix missing error code in mt6370_chg_toggle_cfo()
      commit: 779873ec81306d2c40c459fa7c91a5d40655510d

Best regards,
diff mbox series

Patch

diff --git a/drivers/power/supply/mt6370-charger.c b/drivers/power/supply/mt6370-charger.c
index f27dae5043f5..a9641bd3d8cf 100644
--- a/drivers/power/supply/mt6370-charger.c
+++ b/drivers/power/supply/mt6370-charger.c
@@ -324,7 +324,7 @@  static int mt6370_chg_toggle_cfo(struct mt6370_priv *priv)
 
 	if (fl_strobe) {
 		dev_err(priv->dev, "Flash led is still in strobe mode\n");
-		return ret;
+		return -EINVAL;
 	}
 
 	/* cfo off */